Repository navigation
Expand file tree
/
Copy pathtest_ws.js
More file actions
76 lines (62 loc) · 2.4 KB
/
Copy pathtest_ws.js
File metadata and controls
76 lines (62 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const WebSocket = require('ws');
const PIPELINE = '48963ec3-5f45-4078-a81e-ce0c569566fd';
const URL = `wss://langbot-test.rockchin.top/api/v1/pipelines/${PIPELINE}/ws/connect?session_type=group`;
console.log(`Connecting to ${URL}`);
const ws = new WebSocket(URL, { headers: { Origin: 'https://langbot-test.rockchin.top' } });
ws.on('open', () => console.log('Connected!'));
ws.on('error', e => console.error('Error:', e.message));
ws.on('close', (c, r) => console.log(`Closed: ${c} ${r}`));
ws.on('message', data => {
const msg = JSON.parse(data.toString());
console.log('[RECV]', JSON.stringify(msg, null, 2).substring(0, 800));
});
// Helper: build a Plain text message chain
function textMsg(text) {
return {
type: 'message',
message: [{ type: 'Plain', text }],
};
}
const msgs = [
'大家好,今天的会议几点开始?',
'下午3点,讨论新版本的发布计划',
'好的,我准备了性能测试报告',
'Bob那边CI/CD流程改好了吗',
'改好了,现在自动部署到staging了',
'我觉得我们应该先修复那个内存泄漏的问题',
'同意,内存泄漏在高并发下会导致OOM',
'那就优先级调高,这个版本必须修',
'我来负责修这个,预计需要两天',
'我可以帮忙review代码',
];
async function run() {
// Wait for connected
await new Promise(r => {
const handler = (data) => {
const msg = JSON.parse(data.toString());
if (msg.type === 'connected') { ws.removeListener('message', handler); r(); }
};
ws.on('message', handler);
});
console.log('\n--- Sending 10 group messages ---');
for (const text of msgs) {
ws.send(JSON.stringify(textMsg(text)));
console.log(`[SENT] ${text}`);
await new Promise(r => setTimeout(r, 1000));
}
console.log('\n--- Waiting 3s then sending !summary ---');
await new Promise(r => setTimeout(r, 3000));
ws.send(JSON.stringify(textMsg('!summary')));
console.log('[SENT] !summary');
// Wait for bot response
console.log('--- Waiting 30s for response ---');
await new Promise(r => setTimeout(r, 30000));
console.log('\n--- Sending NL summary request ---');
ws.send(JSON.stringify(textMsg('请帮我总结一下群聊内容')));
console.log('[SENT] 请帮我总结一下群聊内容');
console.log('--- Waiting 30s for response ---');
await new Promise(r => setTimeout(r, 30000));
console.log('\nDone.');
ws.close();
}
ws.on('open', run);