@kyan-du/agent-wechat-wechaty-puppet 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 ADDED
@@ -0,0 +1,107 @@
1
+ # @kyan-du/agent-wechat-wechaty-puppet
2
+
3
+ Wechaty Puppet for [agent-wechat](https://github.com/kyan-du/agent-wechat). Bridges any Wechaty bot to WeChat via the agent-wechat REST/WebSocket server.
4
+
5
+ > **Release boundary:** Fork npm, GHCR, and hosted documentation are unavailable until P1-B publishes and verifies them. Clone this repository, run `corepack enable && pnpm install --frozen-lockfile && pnpm build && pnpm build:image`, and start the local image with `pnpm cli start`.
6
+
7
+ **[Documentation](https://kyan-du.github.io/agent-wechat/integrations/wechaty/puppet-setup/)**
8
+
9
+ ## Prerequisites
10
+
11
+ - **An agent-wechat server** running — set up via the CLI or from the [agent-wechat repo](https://github.com/kyan-du/agent-wechat):
12
+ ```bash
13
+ pnpm cli start # from a built repository checkout
14
+ ```
15
+ Login is not required as a separate CLI step; you can log in through the puppet QR flow.
16
+ - **Node.js >= 22**
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ # Pending P1-B (not available yet): npm install @kyan-du/agent-wechat-wechaty-puppet wechaty wechaty-puppet
22
+ git clone https://github.com/kyan-du/agent-wechat.git
23
+ cd agent-wechat
24
+ corepack enable && pnpm install --frozen-lockfile
25
+ pnpm build
26
+ PUPPET_TARBALL=$(cd packages/wechaty-puppet && npm pack --silent)
27
+ mkdir -p /tmp/agent-wechat-wechaty-consumer
28
+ cd /tmp/agent-wechat-wechaty-consumer
29
+ npm init -y
30
+ npm install "$OLDPWD/packages/wechaty-puppet/$PUPPET_TARBALL" wechaty wechaty-puppet
31
+ ```
32
+
33
+ Create the example below as `bot.mjs` in that clean consumer directory and run `node bot.mjs`. This verifies the package import through its real tarball rather than workspace resolution.
34
+
35
+ ## Usage
36
+
37
+ ```ts
38
+ import { WechatyBuilder } from 'wechaty'
39
+ import PuppetAgentWeChat from '@kyan-du/agent-wechat-wechaty-puppet'
40
+
41
+ const bot = WechatyBuilder.build({
42
+ puppet: new PuppetAgentWeChat({
43
+ serverUrl: 'http://localhost:6174', // optional, this is the default
44
+ token: 'your-token', // optional, reads from ~/.config/agent-wechat/token
45
+ })
46
+ })
47
+
48
+ bot.on('scan', (qrcode, status) => {
49
+ console.log(`Scan QR Code to login: ${status}\nhttps://wechaty.js.org/qrcode/${encodeURIComponent(qrcode)}`)
50
+ })
51
+
52
+ bot.on('login', user => console.log(`Logged in: ${user}`))
53
+
54
+ bot.on('message', async msg => {
55
+ if (msg.text() === 'ding') {
56
+ await msg.say('dong')
57
+ }
58
+ })
59
+
60
+ await bot.start()
61
+ ```
62
+
63
+ ## Configuration
64
+
65
+ | Option | Type | Default | Description |
66
+ |--------|------|---------|-------------|
67
+ | `serverUrl` | string | `http://localhost:6174` | agent-wechat server URL |
68
+ | `token` | string | auto | Auth token. Falls back to `AGENT_WECHAT_TOKEN` env var, then `~/.config/agent-wechat/token` |
69
+ | `pollIntervalMs` | number | `2000` | Message polling interval in milliseconds |
70
+
71
+ ## Supported Features
72
+
73
+ | Feature | Status | Notes |
74
+ |---------|--------|-------|
75
+ | QR Login | Yes | Via WebSocket `/api/ws/login` |
76
+ | Logout | Yes | |
77
+ | Receive Text | Yes | Polling-based |
78
+ | Receive Image | Yes | Via media endpoint |
79
+ | Receive Voice | Yes | Via media endpoint |
80
+ | Receive Video | Yes | Via media endpoint |
81
+ | Receive Emoticon | Yes | |
82
+ | Send Text | Yes | |
83
+ | Send Image | Yes | |
84
+ | Send File | Yes | |
85
+ | Contact List | Yes | Full address book via `/api/contacts` |
86
+ | Contact Alias | Read | From remark field |
87
+ | Room List | Partial | Recent group chats only |
88
+ | Room Topic | Read | From group name |
89
+ | Forward Text | Yes | |
90
+ | Send URL | Partial | Sent as plain text |
91
+ | Message Recall | No | |
92
+ | Room Create | No | |
93
+ | Room Add/Remove | No | |
94
+ | Friendship | No | |
95
+ | Tags | No | |
96
+ | Moments/Posts | No | |
97
+
98
+ ## How It Works
99
+
100
+ The puppet connects to the agent-wechat REST API (Rust server running inside a Docker container alongside WeChat desktop). It does not interact with WeChat directly.
101
+
102
+ - **Login**: WebSocket subscription to `/api/ws/login` drives QR scan events
103
+ - **Messages**: Polls `GET /api/chats` for unreads, then `GET /api/messages/{chatId}` for new messages
104
+ - **Sending**: `POST /api/messages/send` with text, image, or file payloads
105
+ - **Media**: `GET /api/messages/{chatId}/media/{localId}` for image/voice/video downloads
106
+ - **Contacts**: Full address book via `GET /api/contacts`
107
+ - **Rooms**: Derived from `GET /api/chats` (group chats)
package/dist/mod.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { PuppetAgentWeChat, PuppetAgentWeChat as default } from './puppet-agent-wechat.js';
2
+ export type { PuppetAgentWeChatOptions } from './puppet-agent-wechat.js';
3
+ //# sourceMappingURL=mod.d.ts.map