claw_messenger 0.0.1
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 +111 -0
- package/bin/auto-init.js +98 -0
- package/bin/dm-bridge.js +12 -0
- package/bin/install.js +217 -0
- package/bin/setup.js +160 -0
- package/bridge-runner.ts +324 -0
- package/dist/bridge-runner.d.ts +2 -0
- package/dist/bridge-runner.d.ts.map +1 -0
- package/dist/bridge-runner.js +268 -0
- package/dist/bridge-runner.js.map +1 -0
- package/dist/src/auto-register.d.ts +2 -0
- package/dist/src/auto-register.d.ts.map +1 -0
- package/dist/src/auto-register.js +82 -0
- package/dist/src/auto-register.js.map +1 -0
- package/dist/src/env-polyfill.d.ts +8 -0
- package/dist/src/env-polyfill.d.ts.map +1 -0
- package/dist/src/env-polyfill.js +101 -0
- package/dist/src/env-polyfill.js.map +1 -0
- package/dist/src/index.d.ts +36 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +75 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/plugin-entry.d.ts +9 -0
- package/dist/src/plugin-entry.d.ts.map +1 -0
- package/dist/src/plugin-entry.js +174 -0
- package/dist/src/plugin-entry.js.map +1 -0
- package/dist/src/rongcloud-client.d.ts +21 -0
- package/dist/src/rongcloud-client.d.ts.map +1 -0
- package/dist/src/rongcloud-client.js +87 -0
- package/dist/src/rongcloud-client.js.map +1 -0
- package/dist/test-bridge.js +81 -0
- package/dist/test-connection.js +65 -0
- package/dist/test-mock.js +72 -0
- package/openclaw.plugin.json +24 -0
- package/package.json +88 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/**
|
|
7
|
+
* 快速测试脚本 - 使用已有节点 token 测试 bridge
|
|
8
|
+
*/
|
|
9
|
+
const rongcloud_client_1 = require("./src/rongcloud-client");
|
|
10
|
+
const axios_1 = __importDefault(require("axios"));
|
|
11
|
+
const NODE_ID = 'claw_user_614681fad6643783_005';
|
|
12
|
+
const NODE_NAME = '龙虾5号';
|
|
13
|
+
const TOKEN = 'jtXLzSNYhJ99VW8rkgYhWzeqsV06TkPMobzk9RRWZiTddhpsulHcO8Ewjgz+JMidviQs+YylOg4=@3pvy.cn.rongnav.com;3pvy.cn.rongcfg.com';
|
|
14
|
+
const APP_KEY = 'bmdehs6pbyyks';
|
|
15
|
+
const OPENCLAW_URL = 'http://localhost:5678';
|
|
16
|
+
const MODEL = 'soulx-flashtalk-14b';
|
|
17
|
+
async function main() {
|
|
18
|
+
console.log('[Test] ========== Bridge 测试 ==========');
|
|
19
|
+
console.log(` 节点: ${NODE_ID} (${NODE_NAME})`);
|
|
20
|
+
console.log(` OpenClaw: ${OPENCLAW_URL}`);
|
|
21
|
+
const client = new rongcloud_client_1.RongCloudClient({
|
|
22
|
+
appKey: APP_KEY,
|
|
23
|
+
token: TOKEN,
|
|
24
|
+
onMessage: async (msg) => {
|
|
25
|
+
var _a, _b, _c, _d, _e;
|
|
26
|
+
const content = ((_a = msg.content) === null || _a === void 0 ? void 0 : _a.content) || '';
|
|
27
|
+
const fromUser = msg.senderUserId;
|
|
28
|
+
const targetId = msg.targetId;
|
|
29
|
+
const convType = msg.conversationType;
|
|
30
|
+
console.log(`\n[Test] ========== 收到消息 ==========`);
|
|
31
|
+
console.log(` 发送者: ${fromUser}`);
|
|
32
|
+
console.log(` 目标: ${targetId}`);
|
|
33
|
+
console.log(` 类型: ${convType === 3 ? '群聊' : '私聊'}`);
|
|
34
|
+
console.log(` 内容: ${content}`);
|
|
35
|
+
if (msg.messageType !== 'RC:TxtMsg') {
|
|
36
|
+
console.log('[Test] 非文本消息,忽略');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (fromUser === NODE_ID) {
|
|
40
|
+
console.log('[Test] 自己发送的消息,忽略');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
console.log('[Test] 调用 OpenClaw...');
|
|
45
|
+
const resp = await axios_1.default.post(`${OPENCLAW_URL}/v1/chat/completions`, {
|
|
46
|
+
model: MODEL,
|
|
47
|
+
messages: [
|
|
48
|
+
{ role: 'system', content: `你是${NODE_NAME},一个AI助手。回复要简洁友好。` },
|
|
49
|
+
{ role: 'user', content }
|
|
50
|
+
],
|
|
51
|
+
stream: false,
|
|
52
|
+
max_tokens: 200,
|
|
53
|
+
}, { timeout: 30000 });
|
|
54
|
+
const reply = ((_e = (_d = (_c = (_b = resp.data) === null || _b === void 0 ? void 0 : _b.choices) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.message) === null || _e === void 0 ? void 0 : _e.content) || '抱歉,我暂时无法回复。';
|
|
55
|
+
console.log(`[Test] AI 回复: ${reply}`);
|
|
56
|
+
const replyTarget = convType === 3 ? targetId : fromUser;
|
|
57
|
+
await client.sendMessage(replyTarget, reply, convType);
|
|
58
|
+
console.log(`[Test] 已回复到: ${replyTarget}`);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
console.error(`[Test] 处理失败: ${err.message}`);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
onConnectSuccess: (userId) => {
|
|
65
|
+
console.log(`\n[Test] 连接成功! userId: ${userId}`);
|
|
66
|
+
console.log('[Test] 等待消息... (在融云App中给此节点发消息测试)\n');
|
|
67
|
+
},
|
|
68
|
+
onError: (code) => {
|
|
69
|
+
console.error(`[Test] 连接错误: ${code}`);
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
console.log('\n[Test] 连接融云...');
|
|
73
|
+
await client.connect();
|
|
74
|
+
console.log('\n[Test] 按 Ctrl+C 退出');
|
|
75
|
+
process.stdin.resume();
|
|
76
|
+
process.on('SIGINT', () => {
|
|
77
|
+
console.log('\n[Test] 退出');
|
|
78
|
+
process.exit(0);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* 测试脚本:验证融云 SDK 在 Node.js 环境下的连接和收发消息功能
|
|
5
|
+
* 运行方式: npx ts-node test-connection.ts
|
|
6
|
+
*/
|
|
7
|
+
const rongcloud_client_1 = require("./src/rongcloud-client");
|
|
8
|
+
// ================= 配置区 =================
|
|
9
|
+
// 请替换为你的融云 AppKey 和 Token
|
|
10
|
+
// Token 可以通过你的服务端 API 获取,或者使用融云控制台生成的测试 Token
|
|
11
|
+
const APP_KEY = 'bmdehs6pbyyks';
|
|
12
|
+
const TOKEN = 'jtXLzSNYhJ99VW8rkgYhWzeqsV06TkPMobzk9RRWZiSP2u6LRf6VqWgu3JabtYJteWXxEFzQVTg=@3pvy.cn.rongnav.com;3pvy.cn.rongcfg.com';
|
|
13
|
+
// ==========================================
|
|
14
|
+
async function main() {
|
|
15
|
+
console.log('=== 融云 Node.js 连接测试 ===');
|
|
16
|
+
if (APP_KEY === 'YOUR_RONGCLOUD_APP_KEY' || TOKEN === 'YOUR_RONGCLOUD_TOKEN') {
|
|
17
|
+
console.error('请先在 test-connection.ts 中配置 APP_KEY 和 TOKEN');
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
const client = new rongcloud_client_1.RongCloudClient({
|
|
21
|
+
appKey: APP_KEY,
|
|
22
|
+
token: TOKEN,
|
|
23
|
+
onMessage: (msg) => {
|
|
24
|
+
var _a;
|
|
25
|
+
console.log('\n[收到新消息]');
|
|
26
|
+
console.log('发送者:', msg.senderUserId);
|
|
27
|
+
console.log('内容:', (_a = msg.content) === null || _a === void 0 ? void 0 : _a.content);
|
|
28
|
+
console.log('会话类型:', msg.conversationType);
|
|
29
|
+
console.log('目标 ID:', msg.targetId);
|
|
30
|
+
console.log('------------------------');
|
|
31
|
+
},
|
|
32
|
+
onConnectSuccess: (userId) => {
|
|
33
|
+
console.log(`\n[连接成功] 当前登录用户: ${userId}`);
|
|
34
|
+
},
|
|
35
|
+
onError: (code) => {
|
|
36
|
+
console.error(`\n[连接失败] 错误码: ${code}`);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
try {
|
|
40
|
+
// 1. 连接
|
|
41
|
+
await client.connect();
|
|
42
|
+
// 2. 测试发送消息 (可选)
|
|
43
|
+
// 取消注释下方代码并替换目标 ID 进行测试
|
|
44
|
+
/*
|
|
45
|
+
const TARGET_ID = 'TARGET_USER_ID';
|
|
46
|
+
console.log(`\n正在向 ${TARGET_ID} 发送测试消息...`);
|
|
47
|
+
await client.sendMessage(TARGET_ID, 'Hello from Node.js!', 1);
|
|
48
|
+
console.log('发送成功!');
|
|
49
|
+
*/
|
|
50
|
+
// 3. 保持进程运行,等待接收消息
|
|
51
|
+
console.log('\n监听中... (按 Ctrl+C 退出)');
|
|
52
|
+
// 保持进程不退出
|
|
53
|
+
process.stdin.resume();
|
|
54
|
+
// 处理退出信号
|
|
55
|
+
process.on('SIGINT', () => {
|
|
56
|
+
console.log('\n退出测试');
|
|
57
|
+
process.exit(0);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
console.error('测试过程中发生错误:', error);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
main();
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Bridge 测试脚本 - 模拟模式
|
|
5
|
+
* 不需要 OpenClaw,使用预设回复测试
|
|
6
|
+
*/
|
|
7
|
+
const rongcloud_client_1 = require("./src/rongcloud-client");
|
|
8
|
+
const NODE_ID = 'claw_user_614681fad6643783_005';
|
|
9
|
+
const NODE_NAME = '龙虾5号';
|
|
10
|
+
const TOKEN = 'jtXLzSNYhJ99VW8rkgYhWzeqsV06TkPMobzk9RRWZiTddhpsulHcO8Ewjgz+JMidviQs+YylOg4=@3pvy.cn.rongnav.com;3pvy.cn.rongcfg.com';
|
|
11
|
+
const APP_KEY = 'bmdehs6pbyyks';
|
|
12
|
+
const MOCK_REPLIES = [
|
|
13
|
+
'收到!有什么我可以帮你的吗?',
|
|
14
|
+
'好的,我明白了。',
|
|
15
|
+
'这个问题很有趣,让我想想...',
|
|
16
|
+
'你好!我是龙虾AI助手,很高兴为你服务!',
|
|
17
|
+
'没问题,我可以帮你。',
|
|
18
|
+
];
|
|
19
|
+
async function main() {
|
|
20
|
+
console.log('[Bridge] ========== 模拟模式测试 ==========');
|
|
21
|
+
console.log(` 节点: ${NODE_ID} (${NODE_NAME})`);
|
|
22
|
+
console.log(' 模式: 模拟回复 (不需要 OpenClaw)');
|
|
23
|
+
const client = new rongcloud_client_1.RongCloudClient({
|
|
24
|
+
appKey: APP_KEY,
|
|
25
|
+
token: TOKEN,
|
|
26
|
+
onMessage: async (msg) => {
|
|
27
|
+
var _a;
|
|
28
|
+
const content = ((_a = msg.content) === null || _a === void 0 ? void 0 : _a.content) || '';
|
|
29
|
+
const fromUser = msg.senderUserId;
|
|
30
|
+
const targetId = msg.targetId;
|
|
31
|
+
const convType = msg.conversationType;
|
|
32
|
+
// 忽略离线消息
|
|
33
|
+
if (msg.isOffLineMessage) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
console.log(`\n[Bridge] ========== 新消息 ==========`);
|
|
37
|
+
console.log(` 发送者: ${fromUser}`);
|
|
38
|
+
console.log(` 类型: ${convType === 3 ? '群聊' : '私聊'}`);
|
|
39
|
+
console.log(` 内容: ${content}`);
|
|
40
|
+
if (msg.messageType !== 'RC:TxtMsg')
|
|
41
|
+
return;
|
|
42
|
+
if (fromUser === NODE_ID)
|
|
43
|
+
return;
|
|
44
|
+
const reply = MOCK_REPLIES[Math.floor(Math.random() * MOCK_REPLIES.length)];
|
|
45
|
+
console.log(`[Bridge] 模拟回复: ${reply}`);
|
|
46
|
+
const replyTarget = convType === 3 ? targetId : fromUser;
|
|
47
|
+
try {
|
|
48
|
+
await client.sendMessage(replyTarget, reply, convType);
|
|
49
|
+
console.log(`[Bridge] 已发送回复到: ${replyTarget}`);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
console.error(`[Bridge] 发送失败: ${err.message}`);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
onConnectSuccess: (userId) => {
|
|
56
|
+
console.log(`\n[Bridge] 连接成功! userId: ${userId}`);
|
|
57
|
+
console.log('[Bridge] 等待新消息... (在融云App中发送消息测试)\n');
|
|
58
|
+
},
|
|
59
|
+
onError: (code) => {
|
|
60
|
+
console.error(`[Bridge] 连接错误: ${code}`);
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
console.log('\n[Bridge] 正在连接融云...');
|
|
64
|
+
await client.connect();
|
|
65
|
+
console.log('\n[Bridge] 监听中... (Ctrl+C 退出)');
|
|
66
|
+
process.stdin.resume();
|
|
67
|
+
process.on('SIGINT', () => {
|
|
68
|
+
console.log('\n[Bridge] 退出');
|
|
69
|
+
process.exit(0);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "claw_messenger",
|
|
3
|
+
"name": "claw_messenger",
|
|
4
|
+
"description": "融云 IM 直连通道插件",
|
|
5
|
+
"version": "2.0.0",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": "https://github.com/your-org/claw_messenger",
|
|
9
|
+
"keywords": ["rongcloud", "im", "chat", "channel"],
|
|
10
|
+
"entry": "./dist/src/plugin-entry.js",
|
|
11
|
+
"configSchema": {
|
|
12
|
+
"appKey": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"label": "融云 AppKey",
|
|
15
|
+
"required": true
|
|
16
|
+
},
|
|
17
|
+
"token": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"label": "融云 Token",
|
|
20
|
+
"required": true,
|
|
21
|
+
"secret": true
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "claw_messenger",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "OpenClaw RongCloud Bridge - 融云直连桥接插件",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"claw_messenger": "./bin/install.js",
|
|
10
|
+
"rongcloud-bridge": "./bin/install.js",
|
|
11
|
+
"claw-bridge": "./bin/dm-bridge.js",
|
|
12
|
+
"claw-bridge-setup": "./bin/setup.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"bin",
|
|
16
|
+
"dist",
|
|
17
|
+
"openclaw.plugin.json",
|
|
18
|
+
"README.md",
|
|
19
|
+
"bridge-runner.ts"
|
|
20
|
+
],
|
|
21
|
+
"openclaw": {
|
|
22
|
+
"extensions": [
|
|
23
|
+
"./dist/src/plugin-entry.js"
|
|
24
|
+
],
|
|
25
|
+
"channel": {
|
|
26
|
+
"id": "claw_messenger",
|
|
27
|
+
"label": "claw_messenger",
|
|
28
|
+
"selectionLabel": "融云 IM",
|
|
29
|
+
"docsPath": "/channels/rongcloud",
|
|
30
|
+
"blurb": "RongCloud IM channel for OpenClaw",
|
|
31
|
+
"order": 80
|
|
32
|
+
},
|
|
33
|
+
"install": {
|
|
34
|
+
"npmSpec": "claw_messenger",
|
|
35
|
+
"defaultChoice": "npx",
|
|
36
|
+
"minHostVersion": ">=2026.3.24"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc",
|
|
41
|
+
"start": "node bin/claw-bridge.js",
|
|
42
|
+
"bridge": "ts-node bridge-runner.ts",
|
|
43
|
+
"test": "ts-node test-connection.ts",
|
|
44
|
+
"prepublishOnly": "npm run build",
|
|
45
|
+
"publish:patch": "npm version patch && npm publish",
|
|
46
|
+
"publish:minor": "npm version minor && npm publish",
|
|
47
|
+
"publish:major": "npm version major && npm publish"
|
|
48
|
+
},
|
|
49
|
+
"keywords": [
|
|
50
|
+
"openclaw",
|
|
51
|
+
"rongcloud",
|
|
52
|
+
"im",
|
|
53
|
+
"chat",
|
|
54
|
+
"bridge",
|
|
55
|
+
"ai"
|
|
56
|
+
],
|
|
57
|
+
"author": "",
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "https://github.com/your-org/claw_messenger.git"
|
|
62
|
+
},
|
|
63
|
+
"bugs": {
|
|
64
|
+
"url": "https://github.com/your-org/claw_messenger/issues"
|
|
65
|
+
},
|
|
66
|
+
"homepage": "https://github.com/your-org/claw_messenger#readme",
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"@rongcloud/engine": "^5.8.0",
|
|
69
|
+
"@rongcloud/imlib-next": "^5.8.0",
|
|
70
|
+
"axios": "^1.15.0",
|
|
71
|
+
"fake-indexeddb": "^6.2.5",
|
|
72
|
+
"jsdom": "^24.0.0",
|
|
73
|
+
"openclaw": "^2026.3.24",
|
|
74
|
+
"qrcode-terminal": "^0.12.0",
|
|
75
|
+
"ws": "^8.16.0"
|
|
76
|
+
},
|
|
77
|
+
"devDependencies": {
|
|
78
|
+
"@types/jsdom": "^21.1.6",
|
|
79
|
+
"@types/node": "^20.11.0",
|
|
80
|
+
"@types/qrcode-terminal": "^0.12.2",
|
|
81
|
+
"@types/ws": "^8.5.10",
|
|
82
|
+
"ts-node": "^10.9.2",
|
|
83
|
+
"typescript": "^5.3.3"
|
|
84
|
+
},
|
|
85
|
+
"engines": {
|
|
86
|
+
"node": ">=16.0.0"
|
|
87
|
+
}
|
|
88
|
+
}
|