Webhooks
Receiving events, and verifying each delivery in Node, Python and PHP.
Webhooks send you an event within seconds of something happening, so you do not have to keep asking. TRAKI signs every delivery with the Standard Webhooks format, which has ready-made libraries in most languages.
The event
Every event has the same envelope:
{
"id": "evt_mi7x2k9a3f8c1d0e7b",
"type": "call.ended",
"createdAt": "2026-12-01T14:03:22.418Z",
"data": { "…": "…" }
}What a receiver can rely on:
- The
idis the same on every retry, so you can skip an event you already handled. - Order is not guaranteed. When you need the latest state, fetch the record.
- Answer within 10 seconds with any 2xx status, then do slow work afterwards.
- A failed delivery is retried about 10 times over 3 days, waiting longer each time. An endpoint that fails for 3 days is paused, and its owner is emailed.
The headers
| Header | What it holds |
|---|---|
webhook-id | The event's id |
webhook-timestamp | When this attempt was sent, in seconds since 1970 (UTC) |
webhook-signature | One or more signatures, space-separated, each v1,<base64> |
Verifying a delivery
Never trust an event before checking its signature. An unchecked webhook endpoint lets anyone post fake events to you.
- Take the endpoint's secret. It starts
whsec_; the rest is base64. Decode the rest to get the signing key. - Join the
webhook-id, thewebhook-timestampand the raw body with dots:id.timestamp.body. Use the body exactly as received, before any JSON parsing. - Compute HMAC-SHA256 of that text with the key, and base64 it.
- Compare it, in constant time, with each
v1,signature in the header. One match is enough. While a secret is being rolled, the old and the new secret both sign for 24 hours. - Refuse the event if the timestamp is more than 5 minutes away from your clock. This stops a captured event being sent again.
import crypto from 'node:crypto';
// rawBody: the request body as a string, exactly as received.
export function verifyWebhook(headers, rawBody, secret) {
const id = headers['webhook-id'];
const timestamp = headers['webhook-timestamp'];
const signatures = headers['webhook-signature'] ?? '';
if (!id || !timestamp) return false;
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64');
const expected = crypto
.createHmac('sha256', key)
.update(`${id}.${timestamp}.${rawBody}`)
.digest();
return signatures.split(' ').some((part) => {
const [version, value] = part.split(',');
if (version !== 'v1' || !value) return false;
const given = Buffer.from(value, 'base64');
return given.length === expected.length && crypto.timingSafeEqual(given, expected);
});
}In PHP, header names arrive in $_SERVER as HTTP_WEBHOOK_ID and so on; map them to the names above first.
Catching up after downtime
Your endpoint can be down for a while without losing anything: deliveries are retried for 3 days. After a longer outage, compare your copy with the lists, using updatedSince (see paging).
Managing endpoints
Endpoints are managed in the portal today, on the Webhooks page, where each has its own secret, a delivery log and a replay button. Routes to manage them from the API arrive in release 2.