Skip to main content
One complete cycle of a bot conversation: customer sends → your bot decides → bot replies → Meta confirms delivery. Understanding this sequence is essential for building any WhatsApp bot.

The four stages

INBOUND → LOGIC → OUTBOUND → STATUS

Stage 1 — INBOUND

Customer sends “Hi” from their phone:
Customer's phone
      ↓  sends "Hi"
Meta servers receive it

Meta POSTs JSON to your webhook URL

Your server: [INBOUND] Text from 919959623255: Hi
Your code reads message.from (who) and message.text.body (what).

Stage 2 — LOGIC

Your server decides what to reply:
const text = message.text.body.toLowerCase();

if (text === 'hi') {
  replyText = 'Hello! Type 1 for price, 2 for support.';
} else if (text === '1') {
  replyText = 'Pricing starts at ₹999/month.';
}
This is the bot brain — simple if/else for basic bots, AI for smarter ones.

Stage 3 — OUTBOUND

Your server calls the Messages API to send the reply:
Your server
      ↓  POST /messages
Meta API accepts it → returns message ID (wamid.xxx)

Your server: [AUTO-REPLY] Sent to 919959623255

Customer's phone receives the message

Stage 4 — STATUS

Meta fires status events back to confirm delivery:
Meta → POST /webhook → { "status": "sent" }
Meta → POST /webhook → { "status": "delivered" }
Meta → POST /webhook → { "status": "read" }

Full terminal output for one round trip

[INBOUND] Text from 919959623255: hi
[AUTO-REPLY] Sent to 919959623255: Hello! Type 1 for price...
[STATUS] sent      → 919959623255 | msg: wamid.HBgM...
[STATUS] delivered → 919959623255 | msg: wamid.HBgM...
[STATUS] read      → 919959623255 | msg: wamid.HBgM...

Frequently asked

Four stages — inbound (Meta POSTs customer message to your webhook), logic (your code decides the reply), outbound (you call Meta API to send the reply), status (Meta fires sent/delivered/read events back to confirm).
Inbound = customer → Meta → your webhook (Meta calls you). Outbound = your server → Meta API → customer (you call Meta).

Gotchas & common mistakes

  • Forgetting to handle statuses — if your webhook only handles messages and ignores statuses, the status events pile up silently. Always handle both.
  • Calling the API inside the webhook synchronously — if sending the reply is slow, you may delay the 200 response and trigger retries. Use async/await or fire-and-forget. See Webhook reliability.