Architecture
Layers
Wechaty Bot / plugins ↓PuppetAgentWechat → Bridge → Client (HTTP + SSE) ↓ agent-wechat (wx serve)- Puppet — implements
wechaty-puppetmethods (messageSendText,contactList, …) and emits Wechaty events. - Bridge — translates Wechaty-shaped calls into the agent-wechat HTTP API and normalizes inbound events.
- Client — HTTP requests for reads/sends, and an SSE watcher for live events.
Inbound messages
agent-wechat exposes a native SSE stream. After login the Bridge:
- Opens
GET /v1/accounts/{account}/events/stream?newest=true - Handles
message.committed(andmessage.recalled) - Loads the message with
GET /v1/accounts/{account}/messages/{id} - Emits a Wechaty
messageevent - Acknowledges progress with
POST /v1/accounts/{account}/consumers/{name}/ack
Outbound messages
Puppet send methods call Bridge helpers. Sends that need at-most-once semantics use an Idempotency-Key per attempt. If the outcome is uncertain, the Bridge reports the key instead of silently retrying with a new one.
Source layout
| Path | Role |
|---|---|
src/puppet/puppet-bridge-agent-wechat.ts |
Wechaty Puppet |
src/agents/agent-wechat/ |
Bridge + HTTP/SSE client |
examples/ripe-wechaty-agent-wechat.ts |
Sample Wechaty bot |
examples/raw-bridge-agent-wechat.ts |
Bridge-only smoke example |