Webhooks
A webhook sends what happens in Welkai, such as a new message, to an address on your server as it happens. Each number or channel has its own webhook address and its own secret. Webhooks work on every plan.
Set the address
In the dashboard: Channels, the channel's card menu, Channel webhook. Fill the address and save; the Signing secret is shown there. Pick which events to send under API and webhooks, Webhooks, Default webhook events.
With the full API (key scopes numbers and read):
curl -X PATCH https://your-business.welkai.net/devices/<device_id>/webhook \
-H "Authorization: Bearer <your key>" -H "Content-Type: application/json" \
-d '{"webhook_url": "https://crm.example.com/welkai", "webhook_events": "message,contact.opted_out"}'
The answer carries webhook_secret. Keep it: reading the webhook settings again with a key does not show it. Send your own webhook_secret in the same request to choose it yourself. Several addresses can be given, separated by commas. webhook_events is a comma-separated list; leave it empty to get every event.
Then send a test event, POST /devices/<device_id>/webhook/test (or Send a test event in the dashboard). It goes at once, outside the queue, signed like every other request, and the answer shows what your server replied.
What arrives
Every event is an HTTPS POST with a JSON body:
{
"event": "message",
"device_id": "628987654321@s.whatsapp.net",
"session_id": "my-number",
"timestamp": "2026-11-15T09:30:00Z",
"payload": {
"id": "3EB0C127D7BACC83D6A1",
"chat_id": "628123456789@s.whatsapp.net",
"from": "628123456789@s.whatsapp.net",
"timestamp": "2026-11-15T09:30:00Z",
"is_from_me": false,
"body": "Hello, is the blue one in stock?",
"contact_external_id": "crm-10042"
}
}
event: the event's name (below).device_id: the number's own id on its channel.session_id: the number's id in Welkai, the one you send asX-Device-Id.payload: the event's details. Every event's full example is in the API reference, under Webhooks.contact_external_id: your CRM's id for the contact, when one is set on it (see Connect a CRM).
Every channel (WhatsApp by QR, the official API, Messenger, Instagram, Telegram and mailboxes) sends the same message event shape, with the same headers and signature.
Events
| Event | When |
|---|---|
message | A customer sent a message: text, photo, file, location and more. |
message.reaction | Someone reacted to a message with an emoji. |
message.edited | A message was edited. |
message.revoked | A message was deleted for everyone. |
message.deleted | A message was deleted for you only. |
message.ack | A message you sent was delivered or read. |
chat_presence | A customer is typing or recording a voice note. |
label.edit | A WhatsApp label was made, renamed or removed. |
label.association | A WhatsApp label was put on or taken off a chat. |
contact.opted_out | A contact asked to get no more campaigns. |
contact.opted_in | A contact said yes to campaigns again. |
group.participants | People joined, left, or became or stopped being group admins. |
group.joined | Your number was added to a group. |
newsletter.joined | Your number followed a WhatsApp channel. |
newsletter.left | Your number stopped following a WhatsApp channel. |
newsletter.message | A WhatsApp channel you follow posted. |
newsletter.mute | A WhatsApp channel was muted or unmuted. |
call.offer | A customer is calling. |
call.ready | A call connected. |
call.ended | A call ended. |
call.placed | A call you queued was dialled, or could not be. |
call.ack | Whether the person you called sent back the confirm code. |
flow.run.started | A flow started for a contact. |
flow.run.completed | A flow finished for a contact. |
flow.run.failed | A flow stopped with an error. |
flow.alert | A flow's Alert team step fired. |
webhook.test | A test you sent to check your address works. |
Headers
| Header | Value |
|---|---|
X-Hub-Signature-256 | sha256= and the hex HMAC-SHA256 of the body |
X-Welkai-Timestamp | Unix seconds when this try was sent |
X-Welkai-Signature | v1= and the hex HMAC-SHA256 of the timestamp, a dot, then the body |
X-Welkai-Delivery | The delivery's id, the same on every try |
X-Welkai-Attempt | This try's number, from 1 |
X-Welkai-Resend-Of | Only on a delivery sent again by hand: the id of the first one |
User-Agent | Welkai-Webhooks/1 |
Check the signature
Both signatures use the channel's signing secret, as text, as the HMAC key, and the raw body exactly as it arrived: check before you parse the JSON. Check X-Welkai-Signature and refuse a timestamp more than 5 minutes from your clock, so a request copied and sent again later is refused. X-Hub-Signature-256 signs the body alone, for tools that only know that header. Both are made again on every try with the secret the channel has at that moment, so after you change the secret a retry of an older event is signed with the new one. Compare in constant time.
Node.js
import crypto from "node:crypto";
import express from "express";
const SECRET = process.env.WELKAI_WEBHOOK_SECRET;
const hmac = (text) => crypto.createHmac("sha256", SECRET).update(text).digest("hex");
const same = (a = "", b = "") => {
const x = Buffer.from(a), y = Buffer.from(b);
return x.length === y.length && crypto.timingSafeEqual(x, y);
};
function signedByWelkai(raw, headers) {
const ts = headers["x-welkai-timestamp"];
if (!ts || Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false;
return same(headers["x-welkai-signature"], "v1=" + hmac(Buffer.concat([Buffer.from(ts + "."), raw])));
}
// the older header, body only
const hubSigned = (raw, headers) => same(headers["x-hub-signature-256"], "sha256=" + hmac(raw));
const app = express();
app.post("/welkai", express.raw({ type: "application/json" }), (req, res) => {
if (!signedByWelkai(req.body, req.headers)) return res.sendStatus(401);
const event = JSON.parse(req.body);
// save it, answer at once, do the work afterwards
res.sendStatus(200);
});
Python
import hashlib, hmac, os, time
SECRET = os.environ["WELKAI_WEBHOOK_SECRET"].encode()
def signed_by_welkai(raw: bytes, headers) -> bool:
ts = headers.get("X-Welkai-Timestamp", "")
if not ts.isdigit() or abs(time.time() - int(ts)) > 300:
return False
expected = "v1=" + hmac.new(SECRET, ts.encode() + b"." + raw, hashlib.sha256).hexdigest()
return hmac.compare_digest(headers.get("X-Welkai-Signature", ""), expected)
def hub_signed(raw: bytes, headers) -> bool: # the older header, body only
expected = "sha256=" + hmac.new(SECRET, raw, hashlib.sha256).hexdigest()
return hmac.compare_digest(headers.get("X-Hub-Signature-256", ""), expected)
# Flask: signed_by_welkai(request.get_data(), request.headers)
PHP
<?php
$secret = getenv('WELKAI_WEBHOOK_SECRET');
$raw = file_get_contents('php://input');
$ts = $_SERVER['HTTP_X_WELKAI_TIMESTAMP'] ?? '';
$sig = $_SERVER['HTTP_X_WELKAI_SIGNATURE'] ?? '';
$fresh = ctype_digit($ts) && abs(time() - (int) $ts) <= 300;
$expected = 'v1=' . hash_hmac('sha256', $ts . '.' . $raw, $secret);
if (!$fresh || !hash_equals($expected, $sig)) {
http_response_code(401);
exit;
}
// the older header, body only:
// hash_equals('sha256=' . hash_hmac('sha256', $raw, $secret), $_SERVER['HTTP_X_HUB_SIGNATURE_256'] ?? '')
$event = json_decode($raw, true);
http_response_code(200);
Go
package webhook
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"io"
"net/http"
"strconv"
"time"
)
func sign(secret, text []byte) string {
m := hmac.New(sha256.New, secret)
m.Write(text)
return hex.EncodeToString(m.Sum(nil))
}
// SignedByWelkai checks X-Welkai-Signature and refuses a timestamp older than 5 minutes.
func SignedByWelkai(secret, raw []byte, h http.Header) bool {
ts := h.Get("X-Welkai-Timestamp")
sec, err := strconv.ParseInt(ts, 10, 64)
if err != nil || time.Since(time.Unix(sec, 0)).Abs() > 5*time.Minute {
return false
}
want := "v1=" + sign(secret, append([]byte(ts+"."), raw...))
return hmac.Equal([]byte(want), []byte(h.Get("X-Welkai-Signature")))
}
// HubSigned checks the older header, body only.
func HubSigned(secret, raw []byte, h http.Header) bool {
return hmac.Equal([]byte("sha256="+sign(secret, raw)), []byte(h.Get("X-Hub-Signature-256")))
}
func Handler(secret []byte) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
raw, err := io.ReadAll(io.LimitReader(r.Body, 1<<20))
if err != nil || !SignedByWelkai(secret, raw, r.Header) {
http.Error(w, "bad signature", http.StatusUnauthorized)
return
}
// save raw, answer at once, do the work afterwards
w.WriteHeader(http.StatusOK)
}
}
Delivery rules
Every event goes into a queue on Welkai's side first, so a slow or stopped server loses nothing and a restart on our side drops nothing that is waiting.
- Success is any 2xx answer within 10 seconds. Anything else is a failed try. Save the event, answer, then do the work.
- Retries: 10 tries in all. After a failed try the next waits 1 minute, 5 minutes, 15 minutes, 1 hour, 3 hours, 6 hours, 12 hours, 24 hours, then 24 hours. An event not delivered after its 10th try, or 72 hours after it happened, is marked failed. A
429or503withRetry-Afteris honoured when it asks for longer, up to 24 hours. - A stopped server is not flooded: while a channel's address keeps failing, one waiting event is tried at a time, and the rest follow as soon as one succeeds. At most 2 requests per channel are in flight at once.
- At least once: an event can arrive more than once, for example when your server saved it but its answer was lost. Every try of one event carries the same
X-Welkai-Delivery: store the ids you have handled and skip a repeat. - No order is promised: a retry can arrive after newer events. Order by the payload's
timestampand the message ids, never by arrival. - Sent again by hand: a failed event sent again from the dashboard or the API is a new delivery with a new
X-Welkai-DeliveryandX-Welkai-Resend-Ofnaming the first. Dedupe on the first id when that header is there. - Redirects: only
307and308to the same scheme, host and port are followed (at most 3, never from https to http), so the signature always reaches you. Any other redirect is a failed try: use the final address. - Private addresses: an address on a private network is refused, and the event is marked failed at once.
- Size: a payload over 256 KB is cut to its short fields (ids, times, media links) and carries
"truncated": true. Fetch the full message through the API. - Media links in a payload are signed when each try is sent and work for 7 days from that try.
- Limits: up to 20,000 events or 50 MB wait per channel. Past that, the oldest waiting events are dropped.
- Changing the address keeps waiting events: each try goes to the address the channel has at that moment. Removing the address, or the channel, cancels them.
- The delivery log keeps delivered events 7 days (their content 24 hours) and failed or cancelled ones 30 days.
The delivery log
The dashboard shows every delivery under API and webhooks, Webhooks, Deliveries, with the answer your server gave and Send again. The same with the full API (scopes numbers and read):
| Request | What it does |
|---|---|
GET /webhooks/deliveries?device_id=<id> | Deliveries, newest first |
GET /webhooks/deliveries/<id> | One delivery with its tries and payload, while it is kept |
POST /webhooks/deliveries/<id>/resend | Send it again as a new delivery |
POST /webhooks/deliveries/resend-failed with {"device_id": "<id>"} | Send every failed delivery of a channel again, once a minute |
When a channel's webhook keeps failing for an hour, people who manage that channel get a notice in the dashboard and by email.