Skip to content

Message status webhook

When you send a WhatsApp template through the Saqr API, Saqr can send each status of that message to your server. Every call is signed, so you can check it came from Saqr.

Webhooks

How it works

Each time WhatsApp reports a new status for a message you sent with the API, Saqr puts it in a CloudEvents 1.0 envelope and POSTs it to your webhook address. Each status of a message is sent at most once: up to 3 attempts (see Retries). When all of them fail, or, rarely, when Saqr fails before the first attempt, that status is not sent again. To fill a gap, read the message with GET /whatsapp/messages/{message_id}.

  1. In your Saqr workspace, open Account → Developers and save your webhook address (https).
  2. Copy the signing secret. It is shown once: keep it on your server.
  3. Send a template with POST /whatsapp/templates/send. Each of its statuses is posted to your address, signed with your secret.

The event

Every call carries one status of one message. Its type is always: template_message_status

sent

WhatsApp accepted the message and is delivering it.

delivered

The message reached the customer's phone.

read

The customer opened the message. Sent only when the customer has read receipts on.

failed

WhatsApp could not deliver the message. `error` carries WhatsApp's code and reason.

Sample event

Every event is a CloudEvents 1.0 envelope with the status in `data`. `message_id` is the id that POST /whatsapp/templates/send returned. Check the signature first, then use `id` to skip duplicates.

POST /your-webhook-urljson
{
  "specversion": "1.0",
  "type": "template_message_status",
  "source": "urn:saqr:tenant:00000000-0000-0000-0000-000000000000",
  "id": "f4d2c5b1-3a8f-4f9e-b2c1-d3e7f8a9b0c1",
  "time": "2026-11-11T10:23:45.123Z",
  "datacontenttype": "application/json",
  "saqrversion": 1,
  "tenant_id": "00000000-0000-0000-0000-000000000000",
  "data": {
    "message_id": "wamid.EXAMPLE0123456789",
    "send_id": "9c8b7a6d-0000-4000-8000-000000000001",
    "status": "delivered",
    "status_at": "2026-11-11T10:23:44.000Z",
    "recipient": "+447700900123",
    "template": { "name": "order_update", "language": "en_US" },
    "error": null
  }
}
X-Saqr-Signature

HMAC-SHA256 of the raw body, made with your signing secret. Format: sha256=<hex>

X-Saqr-Event

The event type, the same as `type` in the body

X-Saqr-Event-Id

The event's id, the same on every attempt: use it to skip duplicates

X-Saqr-Delivery-Attempt

1, 2 or 3: which attempt this is

Check the signature

Every call carries an HMAC-SHA256 signature of the raw body in the X-Saqr-Signature header, made with your signing secret. Check it before you trust the event, and reject an event whose `time` is more than 5 minutes old.

Node.js (Express)

verify-webhook.jsjavascript
// verify-webhook.js (Express middleware)
import crypto from "node:crypto";

export function verifySaqrWebhook(secret) {
  return (req, res, next) => {
    const signature = req.header("X-Saqr-Signature") || "";
    const provided = signature.replace(/^sha256=/, "");
    if (!provided) return res.status(401).send("missing signature");

    const expected = crypto
      .createHmac("sha256", secret)
      .update(req.rawBody)
      .digest("hex");

    const ok =
      provided.length === expected.length &&
      crypto.timingSafeEqual(
        Buffer.from(provided, "hex"),
        Buffer.from(expected, "hex"),
      );

    if (!ok) return res.status(401).send("invalid signature");
    next();
  };
}

Python (FastAPI)

verify_webhook.pypython
# verify_webhook.py (FastAPI dependency)
import hmac, hashlib
from fastapi import Request, HTTPException, Header

WEBHOOK_SECRET = "your-signing-secret"

async def verify_saqr_webhook(
    request: Request,
    x_saqr_signature: str = Header(None),
):
    if not x_saqr_signature:
        raise HTTPException(401, "missing signature")

    provided = x_saqr_signature.replace("sha256=", "", 1)
    body = await request.body()

    expected = hmac.new(
        WEBHOOK_SECRET.encode(),
        body,
        hashlib.sha256,
    ).hexdigest()

    if not hmac.compare_digest(provided, expected):
        raise HTTPException(401, "invalid signature")

    return body

Retries

Saqr tries each event up to 3 times: at once, after 1 second and after 3 seconds. A 2xx answer within 5 seconds counts as received. A timeout, a 5xx, a 408 or a 429 is tried again; any other 4xx is not.

Retry timing
Attempt 1: at once
Attempt 2: + 1 s
Attempt 3: + 3 s

Each attempt waits up to 5 s for a 2xx answer.

Duplicates and order

A retry can bring an event you already handled: keep the event's `id` (also in X-Saqr-Event-Id) and skip repeats. Statuses can arrive out of order (a read before a delivered), so compare `status_at`, not the order they arrive in.

Was this article helpful?