Webhooks
With a webhook, Guria notifies your system the moment something happens: a message arrived, went out, was delivered, read or refused.
How it works
- You register an address
An
httpsaddress in your system and the list of events it wants to receive. In the panel or through Create a webhook. - Guria stores a secret
The response to the registration carries the secret that signs every delivery. It is shown in full only once.
- Something happens
Guria makes a
POSTto your address with the event in JSON and the signature in a header. - You answer 2xx
Within 10 seconds. Any other response counts as a failure, and the delivery is retried.
See it happen
The simulator below runs in your browser and goes through the whole cycle: your system sends a message through the API, it shows up on the customer's device, and each state comes back as a delivery to your webhook, with the signature actually computed over the body.
- 1send
- 2accepted
- 3sent
- 4delivered
- 5read
Write the message below and send it. Your system talks to Guria, the message appears here, and each of its states comes back as a delivery to your webhook, on the side.
segredo-de-exemplo-0000000000000Each step of the cycle shows up here, numbered, with who is talking to whom.
The delivery body
Every delivery has the same envelope. What changes from one event to another is the content of data.
| Field | What it is |
|---|---|
event | The event name, such as MessageReceived. |
business_id | The company the event happened in. |
timestamp | When it happened, in Unix seconds. |
data | The event data. Its fields are in snake_case. |
{
"event": "MessageReceived",
"business_id": "2ea7ad0d-8e13-4008-9fd8-7c92fe8677f2",
"timestamp": 1764092406,
"data": {
"message_id": "9e4b7c2a-6d1f-4a3e-8b5c-0f7d2a9e6c41",
"conversation_id": "3c8e1a5d-7b2f-4d6a-9e0c-5a1f8b3d7e29",
"contact_id": "af147888-ebb0-4ec9-92e5-da66cd561461",
"from": "5511988887777",
"type": "text",
"waba_message_id": "wamid.HBgNNTUxMTk4ODg4Nzc3NxUCABEYEjZDMUQ0RjNBOEIyRTdDOTUwAA==",
"timestamp": 1764092406,
"content": {
"text": "Oi, Fulano! Seu pedido saiu para entrega e chega hoje até as 18h."
},
"media_url": null
}
}- In a text message,
contentis{ "text": "…" }. In the other received types (image, audio, document, location, button),contentis the message in the WhatsApp Business API format. - When the message has media,
media_urlis a signed address to download the file, valid for 7 days.
Events
| Event | When it happens |
|---|---|
MessageReceived | A customer sent a message to one of the company's numbers. |
MessageSent | A message from the company was accepted by WhatsApp and went out. |
MessageDelivered | The message reached the customer's device. |
MessageRead | The customer opened the conversation and read the message. |
MessageFailed | WhatsApp refused the send. The body carries the code and the reason. |
Besides messages, a webhook can subscribe to the events of the company's WhatsApp account:
| Subject | Events | When it happens |
|---|---|---|
| Templates | TemplateApproved, TemplateRejected | Meta approved or rejected a template submitted for review. |
| Numbers | NumberConnected, NumberDisconnected | One of the company's numbers connected or lost its connection. |
| WhatsApp account | AccountUpdate, AccountRestricted, AccountBanned, QualityChanged, NameStatusChanged | Meta changed the account's status, quality or display name. |
The full list of accepted names comes from List the available events.
Delivery headers
| Header | What it carries |
|---|---|
X-Webhook-Signature | The signature of the body: sha256= followed by the HMAC SHA-256 in hexadecimal. |
X-Webhook-Id | The delivery id. It is the same on every attempt: use it to avoid processing twice. |
X-Webhook-Attempt | The attempt number, starting at 1. |
User-Agent | Always GuriaWebhooks/1.0, so you can recognize the origin and allow it through your firewall. |
Validating the signature
Anyone who finds out your address can send a POST to it. The signature is what proves the delivery came from Guria: compute the HMAC SHA-256 of the body exactly as it arrived, with the webhook secret, and compare it with the X-Webhook-Signature header.
import crypto from "node:crypto";
import express from "express";
const app = express();
// The signature covers the raw body: read the bytes before any conversion.
app.post("/webhooks/guria", express.raw({ type: "application/json" }), (req, res) => {
const expected = "sha256=" + crypto
.createHmac("sha256", process.env.GURIA_WEBHOOK_SECRET)
.update(req.body)
.digest("hex");
const received = req.get("X-Webhook-Signature") ?? "";
const valid = received.length === expected.length
&& crypto.timingSafeEqual(Buffer.from(received), Buffer.from(expected));
if (!valid) return res.sendStatus(401);
// Answer right away and process later: the delivery waits at most 10 seconds.
res.sendStatus(200);
enqueue(req.get("X-Webhook-Id"), JSON.parse(req.body));
});Attempts
A delivery is retried when your address answers 408, 429 or 5xx, takes longer than 10 seconds or does not accept the connection. There are up to 6 attempts:
| Attempt | When |
|---|---|
| 1st | The moment the event happens. |
| 2nd | 30 seconds after the previous attempt. |
| 3rd | 2 minutes after the previous attempt. |
| 4th | 10 minutes after the previous attempt. |
| 5th | 1 hour after the previous attempt. |
| 6th | 6 hours after the previous attempt. |
- Other
4xxresponses end the delivery right away: retrying would give the same result. - After the last attempt the delivery is closed. The panel keeps the history of each one and lets you resend it.
- Arrival order is not guaranteed: a retried delivery can arrive after a newer event. Order by
timestamp.
Good practices
- Answer fast: put the event on a queue and return
200. Slow processing comes later. - Do not process twice: store the
X-Webhook-Idof the deliveries you already handled and ignore repeats. - Subscribe only to what you use: fewer events, less traffic and less code to maintain.
- Rotate the secret if it leaks, through Rotate the signing secret. The previous one stops working immediately.