Sendra / Guides

Build a reliable WhatsApp webhook

A WhatsApp webhook sends messages and status updates to your app. Check the signature against the raw body, save the event ID, then return 200 quickly. Do slower work afterwards, and expect some events to arrive more than once.

By BobWork. Updated .

What to do with each event

  1. Read the raw body. Don't parse the JSON yet.
  2. Check its signature and time.
  3. Parse the JSON and save the event's id. If you already have it, return 200 and stop.
  4. Save the event or add it to a queue.
  5. Return 200 within 10 seconds, then do slower work such as calling an AI model.

Save the event before you return 200. If your app returns 200 and then crashes, the event won't be sent again.

Check the signature in Node.js

Sendra signs the time, a full stop and the raw body. This code refuses bad signatures and events that are more than 5 minutes old. Add your own code to save the event before it returns 200.

import crypto from "node:crypto";
import express from "express";

function verify(rawBody, header, secret) {
  const { t, v1 } = Object.fromEntries(String(header || "").split(",").map((p) => p.split("=")));
  if (!/^\d+$/.test(t || "") || !/^[0-9a-f]{64}$/.test(v1 || "")) return false;
  if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return false;
  const want = crypto.createHmac("sha256", secret).update(`${t}.`).update(rawBody).digest();
  return crypto.timingSafeEqual(want, Buffer.from(v1, "hex"));
}

const app = express();
// Use the raw body: parsing it as JSON first would break the signature check.
app.post("/whatsapp", express.raw({ type: "application/json" }), (req, res) => {
  if (!verify(req.body, req.get("X-Sendra-Signature"), process.env.SENDRA_WEBHOOK_SECRET)) return res.sendStatus(401);
  const event = JSON.parse(req.body.toString("utf8"));
  // Save event.id (skip it if you already have it), then do slow work after answering.
  res.sendStatus(200);
});
app.listen(3000);

Check the signature in Python

Pass this function the raw request bytes, the X-Sendra-Signature header and your signing secret.

import hashlib, hmac, re, time

def verify(raw_body: bytes, header: str, secret: str) -> bool:
    parts = dict(p.split("=", 1) for p in (header or "").split(",") if "=" in p)
    t, v1 = parts.get("t", ""), parts.get("v1", "")
    if not re.fullmatch(r"[0-9]+", t) or not re.fullmatch(r"[0-9a-f]{64}", v1):
        return False
    if abs(time.time() - int(t)) > 300:
        return False
    want = hmac.new(secret.encode(), t.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(want, v1)

Keep the signing secret in an environment variable. Sendra only shows it once. If you lose it or it leaks, create a new one.

Events Sendra can send

Event When Sendra sends it
message.received A customer sent you a message. content keeps WhatsApp's format, so it depends on type. contact can be null.
message.status A message's status changed. message_id can be null if we have no matching message. Sandbox events don't include error_code.
message.echo You sent a message from the WhatsApp Business app on a connected number.
number.connected A number was connected in Sendra. mode is always api.
number.quality Meta changed a number's quality rating, messaging limit or status. We check about every 6 hours. Values can be null.
ping A test from the dashboard or POST /webhook/test.

Use livemode to keep test and real events apart. It's false for sandbox events and true for live ones.

How Meta and Sendra deliver webhooks

Meta's webhook Sendra's webhook
Signature header X-Hub-Signature-256 X-Sendra-Signature
If delivery fails Retries less and less often, for up to 7 days Tries again after 1 minute, 5 minutes, 30 minutes, 2 hours and 6 hours
Format Meta's original format, up to 3 MB One event at a time, each with an id, type and livemode

Meta keeps trying for longer. With Sendra, if every retry fails, you can still use GET /messages to find the messages you missed.

Common mistakes

  • Treating a status update as a message: a delivery update shouldn't make your bot reply. Check the event's type first.
  • Replying to yourself: message.echo means your team replied in the WhatsApp Business app. Don't treat it as a customer's message.
  • Expecting events in order: a status update can arrive late. Don't change a message from read back to delivered.
  • Waiting for an AI reply: save the event and return 200 first.

Test it safely

Set a public HTTPS webhook in the sandbox. Use POST /webhook/test to send a ping, then simulate a customer message. Check that a wrong signature gets a 401, and that sending the same event twice only processes it once.

Common questions

Why does my webhook signature check fail?

The body was often changed before the check. Parsing JSON and turning it back into text can change spaces or the order of fields. Check the exact bytes you received, then parse them.

How do I handle the same webhook event twice?

Save each event's ID with a unique rule in your database. If that ID is already saved, return 200 without processing the event again.

How long does Sendra wait for my webhook?

Sendra waits 10 seconds for a 2xx response. If it doesn't get one, it tries again after 1 minute, 5 minutes, 30 minutes, 2 hours and 6 hours.

Are Meta and Sendra webhook signatures the same?

No. Meta uses the X-Hub-Signature-256 header. Sendra uses X-Sendra-Signature, which also includes the time. Use the check that matches who sent the webhook.

Sources

Checked 2 December 2026. Prices and features change, so check the links before you decide. If something here is out of date, tell us and we'll fix it.

Related

Try it before you connect a number

Sign up free and create a sandbox key. You don't need a phone or a Meta account, and test messages never reach real people.

Start freeConnect a number with Claude Code