// COMPLETE REFERENCE
WhatsApp Channel
General Bots talks to WhatsApp through Meta’s Cloud API directly, without a
business-solution provider in between. Meta posts each delivery to
/api/whatsapp/webhook, the botwhatsapp crate normalises it, and the content
runs through the same bot pipeline as every other channel. Replies are buffered
for the turn and delivered as plain text messages.
This page documents what the channel does today and how to configure it. The endpoint contract is in WhatsApp API.
What the channel does
| Capability | Status | Evidence |
|---|---|---|
| Inbound text | ✅ | webhooks::normalize_payload → process_incoming_message (botwhatsapp/src/webhooks.rs:164) |
| Inbound button and list replies | ✅ | the reply title is used as the message text (utils.rs:169-185) |
| Inbound media (image, video, audio, document, sticker) | ✅ | downloaded with the bot’s access token and stored in Drive inbox/ (media.rs:39-126) |
| Outbound text | ✅ | one type: "text" message per 4096-byte part (message_processing.rs:117, utils.rs:61) |
| Outbound media, buttons, lists, templates | ❌ | the send path builds text bodies only (botserver/src/whatsapp/mod.rs:203-208) |
| Chat suggestions | ❌ | supports_suggestions() returns false (botserver/src/whatsapp/mod.rs:113) |
| Audio transcription | ❌ | transcribe_audio always returns an error (botserver/src/whatsapp/mod.rs:281) |
| Streaming | ❌ | supports_streaming() returns false; each turn is one delivery (:112) |
An inbound attachment reaches the model as a marker line, not as a file:
[image] inbox/a1b2.jpg followed by the caption when Meta sent one
(botwhatsapp/src/media.rs:218).
Credentials
The adapter reads six keys at boot (botserver/src/whatsapp/mod.rs:150-185).
Each has a dashed config.csv name and an underscored name in the bot’s
WhatsApp Vault secret; the resolution order is described below the table.
| Key | Vault field | Required | Purpose |
|---|---|---|---|
whatsapp-phone-number-id |
whatsapp_phone_number_id |
yes | Phone number id used in the Graph URL; also the value that binds an inbound delivery to a bot |
whatsapp-api-key |
whatsapp_api_key |
yes | Bearer token for Graph API calls |
whatsapp-verify-token |
whatsapp_verify_token |
yes | Expected hub.verify_token on the subscription handshake |
whatsapp-app-secret |
whatsapp_app_secret |
yes | HMAC key for X-Hub-Signature-256; without it every delivery is refused |
whatsapp-business-account-id |
whatsapp_business_account_id |
no | WABA id; read but not used by the send path |
whatsapp-api-url |
whatsapp_api_url |
no | Graph base URL; defaults to https://graph.facebook.com/v21.0 |
api-key, verify-token and app-secret contain key/token/secret, so
is_sensitive_key treats them as secrets
(botsecurity-crypto/src/secrets/add_api_key.rs:121): they belong in Vault and
are never written to config.csv. The other three live in the bot’s
config.csv, which the Drive monitor persists to bot_configuration
(config_key / config_value).
The channel reads Vault from one fixed path:
vault kv put secret/gbo/00000000-0000-0000-0000-000000000000/<bot_id>/whatsapp \
whatsapp_api_key=<token> \
whatsapp_phone_number_id=<phone-number-id> \
whatsapp_verify_token=<verify-token> \
whatsapp_app_secret=<app-secret>
This path is configured in botserver/src/whatsapp/mod.rs:125 and is not
the secret/gbo/{org}/{branch}/{bot} path the generic config resolver uses
(botcore/src/config/resolve_bot_identity.rs:25). The adapter reads Vault once,
when the router is built, so a credential change needs a botserver restart; a
config.csv change does not (the Drive monitor reloads it).
The two layouts can both hold a credential, with different key names. The
adapter’s own secret uses underscores (whatsapp_api_key); when that secret has
no such field it falls back to ConfigManager, which for a sensitive key reads
secret/gbo/{org}/{branch}/{bot} with the dashed name (whatsapp-api-key) and
then bot_configuration. An underscored value in the whatsapp secret
therefore wins. Store each credential in exactly one place.
Bind a phone number to a bot
An inbound delivery names its phone_number_id. The channel looks for a bot
whose bot_configuration has config_key = 'whatsapp-phone-number-id' and that
value (botserver/src/whatsapp/mod.rs:22). When nothing matches it falls back
to the first active bot, preferring a bot literally named cristo (:38). A
number that no bot claims therefore answers as the wrong bot rather than
failing, so configure the key on every bot that owns a number.
The outbound API names a bot with bot_id. Without it the call does not
look the recipient up: get_bot_for_phone ignores the number and returns the
same default bot (botwhatsapp/src/session_management.rs:123-134), so pass
bot_id whenever the workspace holds more than one WhatsApp number.
Configure Meta
- Create a Meta app at
developers.facebook.comand add the WhatsApp product. - Register the business number and copy its Phone Number ID and WABA ID.
- Create a permanent System User token scoped to that number; store it as
whatsapp_api_key. - Set the callback URL to
https://<your-host>/api/whatsapp/webhook, enter the verify token, and subscribe to themessagesfield. - Copy the app secret into
whatsapp_app_secret. Meta signs every POST with it, and the endpoint refuses unsigned deliveries.
The handshake is a GET on the same path: the handler requires
hub.mode=subscribe, compares hub.verify_token in constant time and echoes
hub.challenge verbatim (botwhatsapp/src/webhooks.rs:100-123). A wrong mode or
token answers 403; a missing challenge answers 400.
Webhook security
Every POST must carry X-Hub-Signature-256: sha256=<hex>, the HMAC-SHA256 of
the raw request bytes keyed with the app secret. The gate fails closed
(botwhatsapp/src/webhooks.rs:140-154):
| App secret | Signature | Result |
|---|---|---|
| empty | anything | 403 — every delivery refused |
| set | valid, lowercase hex | processed |
| set | missing, malformed, uppercase or wrong | 403 |
Meta retries a delivery whose 200 is slow, and media ingestion is slow, so the
channel remembers the last 1,000 message ids and drops a repeat
(webhooks.rs:66-95). statuses entries are logged and are not turns;
object values other than whatsapp_business_account answer 200 ignored.
Sending a message from a bot
Inside an inbound conversation, TALK is enough: the reply is buffered, HTML is
stripped and the text is sent back to that phone number.
For anything else, POST /api/whatsapp/send. The Basic keywords that name a
channel do not deliver over WhatsApp in this runtime:
| Attempt | Result |
|---|---|
TALK "…" in an inbound turn |
sent to the sender |
POST /api/whatsapp/send |
sent; see the API page |
SEND TO "whatsapp:+5511…", "…" |
error — the adapter is a stub (botbasic_comms/.../send_message.rs:6) |
SEND FILE TO "whatsapp:+5511…", file |
error — no media-upload adapter (send_file_to_recipient.rs:138) |
SEND_TEMPLATE "…", "+5511…", "whatsapp" |
returns success: true / status: "queued" without calling a provider (messaging/send_template/sending.rs:56) |
Campaign or /api/crm/whatsapp/send |
send_whatsapp is wired to a stub returning "stub" (main_module/routes/feature_routers/make_saas_router.rs:225) |
Treat the template and campaign rows as unavailable, not as slow: no Graph call is made.
Limits and format
- Message length. Outbound text is split at 4,096 bytes on line boundaries
where possible (
utils.rs:61). - Phone numbers.
format_phone_numberkeeps digits only, drops one leading zero and prefixes55unless the number already starts with5(utils.rs:1). That assumes a Brazilian number: a US number14155551234becomes5514155551234. Send numbers whose country code begins with5, or normalise them before the call. - 24-hour window. Outside the 24 hours that follow a user message, Meta only delivers approved templates. The channel cannot send templates (see above), so a business-initiated message has to be started by the user or sent from WhatsApp Manager.
Troubleshooting
| Symptom | Cause | Check |
|---|---|---|
403 Webhook signature not configured |
whatsapp_app_secret empty |
Vault entry, then restart |
403 Invalid signature |
wrong app secret, or the body was re-serialised before hashing | secret matches Meta, raw bytes |
403 Invalid verify token |
whatsapp_verify_token differs from Meta |
compare the two exactly |
| Deliveries processed by the wrong bot | no whatsapp-phone-number-id match |
config_key row for that bot |
WhatsApp not configured: missing phone_number_id or api_key in the log |
one of the two required keys is empty | status endpoint |
| Message sent but the reply never arrives | access token expired or number not in the test list | Meta API Setup |
| Reply truncated at a paragraph | 4,096-byte split | expected behaviour |
| Bot answers that media or templates are unavailable | capability absent, by design | table above |
GET /api/whatsapp/status reports configured only when both
whatsapp_verify_token and whatsapp_api_key resolve; it is the fastest check
after a restart.
Related
- WhatsApp API — routes, bodies, responses
- Channel Integrations — the shared
ChannelAdaptercontract - Signature Matrix — provider signature comparison
- Connect WhatsApp — the same setup from the UI