feat(channels): add WhatsApp Agent Platform channel
Adds `whatsapp_agent`, an additive channel that connects nanobot to the official WhatsApp Agent Platform API (https://api.whatsapp.com/agent/v1). It authenticates with a per-agent API token and long-polls `GET /updates` instead of linking a device, so it is the officially supported interface rather than the Neonize linked-device protocol used by the existing `whatsapp` channel. The existing `whatsapp` channel is unchanged; both can run at once under different names. Design notes: - The poll cursor, dedup window, and creator identifier live in one atomically replaced state file. A message id is recorded before it is handled, so a crash re-reads the batch without answering twice, and the cursor is only accepted after the batch is processed. - The first poll omits `offset`, which resolves the head and never replays up to 30 days of history into an auto-replying agent. - A changed token resets the cursor, because `next_offset` is only valid for the agent that issued it. - Each API method is paced below its own rolling 60-second limit, and progress/tool-hint messages default to off because they spend the shared 12-per-minute send budget. - Retries are limited to confirmed non-delivery (`429`, `503`/`131016`). A `500` or read timeout is ambiguous, so it is not retried unless `retryAmbiguousSends` is set; a duplicate is worse than a missed reply. - Inbound media is downloaded through the shared SSRF guard, size-capped, and verified against the reported digest. Outbound media is validated before upload. - Reactions are receive-only, matching the API. The token is never logged or persisted; state stores only a SHA-256 fingerprint. Docs compare both WhatsApp channels, including the lack of end-to-end encryption, country availability, and rate limits.
This commit is contained in:
1 parent
74942bd190
commit
b7cb5da4b5
30 files changed
+3962
-1
No files matched your search
+44
-1
@@ -9,6 +9,7 @@ Connect nanobot to Telegram, Discord, Slack, WeChat, Email, Mattermost, Linear,
|
||||
| Slack | [Build a Slack AI Agent with nanobot](./guides/slack-ai-agent.md) |
|
||||
| Feishu | [Build a Feishu AI Agent with nanobot](./guides/feishu-ai-agent.md) |
|
||||
| WhatsApp | [Build a WhatsApp AI Agent with nanobot](./guides/whatsapp-ai-agent.md) |
|
||||
| WhatsApp Agent Platform | [Build an official WhatsApp agent with nanobot](./guides/whatsapp-agent-platform.md) |
|
||||
| WeChat | [Build a WeChat AI Agent with nanobot](./guides/wechat-ai-agent.md) |
|
||||
| QQ | [Build a QQ AI Agent with nanobot](./guides/qq-ai-agent.md) |
|
||||
| Email | [Build an Email AI Agent with nanobot](./guides/email-ai-agent.md) |
|
||||
@@ -50,7 +51,7 @@ The sections below explain what each chat platform requires and provide manual c
|
||||
> nanobot plugins enable <channel>
|
||||
> ```
|
||||
>
|
||||
> Replace `<channel>` with names such as `telegram`, `slack`, `feishu`, `dingtalk`, `matrix`, `qq`, `napcat`, `weixin`, `wecom`, or `msteams`. To turn a channel off later, run `nanobot plugins disable <channel>`. nanobot keeps the saved settings, but stops loading that channel after the next restart.
|
||||
> Replace `<channel>` with names such as `telegram`, `slack`, `feishu`, `dingtalk`, `matrix`, `qq`, `napcat`, `weixin`, `wecom`, `msteams`, or `whatsapp_agent`. To turn a channel off later, run `nanobot plugins disable <channel>`. nanobot keeps the saved settings, but stops loading that channel after the next restart.
|
||||
|
||||
## Manual Setup Pattern
|
||||
|
||||
@@ -89,6 +90,7 @@ If `nanobot channels status` does not show the channel as enabled, the config sn
|
||||
| **Telegram** | Bot token from @BotFather |
|
||||
| **Discord** | Bot token + Message Content intent |
|
||||
| **WhatsApp** | QR code scan (`nanobot channels login whatsapp`) |
|
||||
| **WhatsApp Agent Platform** | Agent API token from WhatsApp → Settings → Agents |
|
||||
| **WeChat (Weixin)** | QR code scan (`nanobot channels login weixin`) |
|
||||
| **Feishu** | QR code scan (`nanobot channels login feishu`) or App ID + App Secret |
|
||||
| **DingTalk** | App Key + App Secret |
|
||||
@@ -474,6 +476,47 @@ Modern WhatsApp can deliver a sender's LID instead of their phone number. nanobo
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><b>WhatsApp Agent Platform</b></summary>
|
||||
|
||||
Connects nanobot through the **official** WhatsApp Agent Platform API. The agent appears as its own chat in WhatsApp and can only talk to you, its creator. No QR pairing, no linked device, and no optional Python dependencies.
|
||||
|
||||
This is a different channel from `whatsapp`. See the [official WhatsApp agent guide](./guides/whatsapp-agent-platform.md) for the full comparison and walkthrough.
|
||||
|
||||
**1. Create the agent in WhatsApp**
|
||||
|
||||
Open WhatsApp → **Settings → Agents → Create an agent**, then copy the key from the agent's chat → **Chat info → API key**. This feature is available only in limited countries and might not be in your account yet.
|
||||
|
||||
**2. Configure**
|
||||
|
||||
```json
|
||||
{
|
||||
"channels": {
|
||||
"whatsapp_agent": {
|
||||
"enabled": true,
|
||||
"token": "${WA_AGENT_TOKEN}"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`allowFrom` is optional. The platform already restricts the chat to the agent's creator; leave `allowFrom` empty to require pairing approval instead of a static list.
|
||||
|
||||
**3. Run**
|
||||
|
||||
```bash
|
||||
nanobot gateway
|
||||
```
|
||||
|
||||
**Notes**
|
||||
|
||||
- At most one gateway may poll a given agent token. A second one causes `409` and is logged as a duplicate-poller error.
|
||||
- Agent conversations are not end-to-end encrypted: Meta processes them on the agent's behalf. Your other chats are unaffected.
|
||||
- Replies are split at 4096 characters. Progress and tool-hint messages are off by default because every send spends the same 12-per-minute budget.
|
||||
- Ambiguous send outcomes (HTTP `500`, read timeouts) are not retried by default, because a duplicate is worse than a miss. Set `retryAmbiguousSends: true` to opt in.
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><b>Feishu</b></summary>
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ Use **Channels** in the WebUI for guided setup. These guides explain the account
|
||||
| Connect Slack | [Slack AI agent](./slack-ai-agent.md) |
|
||||
| Connect Feishu | [Feishu AI agent](./feishu-ai-agent.md) |
|
||||
| Connect WhatsApp | [WhatsApp AI agent](./whatsapp-ai-agent.md) |
|
||||
| Connect an official WhatsApp agent | [Official WhatsApp agent](./whatsapp-agent-platform.md) |
|
||||
| Connect WeChat | [WeChat AI agent](./wechat-ai-agent.md) |
|
||||
| Connect QQ | [QQ AI agent](./qq-ai-agent.md) |
|
||||
| Connect Email | [Email AI agent](./email-ai-agent.md) |
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
# Build an official WhatsApp agent with nanobot
|
||||
|
||||
This guide connects nanobot to WhatsApp through the `whatsapp_agent` channel, which uses the **official WhatsApp Agent Platform** API. The agent appears as its own chat inside WhatsApp and talks only to you.
|
||||
|
||||
This is a different product from the [`whatsapp`](./whatsapp-ai-agent.md) channel.
|
||||
|
||||
## Which WhatsApp channel should I use?
|
||||
|
||||
| | `whatsapp_agent` (this guide) | `whatsapp` |
|
||||
|---|---|---|
|
||||
| How it connects | An official agent API token | A linked WhatsApp device (QR) |
|
||||
| API | `https://api.whatsapp.com/agent/v1` | Neonize device session |
|
||||
| Who it can talk to | Only you, the agent's creator | Chats and groups the linked device can see |
|
||||
| Groups | Not supported | Supported |
|
||||
| Message transport | Long-polling `GET /updates` | Device connection |
|
||||
| End-to-end encryption | **No** — Meta manages agent chats | Yes, like a linked device |
|
||||
| Availability | Limited countries, per account | Wherever WhatsApp can link a device |
|
||||
| Account risk | Officially supported interface | Uses an unofficial linked-device protocol |
|
||||
|
||||
Choose `whatsapp_agent` when you want an official, sandboxed personal assistant that WhatsApp itself provides, and you do not need group access. Keep `whatsapp` when you need groups, media breadth, or availability in a country where the Agent Platform has not rolled out.
|
||||
|
||||
Both channels can be enabled at once with different names and different access rules.
|
||||
|
||||
## What this guide builds
|
||||
|
||||
- the `whatsapp_agent` channel enabled in `config.json`
|
||||
- a WhatsApp agent created from WhatsApp Settings
|
||||
- the agent's API token stored in nanobot
|
||||
- one approved sender
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- A working local nanobot reply:
|
||||
|
||||
```bash
|
||||
nanobot agent -m "Hello!"
|
||||
```
|
||||
|
||||
- A WhatsApp account with **Settings → Agents** available. This experience is available only in limited countries and might not appear in your account yet.
|
||||
- A machine that can keep `nanobot gateway` running. Outbound connections are enough; no inbound webhook or public URL is required.
|
||||
|
||||
## Step 1: Create the agent in WhatsApp
|
||||
|
||||
1. Open WhatsApp and go to **Settings → Agents → Create an agent**.
|
||||
2. Set a display name and avatar.
|
||||
3. Open the agent's chat, then **Chat info → API key**.
|
||||
4. Copy the key. This is the agent's API token.
|
||||
|
||||
You can connect up to five agents to one WhatsApp account. The token is shown again only if you regenerate it, and rotating it invalidates the previous value immediately. If you uninstall WhatsApp, regenerate the token.
|
||||
|
||||
## Step 2: Enable the channel
|
||||
|
||||
The channel uses only nanobot core dependencies, so no optional install is required:
|
||||
|
||||
```bash
|
||||
nanobot plugins enable whatsapp_agent
|
||||
```
|
||||
|
||||
Or edit `~/.nanobot/config.json` directly:
|
||||
|
||||
```json
|
||||
{
|
||||
"channels": {
|
||||
"whatsapp_agent": {
|
||||
"enabled": true,
|
||||
"token": "<AGENT_API_TOKEN>"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Keep the token in an environment variable instead of the file when you can, and reference it:
|
||||
|
||||
```json
|
||||
{
|
||||
"channels": {
|
||||
"whatsapp_agent": {
|
||||
"enabled": true,
|
||||
"token": "${WA_AGENT_TOKEN}"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Step 3: Run and test
|
||||
|
||||
```bash
|
||||
nanobot gateway
|
||||
```
|
||||
|
||||
Open the agent's chat in WhatsApp and send a message. The agent replies in the same chat using the same model, workspace, memory, and tools as the CLI and WebUI.
|
||||
|
||||
## Access control
|
||||
|
||||
The Agent Platform already restricts the conversation to you, the agent's creator. `allowFrom` is a second, local check and is optional.
|
||||
|
||||
When `allowFrom` is empty, an unapproved sender receives a pairing code. Approve it from a trusted local surface:
|
||||
|
||||
```bash
|
||||
nanobot agent -m "/pairing approve ABCD-EFGH"
|
||||
```
|
||||
|
||||
The sender identifier has the form `user:<id>`. Treat it as opaque, never share it, and prefer pairing over hardcoding it, because the identifier can change if you change your phone number or re-register your account. nanobot stores the most recent identifier and uses it for replies.
|
||||
|
||||
## Configuration reference
|
||||
|
||||
| Key | Default | Meaning |
|
||||
|---|---|---|
|
||||
| `enabled` | `false` | Load the channel at gateway start. |
|
||||
| `token` | — | The agent's API token. Required. |
|
||||
| `allowFrom` | `[]` | Extra local allowlist of `user:<id>` values, or `["*"]`. Empty means pairing-only. |
|
||||
| `stateDir` | `~/.nanobot/whatsapp-agent` | Where the durable poll cursor and dedup state are stored. |
|
||||
| `pollTimeout` | `25` | Long-poll hold time in seconds (0–25). |
|
||||
| `markRead` | `true` | Send read receipts for inbound messages. |
|
||||
| `typingIndicator` | `true` | Show "typing…" while the agent works. |
|
||||
| `downloadMedia` | `true` | Download inbound image, audio, video, document, and sticker media. |
|
||||
| `deleteMediaAfterDownload` | `false` | Delete the server copy once downloaded. |
|
||||
| `maxMediaMb` | `16` | Local cap on inbound and outbound media, in MB. |
|
||||
| `retryAmbiguousSends` | `false` | Retry sends whose outcome is unknown (HTTP 500, read timeouts). See "Delivery semantics". |
|
||||
| `sendProgress` | `false` | Send agent progress messages. Off because each one spends the send budget. |
|
||||
| `sendToolHints` | `false` | Send tool-call hints. Off for the same reason. |
|
||||
|
||||
## Media
|
||||
|
||||
Inbound media is downloaded, verified against the digest WhatsApp reports, then stored under the channel's media directory and passed to the agent like media from any other channel.
|
||||
|
||||
- Images: JPEG, PNG — 5 MB.
|
||||
- Stickers: WebP — 500 KB.
|
||||
- Video, audio, documents, generic files — 16 MB.
|
||||
- Voice notes are transcribed when a transcription provider is configured; the audio file stays attached.
|
||||
|
||||
Outbound media is uploaded first, then sent as the matching message type. Files over the limit for their type, or with an MIME type the platform does not accept, are skipped with an error in the log instead of failing the whole reply.
|
||||
|
||||
Note that audio the agent sends arrives as a normal file attachment, not as a WhatsApp voice-note bubble.
|
||||
|
||||
Reactions are receive-only on this platform: the API rejects sending them. nanobot reads an inbound reaction (including an empty emoji, which means the reaction was removed) but does not forward it as a turn, so a reaction never triggers a reply. Media on both sides expires 30 days after it is stored; nanobot holds downloaded files locally and can delete the server copy with `deleteMediaAfterDownload`.
|
||||
|
||||
## Delivery semantics
|
||||
|
||||
The platform's send result determines whether a retry is safe:
|
||||
|
||||
- **Rate limit or "not accepted for delivery"** (`429`, `503`): the message was not sent, so nanobot retries with backoff.
|
||||
- **A plain `500`, a dropped connection, or a read timeout**: WhatsApp cannot say whether the message was delivered. nanobot does **not** retry by default, because a duplicate is more disruptive than a missed reply. Set `retryAmbiguousSends` to `true` if you prefer a chance of duplicates over a chance of loss.
|
||||
|
||||
Replies longer than 4096 characters are split into multiple messages and sent in order. The first chunk quotes the message being answered.
|
||||
|
||||
At most one poller may run per agent token. If you start a second gateway against the same token, the older poll fails with `409`; nanobot logs this clearly and backs off. Run one gateway instance per agent.
|
||||
|
||||
## Operational notes
|
||||
|
||||
- **Rate limits.** WhatsApp allows 12 sends, 12 read receipts, 15 polls, and 12 media requests per minute per agent. nanobot paces each method below its own limit and counts retries against the same budget, which is why progress messages are off by default.
|
||||
- **Durable cursor.** The poll cursor is written to disk after each handled message, so a restart resumes exactly where it stopped and a replayed batch is deduplicated by message id.
|
||||
- **Retention.** WhatsApp keeps updates for 30 days. nanobot starts from the current head on first run, so it does not answer old history.
|
||||
- **Invalid token.** If WhatsApp rejects the token, the channel stops and logs an actionable message instead of retrying forever.
|
||||
- **Privacy.** Agent conversations are not end-to-end encrypted: Meta processes them on the agent's behalf. Your other WhatsApp chats are unaffected. Do not use this channel for data that requires end-to-end encryption.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
| Symptom | Cause | Fix |
|
||||
|---|---|---|
|
||||
| `Settings → Agents` is missing | The feature is not available in your country or account | Use the `whatsapp` channel instead |
|
||||
| "API token was rejected" | Token rotated, revoked, or mistyped | Regenerate it in the agent's chat info and update the config |
|
||||
| `409` in the logs | Two gateways share one agent token | Run a single gateway per agent |
|
||||
| Agent never replies | No inbound message has arrived yet, so no recipient is known | Send the agent a message first |
|
||||
| Media messages show a placeholder | Download failed, digest mismatch, or the file exceeded the limit | Check the log; re-send the file |
|
||||
| Replies arrive late | The turn is longer than the 25-second typing window | This is expected; the reply still arrives |
|
||||
|
||||
## Next steps
|
||||
|
||||
- [Chat Apps reference](../chat-apps.md)
|
||||
- [Pairing](../configuration.md#pairing)
|
||||
- [Official WhatsApp agent help](https://faq.whatsapp.com/1050934623978152)
|
||||
- [Secure local AI agent](./secure-local-ai-agent.md)
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
This guide connects nanobot to WhatsApp through the `whatsapp` channel. The channel links as a WhatsApp device and uses the same nanobot agent runtime, tools, memory, and workspace as the CLI and WebUI.
|
||||
|
||||
> [!NOTE]
|
||||
> WhatsApp also offers an official Agent Platform where the agent appears as its own chat and talks only to you. That is a separate channel with different tradeoffs — no group support, no end-to-end encryption, and limited country availability, but an officially supported interface that does not rely on a linked device. See [Build an official WhatsApp agent with nanobot](./whatsapp-agent-platform.md) to compare them.
|
||||
|
||||
## What this guide builds
|
||||
|
||||
- WhatsApp optional dependencies installed
|
||||
|
||||
Reference in new issue
Block a user