Skip to content

Architecture

Layers

Wechaty Bot / plugins
↓
PuppetAgentWechat → Bridge → Client (HTTP + SSE)
↓
agent-wechat (wx serve)
  1. Puppet — implements wechaty-puppet methods (messageSendText, contactList, …) and emits Wechaty events.
  2. Bridge — translates Wechaty-shaped calls into the agent-wechat HTTP API and normalizes inbound events.
  3. 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:

  1. Opens GET /v1/accounts/{account}/events/stream?newest=true
  2. Handles message.committed (and message.recalled)
  3. Loads the message with GET /v1/accounts/{account}/messages/{id}
  4. Emits a Wechaty message event
  5. 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