Inside aone-whatsapp-orchestrator v9.0
1,229 lines of TypeScript. Here's what happens when a POST arrives from Zapier.
1
Validate & Extract
Checks the incoming JSON for required fields (message, sender_name, sender_phone, channel). Assigns a unique traceId for logging. Rejects invalid requests immediately.
2
Fire Acknowledgement (v8.0+)
Sends a quick "looking into it" message back via SuperChat API immediately, before any heavy processing. This is fire-and-forget — if it fails, the pipeline continues.
POST api.superchat.com/v1.0/messages
Channel: mc_z5xxgzblp1dXLCoozNyzt (WhatsApp)
3
Classify Intent (Claude API)
Sends the customer message to Claude with a system prompt containing AOne business context. Claude returns a structured classification.
10 intents: order_status, payment_verification, delivery_question,
product_inquiry, store_hours, complaint, fraud_investigation,
refund_request, invoice_billing, general_greeting
Research types → what gets queried:
shopify_order → Shopify only
shopify_payment → Shopify + Tilopay FIXED TODAY
invoice → Invoice system
tilopay → Tilopay (+ Shopify if order # found)
none → No research needed
Bug was here: payment_verification and refund_request
were mapped to "shopify_order" (Shopify only).
Now fixed: Both map to "shopify_payment" (Shopify + Tilopay).
4
Route & Research (doResearch)
Based on the research_type, calls out to external APIs to get real data.
Shopify Lookup
Calls aone-shopify-lookup edge function
Queries orders, customers, products
Uses SHOPIFY_ADMIN_TOKEN
NEW TOKEN shpat_9b8f...
Tilopay Lookup
Direct API call to Tilopay gateway
Auth token cached for 23 hours
Searches by order # or date range
Returns capture status, auth codes
Both (shopify_payment)
Runs Shopify AND Tilopay in parallel
Merges results for Claude to synthesise
Used for payment_verification,
refund_request intents
5
Check Escalation Rules
Each intent has routing rules (set in getActionRouting). If escalation_needed is true, a fire-and-forget POST goes to Zapier's notification pipeline (Zap #354426313).
Always escalate: fraud_investigation, complaint (high severity)
AI handles: order_status, payment_verification, delivery_question,
product_inquiry, store_hours, general_greeting
AI then Dwayne: refund_request, invoice_billing
6
Generate Response (Claude API)
Sends the original message + classification + research results back to Claude with instructions to write a reply in Dwayne's communication style. Produces a WhatsApp-formatted response.
7
Return JSON to Zapier
Responds with the AI-generated reply text plus metadata (classification, research sources, timing). Zapier takes the reply_text and sends it via SuperChat API back to the customer's WhatsApp.
Response shape:
{ response, classification, research_sources,
timing_ms, traceId, escalation_dispatched }