openclaw-weixin 2.4.6 → 3.0.0

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 CHANGED
@@ -1,371 +1,102 @@
1
1
  # openclaw-weixin
2
2
 
3
- [简体中文](./README.zh_CN.md)
3
+ [English](./README_EN.md)
4
4
 
5
- Community-maintained distribution of
6
- [Tencent/openclaw-weixin](https://github.com/Tencent/openclaw-weixin), providing
7
- OpenClaw's WeChat channel with QR-code login.
5
+ 这是 [Tencent/openclaw-weixin](https://github.com/Tencent/openclaw-weixin)
6
+ 的社区维护发行版,用于连接 OpenClaw 与微信,并提供更好的使用体验。
8
7
 
9
- > The community npm package, plugin id, and channel id are all
10
- > `openclaw-weixin`. Existing
11
- > `channels.openclaw-weixin`, `plugins.entries.openclaw-weixin`, and
12
- > `~/.openclaw/openclaw-weixin/` data continue to use that id.
8
+ ## 安装或替换
13
9
 
14
- ## Compatibility
10
+ 需要 [OpenClaw](https://docs.openclaw.ai/install) `>=2026.7.1`。请使用运行
11
+ OpenClaw 的同一用户,并在同一环境中执行。
15
12
 
16
- | Requirement | Minimum |
17
- |-------------|---------|
18
- | OpenClaw | `2026.7.1` |
19
- | Node.js | `>=22.22.3 <23`, `>=24.15.0 <25`, or `>=25.9.0` |
20
-
21
- The plugin checks the OpenClaw host version at startup and refuses to load on
22
- older hosts. Node.js 24.15.0 is the recommended runtime.
23
-
24
- ## Prerequisites
25
-
26
- [OpenClaw](https://docs.openclaw.ai/install) must be installed and the
27
- `openclaw` CLI must be available.
28
-
29
- Check your version: `openclaw --version`
30
-
31
- ## Install
32
-
33
- ```bash
34
- openclaw plugins install npm:openclaw-weixin
35
- openclaw config set plugins.entries.openclaw-weixin.enabled true
36
- openclaw channels login --channel openclaw-weixin
37
- openclaw gateway restart
38
- ```
39
-
40
- A QR code appears in the terminal. Scan it with your phone and confirm the
41
- authorization. Credentials are saved locally. Verify the installation after the
42
- restart:
43
-
44
- ```bash
45
- openclaw plugins list
46
- openclaw channels status --probe
47
- ```
48
-
49
- ## Switch from Tencent's package
50
-
51
- Switch in place from `@tencent-weixin/openclaw-weixin`; **do not uninstall the
52
- Tencent package first**. Current OpenClaw uninstall behavior removes channel
53
- configuration owned by the plugin.
13
+ **命令行——一行安装或替换:**
54
14
 
55
15
  ```bash
56
16
  openclaw plugins install npm:openclaw-weixin --force
57
- openclaw gateway restart
58
- openclaw plugins list
59
- openclaw channels status --probe
60
17
  ```
61
18
 
62
- The forced install replaces the package that owns the same internal
63
- `openclaw-weixin` plugin/channel id. The old and community packages must not be
64
- enabled at the same time. Because the internal id and state paths are unchanged,
65
- channel configuration and login credentials are normally retained.
66
-
67
- ## Installation limitations
19
+ <details>
20
+ <summary>替换腾讯官方插件?先看这里</summary>
68
21
 
69
- - Use the CLI for this community npm package. OpenClaw's Control UI does not
70
- install arbitrary npm, git, or local-path plugin sources.
71
- - In Nix mode (`OPENCLAW_NIX_MODE=1`), plugin install, update, uninstall,
72
- enable, and disable commands are intentionally disabled. Add the package and
73
- config to the Nix source, then rebuild instead.
74
- - OpenClaw installs plugin dependencies with lifecycle scripts disabled. This
75
- package therefore ships its compiled `dist/index.js` runtime and does not
76
- build on the user's machine.
22
+ > **警告:**不要先卸载 `@tencent-weixin/openclaw-weixin` 或重新扫码。直接执行
23
+ > 上面的命令;原位替换通常会保留现有配置和登录状态。
77
24
 
78
- ## Adding More WeChat Accounts
25
+ </details>
79
26
 
80
- ```bash
81
- openclaw channels login --channel openclaw-weixin
82
- ```
83
-
84
- Each QR code login creates a new account entry, supporting multiple WeChat accounts online simultaneously.
85
-
86
- ## Multi-Account Context Isolation
27
+ <details>
28
+ <summary>绑定微信账号</summary>
87
29
 
88
- By default, DMs can share one session bucket. For **multiple logged-in WeChat accounts**, isolate by account + channel + sender:
30
+ 如需将微信账号绑定到当前 OpenClaw,请启用插件并开始扫码绑定:
89
31
 
90
32
  ```bash
91
- openclaw config set session.dmScope per-account-channel-peer
92
- ```
93
-
94
- ## Custom BotAgent (optional)
95
-
96
- Every outbound request to the WeChat backend carries a self-declared `bot_agent`
97
- identifier — analogous to an HTTP `User-Agent` — used for log attribution and
98
- monitoring aggregation. The default is `OpenClaw`. Declaring your own app name
99
- makes it much easier to trace your traffic in backend logs.
100
-
101
- Add one line to `openclaw.json`:
102
-
103
- ```json
104
- {
105
- "channels": {
106
- "openclaw-weixin": {
107
- "botAgent": "MyBot/1.2.0"
108
- }
109
- }
110
- }
111
- ```
112
-
113
- **Format** (UA-style):
114
-
115
- - One or more `Name/Version` tokens, space-separated
116
- - Each token may optionally be followed by ` (comment)`
117
- - ASCII only; total length ≤ 256 bytes
118
- - Invalid tokens are silently dropped during sanitization; falls back to
119
- `OpenClaw` if nothing valid remains
120
-
121
- Examples that pass through unchanged:
122
-
123
- - `MyBot/1.2.0`
124
- - `MyBot/1.2.0 (region=cn;env=prod)`
125
- - `MyBot/1.2.0 LangChain/0.3.5`
126
- - `MyBot/1.2.0-rc.1+build.5`
127
-
128
- **Note**: `bot_agent` is for observability only — it is not used for
129
- authentication or routing. All registered agents on this plugin instance
130
- currently share the same `botAgent` declaration; per-agent overrides may be
131
- added in a future version if needed.
132
-
133
- ## Backend API Protocol
134
-
135
- This plugin communicates with the backend gateway via HTTP JSON API. Developers integrating with their own backend need to implement the following interfaces.
136
-
137
- All endpoints use `POST` with JSON request and response bodies. Common request headers:
138
-
139
- | Header | Description |
140
- |--------|-------------|
141
- | `Content-Type` | `application/json` |
142
- | `AuthorizationType` | Fixed value `ilink_bot_token` |
143
- | `Authorization` | `Bearer <token>` (obtained after login) |
144
- | `X-WECHAT-UIN` | Base64-encoded random uint32 |
145
-
146
- ### Endpoint List
147
-
148
- | Endpoint | Path | Description |
149
- |----------|------|-------------|
150
- | getUpdates | `getupdates` | Long-poll for new messages |
151
- | sendMessage | `sendmessage` | Send a message (text/image/video/file) |
152
- | getUploadUrl | `getuploadurl` | Get CDN upload pre-signed URL |
153
- | getConfig | `getconfig` | Get account config (typing ticket, etc.) |
154
- | sendTyping | `sendtyping` | Send/cancel typing status indicator |
155
-
156
- ### getUpdates
157
-
158
- Long-polling endpoint. The server responds when new messages arrive or on timeout.
159
-
160
- **Request body:**
161
-
162
- ```json
163
- {
164
- "get_updates_buf": ""
165
- }
166
- ```
167
-
168
- | Field | Type | Description |
169
- |-------|------|-------------|
170
- | `get_updates_buf` | `string` | Sync cursor from the previous response; empty string for the first request |
171
-
172
- **Response body:**
173
-
174
- ```json
175
- {
176
- "ret": 0,
177
- "msgs": [...],
178
- "get_updates_buf": "<new cursor>",
179
- "longpolling_timeout_ms": 35000
180
- }
181
- ```
182
-
183
- | Field | Type | Description |
184
- |-------|------|-------------|
185
- | `ret` | `number` | Return code, `0` = success |
186
- | `errcode` | `number?` | Error code (e.g., `-14` = session timeout) |
187
- | `errmsg` | `string?` | Error description |
188
- | `msgs` | `WeixinMessage[]` | Message list (structure below) |
189
- | `get_updates_buf` | `string` | New sync cursor to pass in the next request |
190
- | `longpolling_timeout_ms` | `number?` | Server-suggested long-poll timeout for the next request (ms) |
191
-
192
- ### sendMessage
193
-
194
- Send a message to a user.
195
-
196
- **Request body:**
197
-
198
- ```json
199
- {
200
- "msg": {
201
- "to_user_id": "<target user ID>",
202
- "context_token": "<conversation context token>",
203
- "item_list": [
204
- {
205
- "type": 1,
206
- "text_item": { "text": "Hello" }
207
- }
208
- ]
209
- }
210
- }
33
+ openclaw plugins enable openclaw-weixin
34
+ openclaw channels login --channel openclaw-weixin
211
35
  ```
212
36
 
213
- ### getUploadUrl
37
+ 登录命令会在终端显示二维码。
214
38
 
215
- Get CDN upload pre-signed parameters. Call this endpoint before uploading a file to obtain `upload_param` and `thumb_upload_param`.
39
+ </details>
216
40
 
217
- **Request body:**
41
+ <details>
42
+ <summary>重载并检查</summary>
218
43
 
219
- ```json
220
- {
221
- "filekey": "<file identifier>",
222
- "media_type": 1,
223
- "to_user_id": "<target user ID>",
224
- "rawsize": 12345,
225
- "rawfilemd5": "<plaintext MD5>",
226
- "filesize": 12352,
227
- "thumb_rawsize": 1024,
228
- "thumb_rawfilemd5": "<thumbnail plaintext MD5>",
229
- "thumb_filesize": 1040
230
- }
231
- ```
44
+ 确保正在运行的 Gateway 已重载插件。必要时重启承载 OpenClaw 的服务、容器或
45
+ Pod,然后执行:
232
46
 
233
- | Field | Type | Description |
234
- |-------|------|-------------|
235
- | `media_type` | `number` | `1` = IMAGE, `2` = VIDEO, `3` = FILE |
236
- | `rawsize` | `number` | Original file plaintext size |
237
- | `rawfilemd5` | `string` | Original file plaintext MD5 |
238
- | `filesize` | `number` | Ciphertext size after AES-128-ECB encryption |
239
- | `thumb_rawsize` | `number?` | Thumbnail plaintext size (required for IMAGE/VIDEO) |
240
- | `thumb_rawfilemd5` | `string?` | Thumbnail plaintext MD5 (required for IMAGE/VIDEO) |
241
- | `thumb_filesize` | `number?` | Thumbnail ciphertext size (required for IMAGE/VIDEO) |
242
-
243
- **Response body:**
244
-
245
- ```json
246
- {
247
- "upload_param": "<original image upload encrypted parameters>",
248
- "thumb_upload_param": "<thumbnail upload encrypted parameters>"
249
- }
47
+ ```bash
48
+ openclaw plugins list
49
+ openclaw channels status --probe
250
50
  ```
251
51
 
252
- ### getConfig
52
+ 插件无加载错误且目标账号探测成功即完成;若显示未登录,请执行上面的登录命令。
253
53
 
254
- Get account configuration, including the typing ticket.
54
+ </details>
255
55
 
256
- **Request body:**
257
-
258
- ```json
259
- {
260
- "ilink_user_id": "<user ID>",
261
- "context_token": "<optional, conversation context token>"
262
- }
263
- ```
56
+ ### 通过 Agent 安装
264
57
 
265
- **Response body:**
58
+ OpenClaw `>=2026.7.2-beta.1` 时,如果已设置 `commands.plugins: true`,并且你是
59
+ owner/admin,直接发送:
266
60
 
267
- ```json
268
- {
269
- "ret": 0,
270
- "typing_ticket": "<base64-encoded typing ticket>"
271
- }
61
+ ```text
62
+ /plugins install npm:openclaw-weixin --force
272
63
  ```
273
64
 
274
- ### sendTyping
65
+ 然后按上面的**重载并检查**操作。
275
66
 
276
- Send or cancel the typing status indicator.
67
+ ### Shell Agent 提示词
277
68
 
278
- **Request body:**
69
+ 将下面的提示词直接发送给有 Shell 权限的 Agent,用于安全安装或原位替换插件。
70
+ 安装期间,启用了配置重载的受管 Gateway 可能自动重启;否则由你按 Agent 的提示重载,
71
+ 扫码仍由你完成:
279
72
 
280
- ```json
281
- {
282
- "ilink_user_id": "<user ID>",
283
- "typing_ticket": "<obtained from getConfig>",
284
- "status": 1
285
- }
73
+ ```text
74
+ 请在不改变现有配置和登录状态的前提下,安装或原位替换 `openclaw-weixin`。先确认
75
+ `openclaw --version` 不低于 2026.7.1。我信任 npm 来源 `openclaw-weixin`。执行
76
+ `openclaw plugins install npm:openclaw-weixin --force`;不要先卸载,也不要查看
77
+ 或复制工作区、凭据及账号状态文件。仅在 `openclaw plugins list` 显示已停用时
78
+ 启用插件。不要主动重启 Gateway 或发起扫码登录;安装可能使启用了配置重载的受管
79
+ Gateway 自动重启。若已自动重启,执行 `openclaw channels status --probe`;否则只
80
+ 告诉我需重载的实际 Gateway、服务、容器或 Pod,待我确认重载后再探测。只报告脱敏
81
+ 结果;若未登录,提示我手动扫码。
286
82
  ```
287
83
 
288
- | Field | Type | Description |
289
- |-------|------|-------------|
290
- | `status` | `number` | `1` = typing, `2` = cancel typing |
84
+ ## 多账号
291
85
 
292
- ### Message Structure
293
-
294
- #### WeixinMessage
295
-
296
- | Field | Type | Description |
297
- |-------|------|-------------|
298
- | `seq` | `number?` | Message sequence number |
299
- | `message_id` | `number?` | Unique message ID |
300
- | `from_user_id` | `string?` | Sender ID |
301
- | `to_user_id` | `string?` | Receiver ID |
302
- | `create_time_ms` | `number?` | Creation timestamp (ms) |
303
- | `session_id` | `string?` | Session ID |
304
- | `message_type` | `number?` | `1` = USER, `2` = BOT |
305
- | `message_state` | `number?` | `0` = NEW, `1` = GENERATING, `2` = FINISH |
306
- | `item_list` | `MessageItem[]?` | Message content list |
307
- | `context_token` | `string?` | Conversation context token, must be passed back when replying |
308
-
309
- #### MessageItem
310
-
311
- | Field | Type | Description |
312
- |-------|------|-------------|
313
- | `type` | `number` | `1` TEXT, `2` IMAGE, `3` VOICE, `4` FILE, `5` VIDEO |
314
- | `text_item` | `{ text: string }?` | Text content |
315
- | `image_item` | `ImageItem?` | Image (with CDN reference and AES key) |
316
- | `voice_item` | `VoiceItem?` | Voice (SILK encoded) |
317
- | `file_item` | `FileItem?` | File attachment |
318
- | `video_item` | `VideoItem?` | Video |
319
- | `ref_msg` | `RefMessage?` | Referenced message |
320
-
321
- #### CDN Media Reference (CDNMedia)
322
-
323
- All media types (image/voice/file/video) are transferred via CDN using AES-128-ECB encryption:
324
-
325
- | Field | Type | Description |
326
- |-------|------|-------------|
327
- | `encrypt_query_param` | `string?` | Encrypted parameters for CDN download/upload |
328
- | `aes_key` | `string?` | Base64-encoded AES-128 key |
329
-
330
- ### CDN Upload Flow
331
-
332
- 1. Calculate the file's plaintext size, MD5, and ciphertext size after AES-128-ECB encryption
333
- 2. If a thumbnail is needed (image/video), calculate the thumbnail's plaintext and ciphertext parameters as well
334
- 3. Call `getUploadUrl` to get `upload_param` (and `thumb_upload_param`)
335
- 4. Encrypt the file content with AES-128-ECB and PUT upload to the CDN URL
336
- 5. Encrypt and upload the thumbnail in the same way
337
- 6. Use the returned `encrypt_query_param` to construct a `CDNMedia` reference, include it in the `MessageItem`, and send
338
-
339
- > For complete type definitions, see [`src/api/types.ts`](src/api/types.ts). For API call implementations, see [`src/api/api.ts`](src/api/api.ts).
340
-
341
- ## Uninstall
342
-
343
- Back up `~/.openclaw/openclaw.json` first if you may want to reinstall: current
344
- OpenClaw versions remove the plugin entry and owned
345
- `channels.openclaw-weixin` configuration during uninstall.
86
+ 再次执行登录命令即可绑定其他微信账号:
346
87
 
347
88
  ```bash
348
- openclaw plugins uninstall openclaw-weixin
89
+ openclaw channels login --channel openclaw-weixin
349
90
  ```
350
91
 
351
- ## Troubleshooting
352
-
353
- ### "requires OpenClaw >=2026.7.1" error
354
-
355
- Your OpenClaw version is too old for this plugin version. Check with:
92
+ 多个账号同时登录时,建议按「账号 + 渠道 + 对端」隔离上下文:
356
93
 
357
94
  ```bash
358
- openclaw --version
95
+ openclaw config set session.dmScope per-account-channel-peer
359
96
  ```
360
97
 
361
- Upgrade OpenClaw before installing this package. The community package does not
362
- publish a legacy compatibility line.
363
-
364
- ### Channel shows "OK" but doesn't connect
365
-
366
- Ensure `plugins.entries.openclaw-weixin.enabled` is `true` in `~/.openclaw/openclaw.json`:
98
+ ## 文档
367
99
 
368
- ```bash
369
- openclaw config set plugins.entries.openclaw-weixin.enabled true
370
- openclaw gateway restart
371
- ```
100
+ - [详细指南](docs/guide.zh_CN.md):安装行为、BotAgent、卸载和故障排查
101
+ - [后端 API 协议](docs/backend-api.zh_CN.md)
102
+ - [架构说明](docs/architecture.md)