Webhooks
Signed status events, retries and verification.
Add an HTTPS endpoint under Developers → Webhooks for a project and choose its events. SMS21 sends a signed POST whenever a message changes status. The signing secret (whsec_…) is shown once.
Events
| Event | When |
|---|---|
message.submitted | Handed to a provider. |
message.sent | Left the provider platform. |
message.delivered | Delivered to the handset. |
message.failed | Could not be delivered. |
message.rejected | Refused (invalid number, policy, DLT). |
message.expired | No final report in time. |
message.received | Someone messaged one of your numbers: an SMS reply, a WhatsApp Official reply or a message to a linked WhatsApp Connect number (see channel, senderName and media). |
webhook.test | Sent when you click “Send test event”. |
"sample": true | Marks an example message.received sent from the dashboard (“Send sample message”). It references nothing. |
Body
{
"id": "evt_01k55q8y4m3d9v7x2c6b0n1r8t",
"event": "message.delivered",
"timestamp": "2026-09-15T10:30:04.000Z",
"messageId": "msg_01k55q8y4m3d9v7x2c6b0n1r8t",
"status": "delivered",
"channel": "sms",
"type": "otp",
"environment": "live",
"failure": null
}| Header | Value |
|---|---|
sms21-signature | t=<unix seconds>,v1=<hex> |
sms21-timestamp | Same as t. |
sms21-event-id | The event id — identical on every retry. |
sms21-event-type | The event name. |
sms21-delivery-id | This delivery to this endpoint. |
sms21-attempt | Attempt number, starting at 1. |
Verify every request
- Read the raw body — before any JSON parsing or re-serialization.
- Compute HMAC-SHA256 of
"<t>.<raw body>"with your secret and compare it in constant time with eachv1value (several appear while a secret rotates). - Reject the request when
tis more than 5 minutes away from your clock. - Ignore event IDs you have already processed.
import { webhooks, WebhookSignatureError } from '@sms21/node';
// Express: app.post('/webhooks/sms21', express.raw({ type: 'application/json' }), handler)
export function handler(req, res) {
let event;
try {
event = webhooks.constructEvent({
payload: req.body, // Buffer
signature: req.headers['sms21-signature'],
secret: process.env.SMS21_WEBHOOK_SECRET,
});
} catch (error) {
if (error instanceof WebhookSignatureError) return res.sendStatus(400);
throw error;
}
res.sendStatus(204);
queue.add('sms21-event', event, { jobId: event.id }); // dedupe on event.id
}Responses and retries
- Answer with any
2xxwithin 10 seconds. Process the event asynchronously. - Other responses, timeouts and connection errors are retried with backoff — 30 s, 2 min, 10 min, 30 min, 1 h, 3 h, 6 h — up to 8 attempts by default.
- An endpoint that keeps failing (50 consecutive failures by default) is disabled; re-enable it in the dashboard.
- Deliveries are at-least-once and can arrive out of order: compare
timestampand never move a message backwards.
Endpoint security
Endpoints must be public HTTPS URLs; SMS21 refuses private and internal addresses. Store the secret like a password, and rotate it from the dashboard if it leaks.