Connect an agent to a WhatsApp Business number through Meta's WhatsApp Cloud API
Connect an agent to a WhatsApp Business phone number. People message the number on WhatsApp and the agent answers in the same chat. Each phone number gets its own conversation, and the sender's phone number is used as their verified identity for long-term memory.
You need:
- An agent in the AgentBlit console.
- A Facebook account that can create apps at developers.facebook.com.
- A Meta business portfolio. The WhatsApp account and phone number belong to it.
Each WhatsApp phone number can be connected to one agent. Connecting the same number a second time fails with This WhatsApp number is already connected to an agent.
Values at a glance
| Field in AgentBlit | Where it comes from | Looks like |
|---|---|---|
| Access token | Meta app → WhatsApp → API Setup → Generate token, or a System User token (see Permanent access token) | Long string starting with EAA |
| Phone number ID | Meta app → WhatsApp → API Setup, under the phone number | 15–16 digits, for example 1428344203693540 |
| App secret | Meta app → App settings → Basic → App secret → Show | 32 hex characters |
| Verify token | You make it up. Any random string, entered again in Meta | For example the output of openssl rand -hex 16 |
All four are different values. The Phone number ID is not the phone number itself.
| Meta setting | Value |
|---|---|
| Webhook → Callback URL | Webhook URL from the channel card (below) |
| Webhook → Verify token | The same verify token you entered in AgentBlit |
| Webhook fields | messages subscribed |
| WhatsApp account | Subscribed to the app (step 7) |
The webhook URL always starts with:
https://console.agentblit.com/api/webhooks/channels/whatsapp/It ends with the channel id, which AgentBlit creates when you connect the channel. Copy the full URL from the channel card in step 5. Do not type it by hand.
Set up
1. Create a Meta app with the WhatsApp use case
- Open developers.facebook.com/apps and click Create App.
- Enter an App name and contact email, then click Next. Meta rejects names that contain
WhatsApp,FB,Instaand similar terms. - Under Use cases, select Connect with customers through WhatsApp and click Next.
- Pick the business portfolio that should own the WhatsApp account and click Next.
- Review the summary and click Create app. Meta may ask for your Facebook password.
One Meta app has a single webhook callback URL. Use a separate Meta app for each WhatsApp channel you connect.
2. Get a phone number and its Phone number ID
In the app, open Use cases → Customize on the WhatsApp use case → API Setup (shown as Step 1. Try it out in newer dashboards).
- To start, Meta gives you a free test number. Its Phone Number ID and WhatsApp Business Account ID are shown under the number. Copy the Phone Number ID.
- A test number can only message up to 5 recipient numbers. Add your own WhatsApp number under To → Manage phone number list and enter the code WhatsApp sends you.
- To use your own number instead, add it under Production setup (Step 2). Its Phone number ID appears there once it is registered.
3. Copy the access token and app secret
| Credential | Where in Meta |
|---|---|
| Access token | API Setup → Access token → Generate token. In the Facebook popup, select the WhatsApp account and allow access. Copy the token that appears. |
| App secret | Left sidebar → App settings → Basic → App secret → Show. Meta asks for your Facebook password. |
The token from Generate token expires after about 24 hours. It is fine for a first test. Before real use, replace it with a permanent token from a System User. See Permanent access token.
Then make up a verify token. It only has to match in AgentBlit and Meta. For example, in a terminal:
openssl rand -hex 164. Connect the channel in AgentBlit
- Open the agent in console.agentblit.com.
- In the agent editor, open Channels and click Connect channel.
- Set Provider to WhatsApp. It defaults to Telegram.
- Fill in Access token, Phone number ID, App secret and Verify token with the four values from steps 2–3.
- Pick Access. See Access.
- Click Connect.
AgentBlit checks the token and phone number ID with Meta. A wrong pair fails with WhatsApp auth failed: …. The channel is named after the number's verified business name, or the phone number.
5. Copy the webhook URL from the channel card
The new card shows WhatsApp · followed by the channel name. Under it is the webhook URL, starting with https://console.agentblit.com/api/webhooks/channels/whatsapp/. Copy the whole URL.
6. Set the webhook in Meta
- In the Meta app, open the WhatsApp use case → Configuration (shown as Step 2. Production setup → Configure Webhooks in newer dashboards).
- Paste the webhook URL into Callback URL.
- Enter the same verify token you entered in AgentBlit into Verify token.
- Click Verify and save. Meta calls the URL, and AgentBlit answers only if the verify token matches.
- Under Webhook fields, find
messagesand switch it to Subscribed.
To test the connection, click Test next to messages and then Send to server. A contact named test user name appears under Contacts on the channel card. Block it afterwards.
7. Subscribe the WhatsApp account to the app
Meta only forwards real messages to your webhook after the WhatsApp Business Account is subscribed to the app. Without this, messages show up in Meta's dashboard but never reach AgentBlit, and the agent never replies.
Run this once, with your access token and the WhatsApp Business Account ID from API Setup:
curl -X POST "https://graph.facebook.com/v25.0/<WHATSAPP_BUSINESS_ACCOUNT_ID>/subscribed_apps" \
-H "Authorization: Bearer <ACCESS_TOKEN>"The response is {"success":true}. To check it, send the same URL with GET instead of POST: your app should be listed.
8. Send a message
From a WhatsApp number on the recipient list, send a message to the business number, for example hi. The agent marks the message as read, shows typing…, and replies when it has finished.
Permanent access token
The token from Generate token expires after about 24 hours. When it expires, the agent stops replying and Meta rejects every send. Use a System User token instead, which does not expire.
- Open business.facebook.com → Settings → Users → System users for the business portfolio that owns the app.
- Click Add, give the system user a name and the Admin role, and create it.
- Click Assign assets:
- Apps → your Meta app → Full control (manage app).
- WhatsApp accounts → your WhatsApp account → Full control.
- Click Generate token, select your app, set Token expiration to Never, and select the permissions
whatsapp_business_messagingandwhatsapp_business_management. - Copy the token. Meta shows it only once.
- In AgentBlit, click the pencil on the channel card, paste the token into Access token, and save.
Access
Choose Access when you connect. Change it later in the dropdown on the channel card or with the pencil button.
| Mode | What happens |
|---|---|
| Open to anyone | Anyone who messages the number can use the agent right away. |
| Require approval | A new person's first message gets Your access request is pending approval from the agent owner. The agent does not answer until you approve them. They must send their message again after approval. |
People who message the number act through the agent's connected accounts and tools. Use Require approval unless the number is private to people you trust.
Contacts on the channel card lists everyone who has messaged the number, with their WhatsApp name, phone number (digits only, with country code) and status (active, pending, blocked).
- Approve lets a pending or blocked person use the agent.
- Block stops the agent from answering that person, without telling them.
Changing the access mode applies to people who message the number for the first time afterwards. Existing contacts keep their status.
What people see in WhatsApp
Replies
- When a message arrives, the agent marks it as read and shows typing… until the reply is sent. For long runs the typing indicator is refreshed so it stays visible.
- WhatsApp can't edit a sent message, so the reply is sent once, when the run finishes. It doesn't stream like Slack.
- An answer longer than 4,096 characters continues in further messages.
- Each phone number is one conversation. Send
/newto start over.
Formatting
The agent's Markdown is converted to WhatsApp formatting: *bold*, _italic_, ~strikethrough~, inline code and code blocks. Headings become bold lines, links become text (url), and - bullets and 1. numbered lists are kept. WhatsApp has no tables, so tables are shown as aligned text in a code block.
Approvals
When the agent calls a tool that needs approval, the run pauses and the agent sends a message like:
Approval needed: <what the tool is about to do>
<detail>: <value>
Reply "approve" or "deny".- Reply
approveoryesto continue, ordenyornoto cancel. - Only the person who sent the original message can decide.
- Sending anything else instead skips the approval (
Skipped: a new message arrived.) and the agent handles the new message.
Tools that ask for input through a form cannot show the form in WhatsApp. That request is cancelled and the tool continues without it.
What isn't supported
- Text messages only. Images, voice notes, documents, stickers and locations are ignored.
- Diagrams stay as Mermaid code. WhatsApp replies don't include rendered images.
- The agent only replies. It can't start a conversation. Meta allows free-form replies only within 24 hours of the person's last message.
Commands
Send these as a message in the chat.
| Command | What it does |
|---|---|
/new | Clears this conversation's history and starts fresh (Started a new conversation.). Skips a pending approval. |
/reset | Same as /new. |
/stop | Skips a pending approval in this conversation. |
/claim 12345678 | Links this WhatsApp number to your memory from another chat, using the 8-digit code the agent gave you there. Codes expire after 10 minutes. Needs long-term memory on for the workspace. |
Published version
WhatsApp conversations run the agent's published version, not the draft you are editing. After you change the prompt, tools or model, click Publish before testing in WhatsApp.
- An agent that has never been published runs its draft.
- With a rollout percentage set, that share of conversations runs the draft.
Going live
The test number and an unpublished app are enough to try the agent with up to five numbers. Before real customers use it:
- Add and register your own business phone number under Production setup, and connect a channel with its Phone number ID.
- Use a permanent access token.
- Complete Business verification for the business portfolio.
- Publish the Meta app (switch it to Live). Meta asks for a privacy policy URL and an app category under App settings → Basic.
- Switch the channel's Access to what you want for real customers.
Edit or remove a channel
Each channel card has:
- Switch — turns the channel off and on. While it is off, the agent does not answer and Meta's requests to the webhook URL fail.
- Pencil — opens Edit WhatsApp channel: Name, Access token, App secret, Verify token and Access. Leave a credential blank to keep the current one.
- Trash — removes the channel.
When you change credentials:
- Access token: AgentBlit checks the new token against the channel's phone number ID before saving.
- App secret: if you reset it in Meta, save the new one in AgentBlit right away. Until you do, Meta's requests fail signature checks and nothing reaches the agent.
- Verify token: after changing it in AgentBlit, enter the same value in Meta's webhook settings and click Verify and save again.
Removing a channel and connecting again creates a new channel id, so the webhook URL changes. Paste the new URL into Meta's Callback URL and click Verify and save.
Troubleshooting
| Symptom | Fix |
|---|---|
WhatsApp auth failed: … when connecting | The access token and Phone number ID don't belong together, or the token expired. Copy both again from API Setup. The Phone number ID is not the phone number. |
| Verify and save fails in Meta | The callback URL is incomplete or from an old channel, the channel is switched off, or the verify token in Meta doesn't match the one in AgentBlit. |
| Meta's Test reaches AgentBlit, but real messages get no reply and no contact appears | The WhatsApp account isn't subscribed to the app. Run the subscribed_apps call in step 7. Also check that messages is Subscribed under Webhook fields. |
| The agent stopped replying after about a day | The temporary access token expired. Switch to a permanent access token with the pencil button. |
Something went wrong. Please try again. | The run failed after the message arrived. Send the message again. If it keeps happening, check the console logs for [channels] run failed. |
Bold text shows extra asterisks, like *word* | The console is running a version from before WhatsApp formatting was added. Update to the latest release. |
| Sending to a test recipient fails | A test number can only reach numbers on its recipient list (up to 5). Add the number under API Setup → To → Manage phone number list. |
| New tools or prompt changes don't show up | The change is still a draft. Click Publish in the agent editor. |
Your access request is pending approval from the agent owner. | Access is Require approval. Approve the person in Contacts, or switch Access to Open to anyone. |
This WhatsApp number is already connected to an agent | A phone number can be connected to one agent. Remove the existing WhatsApp channel for that number first. |
| Meta rejects the app name | Names can't contain WhatsApp, FB, Insta and other Meta brand terms. Pick a name without them. |