@kyan-du/agent-wechat-openclaw 0.12.0-next.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 +216 -0
- package/dist/index.js +7629 -0
- package/openclaw.plugin.json +56 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# @kyan-du/agent-wechat-openclaw
|
|
2
|
+
|
|
3
|
+
OpenClaw channel plugin for WeChat. Connects your OpenClaw bot to WeChat using [agent-wechat](https://github.com/kyan-du/agent-wechat).
|
|
4
|
+
|
|
5
|
+
**[Documentation](https://kyan-du.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
|
+
> **Release boundary:** Fork npm, GHCR, and hosted documentation are unavailable until P1-B publishes and verifies them. The commands below use the repository source/local-build path.
|
|
20
|
+
|
|
21
|
+
### 1. Start the agent-wechat Server
|
|
22
|
+
|
|
23
|
+
If you need to run the server yourself:
|
|
24
|
+
|
|
25
|
+
**Option A: CLI** (quickest for local use)
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone https://github.com/kyan-du/agent-wechat.git
|
|
29
|
+
cd agent-wechat
|
|
30
|
+
corepack enable && pnpm install --frozen-lockfile
|
|
31
|
+
pnpm build && pnpm build:image
|
|
32
|
+
pnpm cli start
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Option B: Docker Compose** (production / networked)
|
|
36
|
+
|
|
37
|
+
```yaml
|
|
38
|
+
services:
|
|
39
|
+
agent-wechat:
|
|
40
|
+
image: agent-wechat:${AGENT_WECHAT_ARCH:-amd64}
|
|
41
|
+
container_name: agent-wechat
|
|
42
|
+
hostname: ${AGENT_WECHAT_HOSTNAME:?run scripts/device-identity.sh}
|
|
43
|
+
mac_address: ${AGENT_WECHAT_MAC:?run scripts/device-identity.sh}
|
|
44
|
+
security_opt:
|
|
45
|
+
- seccomp=unconfined
|
|
46
|
+
cap_add:
|
|
47
|
+
- SYS_PTRACE
|
|
48
|
+
- NET_ADMIN
|
|
49
|
+
ports:
|
|
50
|
+
- "6174:6174"
|
|
51
|
+
volumes:
|
|
52
|
+
- agent-wechat-data:/data
|
|
53
|
+
- agent-wechat-home:/home/wechat
|
|
54
|
+
- ~/.config/agent-wechat/token:/data/auth-token:ro
|
|
55
|
+
environment:
|
|
56
|
+
- AGENT_WECHAT_MACHINE_ID=${AGENT_WECHAT_MACHINE_ID:?run scripts/device-identity.sh}
|
|
57
|
+
- AGENT_WECHAT_HOSTNAME=${AGENT_WECHAT_HOSTNAME:?run scripts/device-identity.sh}
|
|
58
|
+
- AGENT_WECHAT_MAC=${AGENT_WECHAT_MAC:?run scripts/device-identity.sh}
|
|
59
|
+
restart: unless-stopped
|
|
60
|
+
|
|
61
|
+
volumes:
|
|
62
|
+
agent-wechat-data:
|
|
63
|
+
agent-wechat-home:
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Generate a token and a persistent device identity before starting. Hostname and MAC must be applied at create time; a mismatch aborts the entrypoint before WeChat starts. From the agent-wechat repo:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
mkdir -p ~/.config/agent-wechat
|
|
70
|
+
openssl rand -hex 32 > ~/.config/agent-wechat/token
|
|
71
|
+
chmod 600 ~/.config/agent-wechat/token
|
|
72
|
+
eval "$(./scripts/device-identity.sh)"
|
|
73
|
+
docker compose up -d
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
If running alongside OpenClaw on the same Docker network, set `serverUrl` to `http://agent-wechat:6174` in the channel config.
|
|
77
|
+
|
|
78
|
+
### 2. Install the extension
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Pending P1-B (not available yet): openclaw plugins install @kyan-du/agent-wechat-openclaw
|
|
82
|
+
pnpm --filter @kyan-du/agent-wechat-openclaw build
|
|
83
|
+
node scripts/prepare-openclaw-plugin.mjs
|
|
84
|
+
openclaw plugins install -l ./.artifacts/openclaw-extension
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 3. Configure the channel
|
|
88
|
+
|
|
89
|
+
OpenClaw's channel catalog may map `openclaw channels add --channel wechat` to its official Weixin plugin rather than this source plugin. Configure the staged plugin through its schema keys and verify the runtime load explicitly:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
openclaw config set channels.wechat.enabled true
|
|
93
|
+
openclaw config set channels.wechat.serverUrl http://localhost:6174
|
|
94
|
+
# Optional when the server requires an explicit token:
|
|
95
|
+
openclaw config set channels.wechat.token <token>
|
|
96
|
+
openclaw plugins inspect wechat --runtime
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Or edit `~/.openclaw/openclaw.json` directly:
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"channels": {
|
|
104
|
+
"wechat": {
|
|
105
|
+
"enabled": true,
|
|
106
|
+
"serverUrl": "http://localhost:6174",
|
|
107
|
+
"dmPolicy": "open",
|
|
108
|
+
"groupPolicy": "open"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
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.
|
|
115
|
+
|
|
116
|
+
### 4. Restart the gateway
|
|
117
|
+
|
|
118
|
+
Restart your OpenClaw gateway so it picks up the new channel config:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
openclaw gateway restart
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 5. Log in to WeChat
|
|
125
|
+
|
|
126
|
+
Ask your bot to log in to WeChat:
|
|
127
|
+
|
|
128
|
+
> "Log in to WeChat"
|
|
129
|
+
|
|
130
|
+
Your bot should generate a QR code image. Alternatively, use the CLI:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
openclaw channels login --channel wechat
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### 6. Scan the QR code
|
|
137
|
+
|
|
138
|
+
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.
|
|
139
|
+
|
|
140
|
+
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.
|
|
141
|
+
|
|
142
|
+
You only need to do this once — the session persists across container restarts.
|
|
143
|
+
|
|
144
|
+
### 7. Configure DM and group policies
|
|
145
|
+
|
|
146
|
+
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.
|
|
147
|
+
|
|
148
|
+
## Limitations
|
|
149
|
+
|
|
150
|
+
- **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.
|
|
151
|
+
|
|
152
|
+
- **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.
|
|
153
|
+
|
|
154
|
+
- **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.
|
|
155
|
+
|
|
156
|
+
## Configuration Reference
|
|
157
|
+
|
|
158
|
+
All config lives under `channels.wechat` in OpenClaw's config file:
|
|
159
|
+
|
|
160
|
+
| Key | Type | Default | Description |
|
|
161
|
+
|-----|------|---------|-------------|
|
|
162
|
+
| `enabled` | boolean | `false` | Enable the WeChat channel |
|
|
163
|
+
| `serverUrl` | string | — | agent-wechat REST API URL |
|
|
164
|
+
| `token` | string | — | Auth token (auto-read from `~/.config/agent-wechat/token` for local setups) |
|
|
165
|
+
| `dmPolicy` | `"open" \| "allowlist" \| "disabled"` | `"disabled"` | Who can DM the bot |
|
|
166
|
+
| `allowFrom` | string[] | `[]` | wxid allowlist for DMs (when policy is `allowlist`) |
|
|
167
|
+
| `groupPolicy` | `"open" \| "allowlist" \| "disabled"` | `"disabled"` | Group message policy |
|
|
168
|
+
| `groupAllowFrom` | string[] | `[]` | Global allowlist of group sender IDs (`wxid_...`) |
|
|
169
|
+
| `groups` | object | `{}` | Per-group overrides (e.g. `{ "id@chatroom": { "requireMention": false, "enabled": true, "groupPolicy": "allowlist", "allowFrom": ["wxid_..."] } }`) |
|
|
170
|
+
| `pollIntervalMs` | integer | `1000` | Message polling interval |
|
|
171
|
+
| `authPollIntervalMs` | integer | `30000` | Auth status check interval |
|
|
172
|
+
| `catchUpMode` | `"read-only" \| "latest"` | `"read-only"` | On startup/recovery, advance the cursor without replying (`read-only`) or dispatch only the bounded recent suffix (`latest`) |
|
|
173
|
+
| `catchUpMaxMessages` | integer | `10` | Maximum messages eligible for a recovery dispatch |
|
|
174
|
+
| `catchUpMaxAgeMs` | integer | `300000` | Maximum age of messages eligible for a recovery dispatch |
|
|
175
|
+
| `catchUpChatBudget` | integer | `5` | Max chats that auto-reply in one reconnect window. Leftovers stay held; raise this to continue, one send per poll |
|
|
176
|
+
| `mediaPartDelayMs` | integer | `750` | Minimum delay between media items and their caption in one logical send task |
|
|
177
|
+
|
|
178
|
+
## Development
|
|
179
|
+
|
|
180
|
+
### Build from source
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
git clone https://github.com/kyan-du/agent-wechat.git
|
|
184
|
+
cd agent-wechat
|
|
185
|
+
pnpm install && pnpm build
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Link for local development
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
node scripts/prepare-openclaw-plugin.mjs
|
|
192
|
+
openclaw plugins install -l ./.artifacts/openclaw-extension
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
This stages only the built plugin files and a production manifest, avoiding pnpm workspace symlinks that OpenClaw correctly rejects as escaping the install root. Rebuild and restage after making changes, then restart the gateway.
|
|
196
|
+
|
|
197
|
+
## Architecture
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
OpenClaw Gateway
|
|
201
|
+
└── WeChat Monitor (polling loop)
|
|
202
|
+
│
|
|
203
|
+
│ GET /api/chats (list chats with unreads)
|
|
204
|
+
│ POST /api/chats/{id}/open (open chat, clear unreads)
|
|
205
|
+
│ GET /api/messages/{id} (fetch new messages)
|
|
206
|
+
│ GET /api/messages/{id}/media/{localId} (download media)
|
|
207
|
+
│ POST /api/messages/send (send reply)
|
|
208
|
+
│
|
|
209
|
+
▼
|
|
210
|
+
agent-wechat container (port 6174)
|
|
211
|
+
│
|
|
212
|
+
▼
|
|
213
|
+
WeChat Desktop (in Xvfb)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
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.
|