How to connect a WhatsApp agent
This guide connects a WhatsApp number to your Agent: someone messages your business number, your agent answers on WhatsApp, and the conversation is remembered across messages.
WhatsApp is a webhook channel, like Telegram. Meta’s WhatsApp Cloud API delivers messages to a public webhook URL, and replies go out over the Graph API. You need a Meta developer app with the WhatsApp product added.
Prerequisites
Section titled “Prerequisites”- A Meta developer app with the WhatsApp product added, and a phone number (the test number Meta provides is fine to start).
- An LLM provider key for the Agent (for example an OpenAI key).
- A publicly reachable Publicus URL — Meta must be able to POST to your webhook.
1. Collect the Meta credentials
Section titled “1. Collect the Meta credentials”From your app in the Meta dashboard, gather four values:
| Value | Where to find it |
|---|---|
| Phone number ID | WhatsApp → API Setup, under the “From” number. A numeric id, not the phone number itself. |
| Access token | WhatsApp → API Setup (temporary 24h token to test), or a permanent System User token for production. |
| App secret | App Settings → Basic → App Secret. Used to verify Meta’s X-Hub-Signature-256 on every POST. |
| Verify token | A random string you choose. You enter the same value in Meta’s webhook config and store it here. |
2. Store the secrets
Section titled “2. Store the secrets”Go to Secrets, a tab of Connections, and create opaque secrets for each:
| Secret | Holds |
|---|---|
whatsappAccessToken |
the Graph access token |
whatsappAppSecret |
the app secret |
whatsappVerifyToken |
the verify token you chose |
openaiApiKey |
your LLM provider key |
The tokens stay in the secret store and are never exposed in a flow or webhook.
3. Create the inbound webhook
Section titled “3. Create the inbound webhook”Publicus receives WhatsApp messages through a webhook that verifies Meta’s challenge and signature for you.
-
Go to Webhooks and create a webhook.
-
Set Channel handler to WhatsApp. This handler answers Meta’s
hub.verify_tokenchallenge (the GET request) and checks theX-Hub-Signature-256HMAC on every POST. -
Pick the two secrets from step 2 in the fields the handler adds:
whatsappVerifyTokenin Verify token secret andwhatsappAppSecretin App secret. To let the flow receive voice notes and files, also pickwhatsappAccessTokenin Access token.

-
Click Create. On the webhook’s page, Copy beside the address under its name copies your callback URL.


4. Register the webhook with Meta
Section titled “4. Register the webhook with Meta”In the Meta dashboard, open WhatsApp → Configuration:
- Set the Callback URL to the URL you copied, and the Verify token to the exact string you stored as
whatsappVerifyToken. - Click Verify and save. Meta sends a GET challenge; Publicus answers it and the webhook is confirmed.
- Under Webhook fields, subscribe to messages.
5. Build the flow
Section titled “5. Build the flow”Create the flow that answers each message. The webhook from step 3 already verified Meta’s signature at the edge, so the flow reads the message straight off the incoming payload. Meta nests the inbound message deep in the body, so use jsonpath() to pull the fields out:
| Field | Expression |
|---|---|
| message text | {{ jsonpath($start->payload, '$.entry[0].changes[0].value.messages[0].text.body') }} |
| sender (wa_id) | {{ jsonpath($start->payload, '$.entry[0].changes[0].value.messages[0].from') }} |
| business number | {{ jsonpath($start->payload, '$.entry[0].changes[0].value.metadata.phone_number_id') }} |
Wire Webhook trigger → Start → Agent → Channel/WhatsApp:
- Add a Webhook trigger node, pick the webhook from step 3 in its Webhook field, and connect its webhook handle to Start.
- On the Agent, set
promptto the message-text expression above and pick theopenaiapikeysecret incredential. Setattachmentsto{!! json_encode($start->attachments) !!}so the agent hears voice notes and sees files. A voice note has no text body, and its transcript is never put into the payload. This needs the Access token from step 3. When the workspace transcribes WhatsApp voice notes on arrival (AI models → Voice messages), the agent reads that transcript instead of transcribing the note again. - Connect a Chat Thread node to the Agent’s Memory handle, with
channel=whatsapp,conversationId= the business-number expression, anduserId= the sender expression. This gives the agent memory per WhatsApp conversation. - On the Channel/WhatsApp reply node, set:
credential= thewhatsappaccesstokensecret, picked from the credential listphoneNumberId= the business-number expressionto= the sender expressiontext={{ $prev->content }}
Sending outside the 24-hour window
Section titled “Sending outside the 24-hour window”If your flow initiates the conversation (a reminder or a notification, for example), free-form text is rejected. Send a pre-approved template instead by setting these fields on the Channel/WhatsApp node:
-
templateName= the name of a template approved in your WhatsApp Business account. When set, the node sends a template message andtextis ignored. -
languageCode= a locale the template was approved in, for exampleen_US. Required whenever a template name is set. -
templateComponents(optional) = a JSON array of WhatsApp component objects that fill the template’s variable placeholders, for example:[{"type": "body", "parameters": [{"type": "text", "text": "Anna"}]}]The value must be a valid JSON array. Anything else is ignored and the template sends without parameters.
Verify it works
Section titled “Verify it works”- Verification: Meta’s Verify and save succeeds (the GET challenge is answered).
- Run: messaging your number creates a completed run under Runs.
- Reply: the agent’s answer arrives in WhatsApp, within the 24-hour window.
- Memory: under Conversations, a thread exists for the conversation. Send a follow-up that refers to an earlier message and confirm the agent remembers.
Troubleshooting
Section titled “Troubleshooting”- Meta’s “Verify and save” fails: the verify token in Meta must match the
whatsappVerifyTokensecret exactly, and the webhook’sclassmust beApp\Webhooks\WhatsAppWebhookConfig. - Messages don’t trigger a run: confirm you subscribed to the messages webhook field and that the callback URL is publicly reachable.
- Messages are rejected before any run appears: the
whatsappAppSecretsecret must hold the app’s real App Secret — the webhook rejects POSTs whoseX-Hub-Signature-256does not match. Status callbacks (delivery/read receipts) carry no message and produce no run, which is expected. - No reply arrives: check the access token and phone number ID, and that you are replying inside the 24-hour window. Outside it, set
templateNameandlanguageCodeto send a pre-approved template instead (see Sending outside the 24-hour window).
Related
Section titled “Related”- Connect an agent to a chat channel — the channel overview.
- Connect a Telegram agent — the other webhook-based channel.
- Channel / WhatsApp · Secrets · Chat Threads.