Files
nanobot/docs/guides/wechat-ai-agent.md
T

104 lines
2.4 KiB
Markdown
Raw Normal View History

2026-07-08 15:23:34 +08:00
# Build a WeChat AI Agent with nanobot
This guide connects nanobot to WeChat through the `weixin` channel. The channel
uses HTTP long polling with QR-code login through the supported upstream API.
## What this guide builds
- the `weixin` channel enabled in nanobot
- a QR-code login session
2026-07-08 15:58:43 +08:00
- one pairing-approved WeChat sender
2026-07-08 15:23:34 +08:00
- a running gateway for message delivery
## Prerequisites
- A working local nanobot reply:
```bash
nanobot agent -m "Hello!"
```
- A WeChat account that can complete QR-code login.
## Install nanobot
```bash
python -m pip install nanobot-ai
nanobot onboard --wizard
```
## Enable the WeChat channel
Install the optional channel dependency:
```bash
nanobot plugins enable weixin
```
Merge this snippet into `~/.nanobot/config.json`:
```json
{
"channels": {
"weixin": {
2026-07-08 15:58:43 +08:00
"enabled": true
2026-07-08 15:23:34 +08:00
}
}
}
```
2026-07-08 15:58:43 +08:00
Omitting `allowFrom` enables pairing-only mode. The first private WeChat message
from a new sender gets a pairing code instead of agent access.
2026-07-08 15:23:34 +08:00
Log in:
```bash
nanobot channels login weixin
```
Use `--force` if you need to discard saved login state and authenticate again.
## Run nanobot gateway
```bash
nanobot channels status
nanobot gateway
```
## Test a message
2026-07-08 15:58:43 +08:00
Send a private WeChat message to the bot. It should reply with a pairing code.
Approve it from a trusted local surface:
```bash
nanobot agent -m "/pairing approve ABCD-EFGH"
```
Send the message again after approval and watch gateway logs for the sender ID
and reply.
2026-07-08 15:23:34 +08:00
## Security notes
2026-07-08 15:58:43 +08:00
- Prefer pairing-only mode for first setup. Add `allowFrom` only when you want a
static allowlist.
2026-07-08 15:23:34 +08:00
- Treat saved login state as sensitive account access.
- Avoid connecting personal accounts to untrusted workspaces or broad tool
permissions.
## Troubleshooting
- If login fails, rerun `nanobot channels login weixin --force`.
2026-07-08 15:58:43 +08:00
- If a first private message returns a pairing code, that is expected. Approve
the code before testing normal agent replies.
- If messages are denied without a pairing code, check gateway logs for whether
WeChat provided the context token required for nanobot to reply.
2026-07-08 15:23:34 +08:00
- If polling disconnects, restart the gateway and check network reachability to
the upstream service.
## Next: memory, automations, MCP tools
- [Chat Apps reference](../chat-apps.md)
- [AI Agent Memory](./ai-agent-memory.md)
- [Secure local AI agent](./secure-local-ai-agent.md)
- [Deployment](../deployment.md)