Description
What is a webhook?
A webhook is an HTTP callback: instead of your system repeatedly asking an API whether anything has changed, the platform calls a URL you own as soon as an event occurs. On the WhatsApp Business Platform every inbound customer message, every delivery or read status for a message you sent, and changes such as a template being approved or a phone number's quality rating moving all arrive this way.
Each notification is a POST request with a JSON body. The body is an envelope — object is whatsapp_business_account, and an entry array holds one or more changes, each naming the field that changed (most often messages) and a value with the details: the business phone number's metadata, the customer's profile and WhatsApp ID, and the message or status objects themselves.
Webhooks are the only way to receive messages on the Cloud API — there is no endpoint to poll for an inbox. That makes the webhook endpoint the most important piece of any WhatsApp integration: if it is down, slow or rejecting requests, inbound conversations and delivery statuses stop flowing into your systems. The opposite model, polling, has your code ask an API for changes on a schedule; the webhooks vs polling page compares the two.
Key takeaways
- A webhook is an HTTP POST the platform sends to your URL the moment an event happens — you never poll for messages.
- On the WhatsApp Cloud API, inbound messages and delivery statuses arrive only through webhooks.
- Verify the
X-Hub-Signature-256HMAC over the raw body before trusting a payload. - Return 200 fast and process from a queue: failed deliveries are retried for up to seven days.
- Deduplicate by
wamid— retries mean the same event can arrive more than once.
How does InfiQ help with a webhook?
InfiQ receives Meta's webhooks for you and forwards what you subscribe to as signed InfiQ events: inbound messages, statuses, campaigns, contacts, templates and account changes, retried until you answer.
- Verify X-InfiQ-Signature on the raw body.
- Deduplicate on X-InfiQ-Event-Id.
Mechanics
How does a webhook work?
step 1 — Register a callback URL
In your Meta app's WhatsApp configuration (or through your provider), set an HTTPS callback URL and a verify token of your choosing, then subscribe the app to the fields you need —
messagescovers inbound messages and statuses.step 2 — Answer the verification request
Meta sends a GET request with
hub.mode=subscribe,hub.verify_tokenandhub.challenge. Your endpoint checks the token matches and responds 200 with the challenge value as the body; anything else and the subscription is not saved.step 3 — Receive event POSTs
From then on, each event is POSTed as JSON. One request can batch several changes, so iterate over every
entryand everychangesitem rather than reading only the first.step 4 — Verify the signature
Every POST carries an
X-Hub-Signature-256header: an HMAC-SHA256 of the raw request body keyed with your app secret. Recompute it over the exact bytes received and compare in constant time before trusting the payload.step 5 — Acknowledge fast, process later
Return 200 within a few seconds, then hand the work to a queue. If your endpoint errors or times out, Meta retries the delivery with decreasing frequency for up to seven days, so slow handlers create duplicates and backlogs.
Usage
A webhook in code
import crypto from "node:crypto";import express from "express";const app = express();// Keep the raw bytes: the signature is computed over them, not over parsed JSON.app.use(express.json({ verify: (req, _res, buf) => { req.rawBody = buf; } }));// 1. Verification handshake (GET)app.get("/webhooks/whatsapp", (req, res) => {const ok = req.query["hub.mode"] === "subscribe" &&req.query["hub.verify_token"] === process.env.VERIFY_TOKEN;return ok ? res.status(200).send(req.query["hub.challenge"]) : res.sendStatus(403);});// 2. Event notifications (POST)app.post("/webhooks/whatsapp", (req, res) => {const expected = "sha256=" + crypto.createHmac("sha256", process.env.APP_SECRET).update(req.rawBody).digest("hex");const given = req.get("X-Hub-Signature-256") ?? "";if (given.length !== expected.length ||!crypto.timingSafeEqual(Buffer.from(given), Buffer.from(expected))) {return res.sendStatus(401);}queue.add("whatsapp-event", req.body); // process asynchronouslyreturn res.sendStatus(200); // acknowledge immediately});
Verify the handshake, check the signature over the raw body, enqueue, and acknowledge — in that order.
Why it matters
Why does a webhook matter?
Without a working webhook, a WhatsApp integration is send-only: customer replies never reach your inbox or chatbot, you cannot tell which messages were delivered or read, and you will not notice when a template is paused. A fast, verified and idempotent webhook endpoint is what turns the API into a two-way channel your team can rely on.
Example
Example: An order-status reply
A Jaipur furniture store sends a utility template confirming dispatch. Twenty minutes later the customer replies "Can it come after 6 pm?". Meta POSTs a messages webhook to the store's endpoint; the handler verifies the signature, stores the message by its wamid (ignoring it if that ID was already processed), pushes it to the shared inbox and returns 200. An agent sees the question within seconds and answers inside the 24-hour customer service window.
Properties
A webhook: key facts and limits
- Method
- GET for verification, POST for events
- Body format
- JSON, object = whatsapp_business_account
- Signature header
- X-Hub-Signature-256 (HMAC-SHA256)
- Main subscription field
- messages (inbound + statuses)
- Retries on failure
- Decreasing frequency, up to 7 days
- Transport
- HTTPS with a valid certificate
Caveats
Common mistakes with a webhook
Doing the work before answering
Calling a CRM, an LLM or a database before returning 200 makes the request slow; timeouts trigger retries and the same event arrives again. Acknowledge first and process from a queue.
Assuming one event per request
A single POST can carry several entries and changes, and statuses can arrive in the same batch as messages. Loop over everything and branch on
fieldand on whethervaluehasmessagesorstatuses.Not deduplicating
Retries and network blips mean the same notification can be delivered more than once. Store each message or status keyed by its
wamidplus status and skip anything already seen.Verifying the signature over re-serialised JSON
Parsing the body and stringifying it again changes whitespace and key order, so the HMAC never matches. Compute it over the raw bytes exactly as received.
Notes
Best practices for a webhook
- Return 200 even for event types you do not handle yet, so Meta does not keep retrying them.
- Log the raw payload (with personal data masked) for a few days — it is the fastest way to debug a missed message.
- Expect statuses out of order: a read can arrive before its delivered event, so never move a message backwards in your status model.
- Alert on a falling webhook rate, not just on errors — silence is the failure mode that hurts most.
Questions
Webhook FAQs
- How do I know a webhook request really came from Meta?
- Check its X-Hub-Signature-256 header. It holds sha256= followed by an HMAC-SHA256 of the raw request body keyed with your app secret: recompute it over the exact bytes you received, compare in constant time and reject any mismatch. The verify token only protects the one-time setup handshake.
- What happens if my webhook endpoint is down?
- Meta retries failed deliveries with decreasing frequency for up to seven days. Events are delayed, not lost, as long as you recover within that period — but expect a burst of retried and duplicate events when you come back.
- Do I need a separate webhook for every phone number?
- No. Subscriptions are set per app, and each notification says which WhatsApp Business Account and phone number it concerns (the
entryid andmetadata.phone_number_id), so one endpoint can serve many numbers. If one number or account needs its own endpoint, a webhook override redirects its message events.