Skip to content
Docs

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.

  • 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.

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.

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.

Publicus receives WhatsApp messages through a webhook that verifies Meta’s challenge and signature for you.

  1. Go to Webhooks and create a webhook.

  2. Set Channel handler to WhatsApp. This handler answers Meta’s hub.verify_token challenge (the GET request) and checks the X-Hub-Signature-256 HMAC on every POST.

  3. Pick the two secrets from step 2 in the fields the handler adds: whatsappVerifyToken in Verify token secret and whatsappAppSecret in App secret. To let the flow receive voice notes and files, also pick whatsappAccessToken in Access token.

    The webhook form with Channel handler set to WhatsApp, which adds Verify token secret, App secret and Access token pickers
    The webhook form with Channel handler set to WhatsApp, which adds Verify token secret, App secret and Access token pickers
  4. Click Create. On the webhook’s page, Copy beside the address under its name copies your callback URL.

The webhook's address under its name at the top of its page, with Copy beside it
The webhook's address under its name at the top of its page, with Copy beside it

In the Meta dashboard, open WhatsApp → Configuration:

  1. Set the Callback URL to the URL you copied, and the Verify token to the exact string you stored as whatsappVerifyToken.
  2. Click Verify and save. Meta sends a GET challenge; Publicus answers it and the webhook is confirmed.
  3. Under Webhook fields, subscribe to messages.

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:

  1. Add a Webhook trigger node, pick the webhook from step 3 in its Webhook field, and connect its webhook handle to Start.
  2. On the Agent, set prompt to the message-text expression above and pick the openaiapikey secret in credential. Set attachments to {!! 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.
  3. Connect a Chat Thread node to the Agent’s Memory handle, with channel = whatsapp, conversationId = the business-number expression, and userId = the sender expression. This gives the agent memory per WhatsApp conversation.
  4. On the Channel/WhatsApp reply node, set:
    • credential = the whatsappaccesstoken secret, picked from the credential list
    • phoneNumberId = the business-number expression
    • to = the sender expression
    • text = {{ $prev->content }}

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 and text is ignored.

  • languageCode = a locale the template was approved in, for example en_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.

  • 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.
  • Meta’s “Verify and save” fails: the verify token in Meta must match the whatsappVerifyToken secret exactly, and the webhook’s class must be App\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 whatsappAppSecret secret must hold the app’s real App Secret — the webhook rejects POSTs whose X-Hub-Signature-256 does 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 templateName and languageCode to send a pre-approved template instead (see Sending outside the 24-hour window).