Webhooks
Inbound webhook contracts for WhatsApp, Teams, and Matrix — the only channels wired to the REST API today.
4 min read
Anvio channels connect to their platforms in one of two ways: outbound polling/WebSocket (Telegram, Discord, Slack, Signal, Mattermost, most channels) or inbound HTTP webhook (WhatsApp, Teams, Matrix). This page documents the three webhook controllers that actually exist in apps/api/src.
Only WhatsApp, Teams, and Matrix have webhook controllers in apps/api/src as of this writing. If you're looking for Slack, Telegram, Discord, Signal, Google Chat, Feishu, SMS, Mattermost, or Email, see Channel Adapters — they use bot polling, signal-cli REST, or SMTP/IMAP instead of an inbound API webhook.
Source: apps/api/src/whatsapp.controller.ts, adapter: packages/channels/src/whatsapp.ts
Meta's Cloud API webhook contract: a GET verification handshake, then POST for real events.
Verification handshake
GET /api/channels/whatsapp/webhook
Meta calls this once when you register the webhook URL in the Meta App Dashboard.
Query params: hub.mode, hub.verify_token, hub.challenge.
// packages/channels/src/whatsapp.ts
verifyWebhook(query): string | null {
if (
query['hub.mode'] === 'subscribe' &&
query['hub.verify_token'] === this.options.verifyToken &&
query['hub.challenge']
) {
return query['hub.challenge'];
}
return null;
}- Match: responds
200with the rawhub.challengestring. - Mismatch: responds
403 Forbidden. - Channel not enabled: responds
404.
The expected verifyToken comes from WHATSAPP_VERIFY_TOKEN (env) or channels.whatsapp.verifyToken in config, falling back to the literal 'anvio-verify' if neither is set — see packages/channels/src/create-channels.ts.
The default verify token is the literal string anvio-verify if WHATSAPP_VERIFY_TOKEN is unset. Always set this explicitly in production — an unset/default verify token means anyone who knows the default can pass Meta's handshake against your endpoint.
Inbound events
POST /api/channels/whatsapp/webhook
Body is the raw Meta Cloud API webhook payload:
{
"object": "whatsapp_business_account",
"entry": [{
"changes": [{
"value": {
"messages": [{ "from": "15551234567", "type": "text", "text": { "body": "hi" } }],
"contacts": [{ "wa_id": "15551234567" }]
}
}]
}]
}The controller calls whatsapp.handleWebhook(body) unconditionally and returns 200 OK. If payload.object !== 'whatsapp_business_account', the handler silently returns (still 200) — Meta expects a fast 200 regardless of whether the payload matched.
No signature verification (X-Hub-Signature-256 HMAC check) is implemented in packages/channels/src/whatsapp.ts as of this writing. The endpoint trusts any POST body shaped like a WhatsApp payload. If you expose this publicly, put it behind a reverse proxy that validates the Meta signature, or track this as a hardening item.
Each inbound text message resolves (or creates) a session keyed by phone:<wa_id> via ChannelSessionBridge, then the adapter's registered handler publishes anvio.agent.run.requested.v1 on the event bus (see Event Model).
Microsoft Teams
Source: apps/api/src/teams.controller.ts, adapter: packages/channels/src/teams.ts
POST /api/channels/teams/webhook
Body is a Bot Framework Activity object:
{
"type": "message",
"text": "hello",
"serviceUrl": "https://smba.trafficmanager.net/...",
"from": { "id": "29:1abc...", "name": "Jane" },
"conversation": { "id": "19:abc..." }
}The controller checks the teams adapter is registered on the ChannelHub (getAdapter('teams') instanceof TeamsChannel); if not, 404. Otherwise it calls adapter.handleActivity(activity) and returns 200 {}.
TeamsChannel is registered unconditionally in packages/channels/src/create-channels.ts (it does not gate on channels.teams.enabled), but it only becomes fully functional once appId, appPassword, and serviceUrl are set (isConfigured()). Special case: activities of type: "invoke" (adaptive card actions, e.g. approve/reject buttons) are routed through handleInvokeActivity() instead of the normal message path and return null.
Matrix
Source: apps/api/src/matrix.controller.ts, adapter: packages/channels/src/matrix.ts
POST /api/channels/matrix/webhook
Body:
{ "roomId": "!abc123:matrix.org", "senderId": "@jane:matrix.org", "body": "hello" }All three fields (roomId, senderId, body) are required — the controller returns 400 Bad Request if any is missing. It then checks the matrix adapter is registered (404 if not), calls adapter.handleRoomMessage({ roomId, senderId, body }), and returns 200 { ok: true }.
Like Teams, MatrixChannel requires homeserverUrl, accessToken, and roomId to be set (isConfigured()) before it does anything beyond acknowledging the webhook. Empty/whitespace-only body is silently ignored (returns null, still 200).
Common shape
All three webhook controllers follow the same pattern, defined per-controller rather than via a shared NestJS guard or interceptor:
Configuring webhook URLs
None of these env vars appear in .env.example by default (they're read directly via process.env.* in packages/channels/src/create-channels.ts, or set in workspace/anvio.yaml under channels:). Relevant variables:
| Channel | Variables |
|---|---|
WHATSAPP_ACCESS_TOKEN, WHATSAPP_PHONE_NUMBER_ID, WHATSAPP_VERIFY_TOKEN | |
| Teams | TEAMS_APP_ID, TEAMS_APP_PASSWORD, TEAMS_SERVICE_URL |
| Matrix | MATRIX_HOMESERVER_URL, MATRIX_ACCESS_TOKEN, MATRIX_USER_ID, MATRIX_ROOM_ID |
Point your platform's webhook configuration at https://<your-api-host>/api/channels/<name>/webhook.
Last updated on