@liangrk/claude-code-wechatbot 0.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # Claude Code WeChat Channel
2
+
3
+ 将微信消息桥接到 Claude Code 会话的 Channel 插件。
4
+
5
+ 基于微信官方 ClawBot ilink API(与 `@tencent-weixin/openclaw-weixin` 使用相同协议),让你在微信中直接与 Claude Code 对话。
6
+
7
+ ## 工作原理
8
+
9
+ ```
10
+ 微信 (iOS) → WeChat ClawBot → ilink API → [本插件] → Claude Code Session
11
+
12
+ Claude Code ← MCP Channel Protocol ← wechat_reply tool
13
+ ```
14
+
15
+ ## 前置要求
16
+
17
+ - [Node.js](https://nodejs.org) >= 18(或 [Bun](https://bun.sh) >= 1.0)
18
+ - [Claude Code](https://claude.com/claude-code) >= 2.1.80
19
+ - claude.ai 账号登录或 API key(`ANTHROPIC_API_KEY`)
20
+ - 微信 iOS 最新版(需支持 ClawBot 插件)
21
+
22
+ ## 快速开始
23
+
24
+ ### 1. 微信扫码登录
25
+
26
+ ```bash
27
+ npx claude-code-wechat-channel setup
28
+ ```
29
+
30
+ 终端会显示二维码,用微信扫描并确认。凭据保存到 `~/.claude/channels/wechat/account.json`。
31
+
32
+ ### 2. 生成 MCP 配置
33
+
34
+ ```bash
35
+ npx claude-code-wechat-channel install
36
+ ```
37
+
38
+ 这会在当前目录生成(或更新) `.mcp.json`,指向本插件。
39
+
40
+ ### 3. 启动 Claude Code + WeChat 通道
41
+
42
+ ```bash
43
+ claude --dangerously-load-development-channels server:wechat
44
+ ```
45
+
46
+ ### 4. 在微信中发消息
47
+
48
+ 打开微信,找到 ClawBot 对话,发送消息。消息会出现在 Claude Code 终端中,Claude 的回复会自动发回微信。
49
+
50
+ ## 命令说明
51
+
52
+ | 命令 | 说明 |
53
+ |------|------|
54
+ | `npx claude-code-wechat-channel setup` | 微信扫码登录 |
55
+ | `npx claude-code-wechat-channel install` | 生成 .mcp.json 配置 |
56
+ | `npx claude-code-wechat-channel start` | 启动 MCP Channel 服务器 |
57
+ | `npx claude-code-wechat-channel help` | 显示帮助 |
58
+
59
+ ## 技术细节
60
+
61
+ - **消息接收**: 通过 `ilink/bot/getupdates` 长轮询获取微信消息
62
+ - **消息发送**: 通过 `ilink/bot/sendmessage` 发送回复
63
+ - **认证**: 使用 `ilink/bot/get_bot_qrcode` QR 码登录获取 Bearer Token
64
+ - **协议**: 基于 MCP (Model Context Protocol) 的 Channel 扩展
65
+
66
+ ## 注意事项
67
+
68
+ - 当前为 research preview 阶段,需要使用 `--dangerously-load-development-channels` 标志
69
+ - Claude Code 会话关闭后通道也会断开
70
+ - 微信 ClawBot 目前仅支持 iOS 最新版
71
+ - 每个 ClawBot 只能连接一个 agent 实例
72
+
73
+ ## License
74
+
75
+ MIT
package/cli.mjs ADDED
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Claude Code WeChat Channel — CLI entry point
5
+ *
6
+ * Usage:
7
+ * npx claude-code-wechat-channel setup — WeChat QR login
8
+ * npx claude-code-wechat-channel start — Start channel server (used by .mcp.json)
9
+ * npx claude-code-wechat-channel install — Write .mcp.json to current directory
10
+ */
11
+
12
+ import { execSync, spawnSync } from "node:child_process";
13
+ import { existsSync, writeFileSync, readFileSync, renameSync } from "node:fs";
14
+ import { resolve, dirname } from "node:path";
15
+ import { fileURLToPath } from "node:url";
16
+
17
+ const __dirname = dirname(fileURLToPath(import.meta.url));
18
+ const DIST_DIR = resolve(__dirname, "dist");
19
+
20
+ function getBunPath() {
21
+ try {
22
+ return execSync("which bun", { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
23
+ } catch {
24
+ return null;
25
+ }
26
+ }
27
+
28
+ function getNodePath() {
29
+ return process.execPath;
30
+ }
31
+
32
+ function runScript(script, args = []) {
33
+ const scriptPath = resolve(DIST_DIR, script);
34
+ if (!existsSync(scriptPath)) {
35
+ console.error(`Error: ${scriptPath} not found. Package may be corrupted.`);
36
+ process.exit(1);
37
+ }
38
+
39
+ // Prefer bun for performance, fall back to node
40
+ const bun = getBunPath();
41
+ const runtime = bun || getNodePath();
42
+ const result = spawnSync(runtime, [scriptPath, ...args], {
43
+ stdio: "inherit",
44
+ env: process.env,
45
+ });
46
+ process.exit(result.status ?? 1);
47
+ }
48
+
49
+ function install() {
50
+ const mcpConfig = {
51
+ mcpServers: {
52
+ wechat: {
53
+ command: "npx",
54
+ args: ["-y", "@liangrk/claude-code-wechatbot", "start"],
55
+ },
56
+ },
57
+ };
58
+
59
+ const mcpPath = resolve(process.cwd(), ".mcp.json");
60
+ const tmpPath = mcpPath + ".tmp";
61
+
62
+ function atomicWrite(filePath, content) {
63
+ writeFileSync(tmpPath, content, "utf-8");
64
+ renameSync(tmpPath, filePath);
65
+ }
66
+
67
+ if (existsSync(mcpPath)) {
68
+ try {
69
+ const existing = JSON.parse(readFileSync(mcpPath, "utf-8"));
70
+ existing.mcpServers = existing.mcpServers || {};
71
+ existing.mcpServers.wechat = mcpConfig.mcpServers.wechat;
72
+ atomicWrite(mcpPath, JSON.stringify(existing, null, 2) + "\n");
73
+ console.log(`Updated: ${mcpPath}`);
74
+ } catch (err) {
75
+ console.error(`Warning: Failed to update existing .mcp.json: ${err}`);
76
+ atomicWrite(mcpPath, JSON.stringify(mcpConfig, null, 2) + "\n");
77
+ console.log(`Created: ${mcpPath}`);
78
+ }
79
+ } else {
80
+ atomicWrite(mcpPath, JSON.stringify(mcpConfig, null, 2) + "\n");
81
+ console.log(`Created: ${mcpPath}`);
82
+ }
83
+
84
+ console.log(`
85
+ Next steps:
86
+ 1. Run: npx claude-code-wechat-channel setup
87
+ 2. Then: claude --dangerously-load-development-channels server:wechat
88
+ `);
89
+ }
90
+
91
+ function help() {
92
+ console.log(`
93
+ Claude Code WeChat Channel
94
+
95
+ Usage: npx claude-code-wechat-channel <command>
96
+
97
+ Commands:
98
+ setup WeChat QR login (scan to authenticate)
99
+ start Start the channel MCP server
100
+ install Write .mcp.json to current directory
101
+ help Show this help message
102
+ `);
103
+ }
104
+
105
+ const command = process.argv[2];
106
+
107
+ switch (command) {
108
+ case "setup":
109
+ runScript("setup.js");
110
+ break;
111
+ case "start":
112
+ runScript("wechat-channel.js");
113
+ break;
114
+ case "install":
115
+ install();
116
+ break;
117
+ case "help":
118
+ case "--help":
119
+ case "-h":
120
+ help();
121
+ break;
122
+ default:
123
+ if (command) {
124
+ console.error(`Unknown command: ${command}`);
125
+ }
126
+ help();
127
+ process.exit(command ? 1 : 0);
128
+ }