AOne WhatsApp Auto-Reply Pipeline

sandylane-registration · Supabase project tsffikrkmszubwfazabu
Channel
Orchestration
AI Processing
Data Source
Payment Gateway
Notifications
Main Pipeline — Message In, Reply Out
A WhatsApp message arrives via SuperChat, gets processed by AI, and a reply is sent back. Total round-trip: ~7-9 seconds.
💬
WhatsApp
Customer sends a message
message arrives
📨
SuperChat
WhatsApp Business API provider
api.superchat.com
webhook fires
Zapier (Inbound)
Zap #354362642 catches the webhook, extracts message + sender, POSTs to edge function
SuperChat Pipeline
POST /aone-whatsapp-orchestrator
🧠
Edge Function v9.0
Classifies intent, researches data, generates AI reply
aone-whatsapp-orchestrator
reply JSON
Zapier (Reply)
Takes AI reply from edge function response, sends it back via SuperChat API
Same Zap, step 3
POST /messages
💬
WhatsApp
Customer receives AI reply

Data Sources — What the Edge Function Queries
Depending on the message classification, the edge function reaches out to one or more of these systems for real data.
🛒
Shopify
Order status, customer history, product info
aonesupermarkets.myshopify.com
TOKEN FIXED
💳
Tilopay
Payment gateway — capture status, approval codes, rejection reasons
app.tilopay.com/api/v1
ROUTING FIXED
🔍
aone-shopify-lookup
Separate edge function that handles Shopify API calls (called by the orchestrator)
Edge Function v8
🤖
Claude API
Powers message classification and response generation
Anthropic API

Escalation Pipeline — When AI Can't Handle It
Some intents (fraud, HR, emergencies) get escalated to Dwayne or Peter via a separate Zapier notification zap.
🧠
Edge Function
Detects escalation_needed = true
fire-and-forget POST
🔔
Zapier (Notify)
Zap #354426313 sends alerts to Dwayne or relevant staff
Escalation Pipeline
notification
👤
Dwayne / Peter
Human takes over the conversation in SuperChat
Two Supabase projects exist: The pipeline runs on the old project (tsffikrkmszubwfazabu — sandylane-registration). The new project (agycnssmvgawfzpkwbtz — aone-ai-assistant) is where development originally happened but the live pipeline uses the old one. All secrets and edge functions that matter are on the old project.
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 }
Accounts, Keys & Credentials
Every external service the pipeline connects to. Secrets are stored as Supabase Edge Function secrets on the old project.