Connect the daemon
agent-wechat runs a native WeChat daemon (wx serve). puppet-bridge talks to its public HTTP API v1 and the event stream — it does not embed QR login.
What you need
wx servelistening (defaulthttp://127.0.0.1:6174)- An account already connected / logged in on the daemon
- A bearer token with scopes
read+send(+mediafor attachments; +adminfor group edits and friendship mutations)
wx servewx tokens create puppet-bridge \ --accounts <ACCOUNT_ID> \ --scopes read --scopes send --scopes mediaEnvironment
| Variable | Required | Default |
|---|---|---|
AGENT_WECHAT_URL |
no | http://127.0.0.1:6174 |
AGENT_WECHAT_TOKEN |
yes | — |
AGENT_WECHAT_ACCOUNT |
yes | daemon account id |
How to get these values
Start from a machine where the agent-wechat CLI (wx) can talk to your daemon.
1. AGENT_WECHAT_URL
Default local listener:
http://127.0.0.1:6174Confirm the daemon is up:
wx status --json# orcurl -sS http://127.0.0.1:6174/v1/statusIf you changed the listen address (or use HTTPS / a reverse proxy / tunnel), put that origin in AGENT_WECHAT_URL — without the /v1 suffix. Example: https://wechat.example.com.
2. AGENT_WECHAT_ACCOUNT
List accounts on the daemon and copy the id of an online account:
wx accounts list --jsonExample shape:
{ "items": [ { "id": "account-14675489135295484865", "alias": "account-1", "connection": "online", "ownUsername": "wxid_..." } ]}Use that id as AGENT_WECHAT_ACCOUNT. Prefer a row with connection: "online" (or authenticated: true). If none exist yet, create and log in first (wx accounts create, wx auth login) — see the agent-wechat setup docs.
3. AGENT_WECHAT_TOKEN
Option A — scoped token (recommended for puppet-bridge)
Create a token limited to this account and the scopes you need. The secret is printed once in the token field:
wx tokens create puppet-bridge \ --accounts <ACCOUNT_ID> \ --scopes read \ --scopes send \ --scopes media \ --jsonAdd --scopes admin if you need group edits or friendship add/accept. Add --scopes read-state if you will mark chats read.
Option B — owner token on the same machine
On first start the daemon writes an owner token to <dataDir>/api-token. Find dataDir with wx status --json (common defaults: ~/.local/share/agent-wechat, or a desktop Application Support hub).
# replace with dataDir from wx status --json if differentexport AGENT_WECHAT_TOKEN="$(cat ~/.local/share/agent-wechat/api-token)"Prefer Option A for bots: narrower scopes, easier to revoke (wx tokens revoke).
Put it together
export AGENT_WECHAT_URL=http://127.0.0.1:6174export AGENT_WECHAT_ACCOUNT=<id from wx accounts list>export AGENT_WECHAT_TOKEN=<token from wx tokens create>
# optional: write a local .env for the sample botscat > .env <<EOFAGENT_WECHAT_URL=$AGENT_WECHAT_URLAGENT_WECHAT_ACCOUNT=$AGENT_WECHAT_ACCOUNTAGENT_WECHAT_TOKEN=$AGENT_WECHAT_TOKENEOFGood to know
API tokens and WeChat logins are separate. Revoking a token does not log out of WeChat, and logging out does not revoke tokens. Keep tokens out of git and URLs.
Run the sample
export AGENT_WECHAT_URL=http://127.0.0.1:6174export AGENT_WECHAT_TOKEN=<token>export AGENT_WECHAT_ACCOUNT=<ACCOUNT_ID>npm run start:ripe:agent-wechat:infoOr construct the puppet yourself:
import { WechatyBuilder } from 'wechaty'import { PuppetAgentWechat } from 'wechaty-puppet-bridge'
const puppet = new PuppetAgentWechat({ baseUrl: process.env.AGENT_WECHAT_URL || 'http://127.0.0.1:6174', token: process.env.AGENT_WECHAT_TOKEN!, account: process.env.AGENT_WECHAT_ACCOUNT!,})const bot = WechatyBuilder.build({ puppet })await bot.start()How inbound messages work
- Checks daemon status (
stateisreadywhile serving) - Confirms the account
connectionisonline(callsPOST /connectif needed) - Opens
GET /v1/accounts/{account}/events/stream?newest=true - On
message.committed, loads the message over REST and emits Wechatymessage - Acknowledges the cursor with
POST /consumers/{name}/ack
Supported vs not
Supported: text (with group @), image / file / video / voice send and download, URL cards, recall, contact and room lists, room create / add / del / quit / rename, contact remark and avatar, room announcement get/clear, friendship search / add / accept, conversation read-mark.
Not supported here: QR login inside puppet-bridge, mini-program / location / contact-card send, setting a non-empty room announcement, tags, changing self name / signature.
Bridge-only helpers (mute, pin, room my-name) exist on the Bridge but have no matching Wechaty Puppet API.
Options
See Options for the full constructor fields.