@agent-wechat/agent-wechat 0.11.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,194 @@
1
+ # @agent-wechat/agent-wechat
2
+
3
+ OpenClaw channel plugin for WeChat. Connects your OpenClaw bot to WeChat using [agent-wechat](https://github.com/thisnick/agent-wechat).
4
+
5
+ **[Documentation](https://thisnick.github.io/agent-wechat/integrations/openclaw/setup/)**
6
+
7
+ ## Prerequisites
8
+
9
+ - **A WeChat account logged in on your phone** — This account will be used by the bot. You must keep it logged in on your phone at all times. If you log out on the phone, the bot loses its connection.
10
+
11
+ - **A second screen** — WeChat login requires scanning a QR code with your phone camera. You'll need the QR code displayed on a screen separate from the phone running WeChat (e.g., a computer monitor, tablet, or another phone).
12
+
13
+ - **An agent-wechat server** — Either self-hosted via Docker or provided by someone else. You'll need the server URL and authentication token.
14
+
15
+ > **Note:** The agent-wechat container requires `SYS_PTRACE` and `seccomp=unconfined` (ptrace access to the WeChat desktop process). It cannot run in serverless or restricted container environments (AWS Fargate, Cloud Run, etc.) — use a VM or bare-metal Docker host.
16
+
17
+ ## Setup
18
+
19
+ ### 1. Start the agent-wechat Server
20
+
21
+ If you need to run the server yourself:
22
+
23
+ **Option A: CLI** (quickest for local use)
24
+
25
+ ```bash
26
+ npm install -g @agent-wechat/cli
27
+ wx up
28
+ ```
29
+
30
+ **Option B: Docker Compose** (production / networked)
31
+
32
+ ```yaml
33
+ services:
34
+ agent-wechat:
35
+ image: ghcr.io/thisnick/agent-wechat:latest
36
+ container_name: agent-wechat
37
+ security_opt:
38
+ - seccomp=unconfined
39
+ cap_add:
40
+ - SYS_PTRACE
41
+ ports:
42
+ - "6174:6174"
43
+ volumes:
44
+ - agent-wechat-data:/data
45
+ - agent-wechat-home:/home/wechat
46
+ - ~/.config/agent-wechat/token:/data/auth-token:ro
47
+ restart: unless-stopped
48
+
49
+ volumes:
50
+ agent-wechat-data:
51
+ agent-wechat-home:
52
+ ```
53
+
54
+ Generate a token before starting:
55
+
56
+ ```bash
57
+ mkdir -p ~/.config/agent-wechat
58
+ openssl rand -hex 32 > ~/.config/agent-wechat/token
59
+ chmod 600 ~/.config/agent-wechat/token
60
+ docker compose up -d
61
+ ```
62
+
63
+ If running alongside OpenClaw on the same Docker network, set `serverUrl` to `http://agent-wechat:6174` in the channel config.
64
+
65
+ ### 2. Install the extension
66
+
67
+ ```bash
68
+ openclaw plugins install @agent-wechat/agent-wechat
69
+ ```
70
+
71
+ ### 3. Configure the channel
72
+
73
+ ```bash
74
+ # Uses defaults (localhost:6174, token from ~/.config/agent-wechat/token)
75
+ openclaw channels add --channel agent-wechat
76
+
77
+ # Override server URL and token
78
+ openclaw channels add --channel agent-wechat --url <url> --token <token>
79
+ ```
80
+
81
+ Or edit `~/.openclaw/openclaw.json` directly:
82
+
83
+ ```json
84
+ {
85
+ "channels": {
86
+ "agent-wechat": {
87
+ "enabled": true,
88
+ "serverUrl": "http://localhost:6174",
89
+ "dmPolicy": "open",
90
+ "groupPolicy": "open"
91
+ }
92
+ }
93
+ }
94
+ ```
95
+
96
+ > **Upgrading from ≤0.11.x?** The channel id changed from `wechat` to `agent-wechat` (OpenClaw's official plugin registry now reserves `wechat`/`weixin` as aliases of Tencent's `openclaw-weixin` plugin, which hijacked this channel's id). Rename the `channels.wechat` key to `channels.agent-wechat` and any `plugins.entries.wechat` key to `plugins.entries.agent-wechat` in `openclaw.json`, then restart the gateway. Allowlist entries and group settings carry over unchanged.
97
+
98
+ For local setups, the token is automatically read from `~/.config/agent-wechat/token` (shared with the CLI and container), so you don't need to set it in the config. When connecting to a remote server, add the `token` field.
99
+
100
+ ### 4. Restart the gateway
101
+
102
+ Restart your OpenClaw gateway so it picks up the new channel config:
103
+
104
+ ```bash
105
+ openclaw gateway restart
106
+ ```
107
+
108
+ ### 5. Log in to WeChat
109
+
110
+ Ask your bot to log in to WeChat:
111
+
112
+ > "Log in to WeChat"
113
+
114
+ Your bot should generate a QR code image. Alternatively, use the CLI:
115
+
116
+ ```bash
117
+ openclaw channels login --channel agent-wechat
118
+ ```
119
+
120
+ ### 6. Scan the QR code
121
+
122
+ Display the QR code on a screen separate from the phone running WeChat. WeChat's login QR scanner uses the camera only — it cannot scan from the phone's photo gallery.
123
+
124
+ Scan the QR code using WeChat's built-in scanner (tap **+** > **Scan**) with the account you want the bot to use. Then tap **Login** on the confirmation screen.
125
+
126
+ You only need to do this once — the session persists across container restarts.
127
+
128
+ ### 7. Configure DM and group policies
129
+
130
+ Once connected, configure how the bot handles direct messages and group chats. You can ask your bot to help you, or edit the config directly. See the Configuration Reference below.
131
+
132
+ ## Limitations
133
+
134
+ - **The WeChat account must stay logged in on your phone.** Logging out on the phone disconnects the bot. One workaround: after the bot is logged in, you can uninstall and reinstall WeChat on your phone — the bot session persists. On Android, you can also run WeChat in a separate profile (Work Profile or Private Space) to keep the bot account isolated.
135
+
136
+ - **Only one desktop session.** Once the bot is logged in as a "desktop" client, you cannot simultaneously use WeChat on another computer or WeChat Web.
137
+
138
+ - **Infrastructure updates disconnect the bot.** If the agent-wechat server restarts or updates, the bot will be disconnected. When this happens, ask your bot to log in again. If the disconnection was brief, you may not need a new QR code scan.
139
+
140
+ ## Configuration Reference
141
+
142
+ All config lives under `channels.agent-wechat` in OpenClaw's config file:
143
+
144
+ | Key | Type | Default | Description |
145
+ |-----|------|---------|-------------|
146
+ | `enabled` | boolean | `false` | Enable the WeChat channel |
147
+ | `serverUrl` | string | — | agent-wechat REST API URL |
148
+ | `token` | string | — | Auth token (auto-read from `~/.config/agent-wechat/token` for local setups) |
149
+ | `dmPolicy` | `"open" \| "allowlist" \| "disabled"` | `"disabled"` | Who can DM the bot |
150
+ | `allowFrom` | string[] | `[]` | wxid allowlist for DMs (when policy is `allowlist`) |
151
+ | `groupPolicy` | `"open" \| "allowlist" \| "disabled"` | `"disabled"` | Group message policy |
152
+ | `groupAllowFrom` | string[] | `[]` | Global allowlist of group sender IDs (`wxid_...`) |
153
+ | `groups` | object | `{}` | Per-group overrides (e.g. `{ "id@chatroom": { "requireMention": false, "enabled": true, "groupPolicy": "allowlist", "allowFrom": ["wxid_..."] } }`) |
154
+ | `pollIntervalMs` | integer | `1000` | Message polling interval |
155
+ | `authPollIntervalMs` | integer | `30000` | Auth status check interval |
156
+
157
+ ## Development
158
+
159
+ ### Build from source
160
+
161
+ ```bash
162
+ git clone https://github.com/thisnick/agent-wechat.git
163
+ cd agent-wechat
164
+ pnpm install && pnpm build
165
+ ```
166
+
167
+ ### Link for local development
168
+
169
+ ```bash
170
+ openclaw plugins install -l ./packages/openclaw-extension
171
+ ```
172
+
173
+ This symlinks the extension so changes are picked up without reinstalling. Rebuild with `pnpm build` after making changes, then restart the gateway.
174
+
175
+ ## Architecture
176
+
177
+ ```
178
+ OpenClaw Gateway
179
+ └── WeChat Monitor (polling loop)
180
+ │
181
+ │ GET /api/chats (list chats with unreads)
182
+ │ POST /api/chats/{id}/open (open chat, clear unreads)
183
+ │ GET /api/messages/{id} (fetch new messages)
184
+ │ GET /api/messages/{id}/media/{localId} (download media)
185
+ │ POST /api/messages/send (send reply)
186
+ │
187
+ ▼
188
+ agent-wechat container (port 6174)
189
+ │
190
+ ▼
191
+ WeChat Desktop (in Xvfb)
192
+ ```
193
+
194
+ The monitor polls for chats with unread messages, fetches new messages, resolves routing/session via OpenClaw's runtime, and dispatches replies back through the agent-wechat API.