Webhooks
Configure Wayits Gateway webhooks, understand event payloads, and verify deliveries in Node.js, Python, or Go.
Use a Gateway webhook to receive WhatsApp events on your server without polling the API. Wayits sends an HTTP POST with a JSON body and an HMAC signature to the callback URL configured for your session.
Gateway and legacy webhooks are separate
This guide covers Gateway webhooks, configured through the Gateway API. They send an event envelope and use X-Hub-Signature-256. The legacy
inbound-message webhook sends message.received with a different body and uses X-Webhook-Secret. Do not use the Gateway signature examples to
verify legacy deliveries.
Configure an endpoint
- Deploy a receiver at a public HTTPS URL on port 443. The Wayits operator must add its exact hostname to
WHATSAPP_GATEWAY_ALLOWED_HOSTS. Wayits does not follow redirects or allow credentials in callback URLs. - Create a Bearer API key and list your WhatsApp sessions. Use
results[].idas thedevice_idin the configuration URL. - Choose your event subscriptions and call
PATCH /devices/{device_id}/webhook. Configure the same signing secret on your receiver before you trigger an event.
Set WAYITS_API_URL to your API origin without a trailing slash, WAYITS_API_KEY to an API key, and WAYITS_DEVICE_ID to the session ID. The example uses jq to omit the signing secret from terminal output. If you omit webhook_secret when creating the configuration, Wayits generates one and returns it as results.webhook_secret. Retrieve it securely using the configuration endpoint and store it as WAYITS_WEBHOOK_SECRET on your receiver, not in client-side code or logs.
curl --fail-with-body --silent --show-error \
--request PATCH \
--url "$WAYITS_API_URL/api/gateway/devices/$WAYITS_DEVICE_ID/webhook" \
--header "Authorization: Bearer $WAYITS_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"webhook_url": "https://receiver.example.com/whatsapp",
"webhook_events": "message,message.ack"
}' | jq 'del(.results.webhook_secret)'Gateway supports one callback configuration per session. Event names are comma-separated and case-insensitive. An empty event list ("webhook_events": "") subscribes to all supported events; omitted fields keep their current values. Send "webhook_url": "" to remove the configuration and cancel its queued deliveries.
Supported events
| Category | Events |
|---|---|
| Messages | message, message.reaction, message.revoked, message.edited, message.deleted |
| Receipts | message.ack |
| Presence and groups | presence, chat_presence, group.participants, group.info, group.joined |
| Labels and newsletters | label.edit, label.association, newsletter.joined, newsletter.left, newsletter.message, newsletter.mute |
| Calls and sessions | call.offer, device.logged_out, device.temporary_ban, device.reachout_timelock |
Event envelope
Route each delivery using event before reading payload. Treat fields that are not needed by your integration as optional and ignore unknown event types. The envelope does not include a universal delivery ID.
| Field | Meaning |
|---|---|
event | Event name, such as message or message.ack. |
device_id | WhatsApp account identifier (JID). |
session_id | Wayits session ID, also used as the device_id path parameter when configuring the webhook. |
timestamp | UTC timestamp included for some events, such as receipts. |
payload | Event-specific data. |
Message events
message covers both incoming and outgoing messages. Check payload.is_from_me before sending an automatic reply. A reply can add replied_to_id, replied_to_sender, and quoted_body; mentions appear in mentions when present.
{
"event": "message",
"device_id": "15550000001@s.whatsapp.net",
"session_id": "example-session-id",
"payload": {
"id": "example-message-id",
"chat_id": "15550000002@s.whatsapp.net",
"from": "15550000002@s.whatsapp.net",
"from_name": "Example sender",
"is_from_me": false,
"body": "Hello",
"timestamp": "2026-01-01T00:00:00.000Z"
}
}Media may also appear as video, audio, document, or sticker. Metadata depends on what WhatsApp supplies; the url is not a guarantee of a public, reusable file. Structured non-media fields include location, contact, contacts, and poll for poll creation.
| Event | Fields to read in payload |
|---|---|
message.edited | original_message_id identifies the edited message; body contains the new text. |
message.revoked | revoked_message_id identifies a message removed for everyone. |
message.deleted | deleted_message_id identifies a locally deleted message. |
message.reaction | reacted_message_id identifies the target; an empty reaction means the reaction was removed. |
Receipt events
message.ack reports delivered, read, or played. Apply the update to each message ID in payload.ids, using chat_id to identify the conversation and from to identify who acknowledged it.
{
"event": "message.ack",
"device_id": "15550000001@s.whatsapp.net",
"session_id": "example-session-id",
"timestamp": "2026-01-01T00:01:00.000Z",
"payload": {
"ids": ["example-message-id"],
"chat_id": "15550000002@s.whatsapp.net",
"from": "15550000002@s.whatsapp.net",
"receipt_type": "read",
"receipt_type_description": "read"
}
}Presence and group events
chat_presence reports composing or paused; media: "audio" indicates recording. For presence, read the contact's state and optional last_seen. Use presence subscription when you need updates for a contact.
group.participants reports join, leave, promote, or demote and lists affected users in jids. group.info reports the new name and may include name_set_by. group.joined contains the new group's chat_id and name.
{
"event": "chat_presence",
"device_id": "15550000001@s.whatsapp.net",
"session_id": "example-session-id",
"timestamp": "2026-01-01T00:02:00.000Z",
"payload": {
"from": "15550000002@s.whatsapp.net",
"chat_id": "15550000002@s.whatsapp.net",
"state": "composing",
"media": "",
"is_group": false
}
}Label and newsletter events
Newsletter message updates require an active live subscription.
| Event | Fields to read in payload |
|---|---|
label.edit | label_id, name, color, optional predefined_id, and deleted. |
label.association | label_id, chat_id, and labeled (true when applied). |
newsletter.joined, newsletter.left | newsletter_id identifies the channel. |
newsletter.message | newsletter_id and messages[]; each update contains server_id and the reported views_count or reaction_counts. |
newsletter.mute | newsletter_id and mute, which can be a string or boolean. |
{
"event": "label.association",
"device_id": "15550000001@s.whatsapp.net",
"session_id": "example-session-id",
"timestamp": "2026-01-01T00:04:00.000Z",
"payload": {
"label_id": "9",
"chat_id": "15550000002@s.whatsapp.net",
"labeled": true
}
}Call and session events
call.offer contains call_id, from, and auto_rejected. Group calls may include group_jid. To reject a ringing call, pass payload.from as caller_jid and payload.call_id as call_id to POST /call/reject.
| Event | Fields to read in payload |
|---|---|
device.logged_out | code, reason, and on_connect. |
device.temporary_ban | code, reason, and expires_in_seconds. A value of 0 means the duration is unknown. |
device.reachout_timelock | is_active, optional enforcement_type, and optional ends_at. |
{
"event": "call.offer",
"device_id": "15550000001@s.whatsapp.net",
"session_id": "example-session-id",
"timestamp": "2026-01-01T00:06:00.000Z",
"payload": {
"call_id": "example-call-id",
"from": "15550000002@s.whatsapp.net",
"auto_rejected": false
}
}Verify the signature
Verify X-Hub-Signature-256 before parsing JSON or performing any action. Its value is sha256= followed by the hexadecimal HMAC-SHA256 digest of the exact raw request body, using the signing secret as the key. Reject missing or malformed signatures and compare the digest in constant time. Do not reserialize parsed JSON or decode a hex-looking secret into bytes: Wayits uses the secret string itself.
Each example shows the same two steps: verify the signature, then decode the event. No framework or extra library is required.
- In your HTTP handler, read the raw body as bytes and get the
X-Hub-Signature-256header. Pass both to the example along withWAYITS_WEBHOOK_SECRETfrom your server configuration. - Return
401if signature verification fails (undefinedin Node.js,PermissionErrorin Python, orErrInvalidSignaturein Go). Return400for invalid JSON. A missing secret is a server configuration error. - Use the decoded
eventname to validate its payload. Return204only after storing the event or adding it to a durable queue. Return503if you cannot save it.
import { createHmac, timingSafeEqual } from 'node:crypto';
export function decodeWebhook(rawBody, signature, secret) {
if (!secret) throw new Error('WAYITS_WEBHOOK_SECRET is required');
const digest = createHmac('sha256', secret).update(rawBody).digest('hex');
const expected = Buffer.from(`sha256=${digest}`);
const received = Buffer.from(signature ?? '');
if (received.length !== expected.length || !timingSafeEqual(received, expected)) {
return undefined;
}
return JSON.parse(Buffer.from(rawBody).toString('utf8'));
}Delivery, retries, and rotation
- Acknowledge after persisting. Return any
2xxresponse after your application stores the event or adds it to a durable queue. Run slow tasks outside the HTTP handler. Wayits allows up to 10 seconds per attempt and makes at most five total attempts with backoff for failed deliveries. Redirects are not followed. - Expect duplicates and reordered events. Use an idempotency key appropriate to your handler. For
message, for example, usesession_id,payload.chat_id, andpayload.idtogether. For a receipt, also include its type and sender, and process each ID inpayload.ids. Do not assume exactly-once delivery or deduplicate unrelated event types by message ID alone. - Rotate with a deployment plan. Gateway configuration accepts a replacement
webhook_secretof 32–128 characters. Wayits uses the current secret and URL for pending attempts. If a receiver must accept overlapping in-flight requests during rotation, temporarily accept both secrets and remove the old one once the transition is complete. - Protect user data. Do not log signatures, secrets, or full message payloads. Set a body size limit appropriate for your integration and keep the webhook receiver on HTTPS.
Troubleshooting
| Symptom | What to check |
|---|---|
Configuration returns 400 | Verify the hostname allowlist, HTTPS/443, and event spelling. |
Configuration returns 401 or 404 | Check the Bearer key and confirm the session belongs to that account. |
Receiver returns 401 | Verify that both sides use the same secret and that you sign the raw body before parsing or transforming it. Confirm this is a Gateway delivery and not a legacy webhook. |
| No deliveries reach the receiver | Confirm the session is connected, the event is subscribed, the Gateway worker is running, and the callback path does not redirect. Trigger a fresh event, such as an incoming chat, and inspect receiver access logs for the response status. |
| Deliveries repeat | Check that the receiver returns 2xx within the timeout, even when it recognizes an event it has already stored. |