# Webhooks Signed HTTPS callbacks for incoming messages, delivery status and order changes: events, payloads, signature check and retries. A webhook is a URL on **your** server. The platform sends an HTTP `POST` to it when something happens, so you do not have to poll. ## Add an endpoint Dashboard: **Developers > Webhooks**. Paste the URL, pick the events (or all), press add. The **signing secret** (`whsec_...`) is shown once; you can create a new one any time ("New secret"). Only the workspace owner manages webhooks. Up to 5 endpoints per workspace. **Test** sends a `ping` event so you can see your server answer. URL rules, for security: `https` only, default port, no username or password in the URL, and the address must resolve to a **public** internet address (never a private or internal one). The check is repeated at delivery time. ## Events | Event | When | |---|---| | `message.received` | A customer sent you a message | | `message.status` | A message you sent changed status: `sent`, `delivered`, `read` or `failed` | | `order.updated` | An order's status changed (by your team or by the customer's reply) | | `ping` | You pressed **Test**. `data` is `{ "message": "Test from EasyTawasul" }` | ## The request ```http POST /your/webhook HTTP/1.1 Content-Type: application/json User-Agent: EasyTawasul-Webhooks/1 X-Webhook-Event: message.status X-Webhook-Id: 3f1c2a9e-... X-Webhook-Timestamp: 1790000000 X-Webhook-Signature: sha256=9a8b... ``` ```json { "id": "3f1c2a9e-5b7e-4d0a-9c44-0e6a1f2b7d10", "event": "message.status", "created_at": "2026-10-22T10:00:05+03:00", "data": { "message_id": "wamid.HBg...", "id": "msg_81", "client_reference": "order-1042", "status": "delivered" } } ``` ### `data` by event `message.received`: ```json { "conversation_id": 12, "from": "201000000000", "name": "Mona", "type": "text", "text": "Hello", "at": "2026-10-22T10:01:00+03:00" } ``` `message.status`: `message_id` (WhatsApp's id), `id` (the API id `msg_...`), `client_reference` (yours, or `null`), `status`, and `error` when failed. `order.updated`: `{ "order_id": 17, "external_id": "S-1042", "status": "confirmed" }` (`order_id` is the platform's number; `external_id` is yours). ## Verify the signature The signature is `HMAC-SHA256` of `timestamp + "." + raw request body` with your secret, hex encoded, prefixed `sha256=`. Compute it on the **raw body** (before JSON parsing) and compare in constant time. Reject requests whose timestamp is more than 5 minutes old. ```js import crypto from 'node:crypto'; export function verify(rawBody, headers, secret) { const ts = headers['x-webhook-timestamp']; if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false; const expected = 'sha256=' + crypto.createHmac('sha256', secret).update(`${ts}.${rawBody}`).digest('hex'); const got = headers['x-webhook-signature'] || ''; return got.length === expected.length && crypto.timingSafeEqual(Buffer.from(got), Buffer.from(expected)); } ``` ```php $ts = $_SERVER['HTTP_X_WEBHOOK_TIMESTAMP'] ?? ''; $raw = file_get_contents('php://input'); $ok = abs(time() - (int) $ts) <= 300 && hash_equals('sha256=' . hash_hmac('sha256', $ts . '.' . $raw, $secret), $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? ''); ``` ## Answer and retries Return any `2xx` within 8 seconds. Redirects are not followed. Otherwise the delivery is retried after **1 minute, 5 minutes, 30 minutes, 2 hours and 6 hours**, then it is marked stopped. The dashboard shows the latest deliveries, their status code and attempts. Handle duplicates: use `X-Webhook-Id` (or `id` in the body) as an idempotency key.