openclaw-glance-plugin 0.1.0 → 0.1.2
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 +13 -6
- package/package.json +1 -1
- package/src/OpenClawBridgeClient.js +1 -1
- package/src/OpenClawPluginAdapter.js +24 -2
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@ OpenClaw 集成引导请看:[docs/openclaw-install-guide.md](./docs/openclaw-i
|
|
|
24
24
|
|
|
25
25
|
- 与 `openclaw-bridge` 建立 WebSocket 长连接
|
|
26
26
|
- 支持请求:`watch.create` / `watch.activate` / `watch.pause` / `watch.delete` / `ping`
|
|
27
|
+
- 支持渠道:`openclaw` / `email` / `call`
|
|
27
28
|
- 订阅推送:`watch.triggered`
|
|
28
29
|
- 自动重连 + 心跳
|
|
29
30
|
- 断线请求排队(可配置),重连后自动冲刷
|
|
@@ -44,7 +45,6 @@ npm test
|
|
|
44
45
|
## 运行示例
|
|
45
46
|
|
|
46
47
|
```bash
|
|
47
|
-
OPENCLAW_BRIDGE_WS_BASE=ws://glanceup-pre.100credit.cn \
|
|
48
48
|
OPENCLAW_WS_TOKEN=your_ws_token \
|
|
49
49
|
npm start
|
|
50
50
|
```
|
|
@@ -61,7 +61,7 @@ npm run start:adapter
|
|
|
61
61
|
import { OpenClawBridgeClient } from './src/index.js';
|
|
62
62
|
|
|
63
63
|
const client = new OpenClawBridgeClient({
|
|
64
|
-
baseWsUrl: '
|
|
64
|
+
baseWsUrl: 'wss://glanceup-pre.100credit.cn',
|
|
65
65
|
token: '<JWT_TOKEN>',
|
|
66
66
|
enqueueIfDisconnected: true
|
|
67
67
|
});
|
|
@@ -90,7 +90,7 @@ const res = await client.createWatch({
|
|
|
90
90
|
import { OpenClawPluginAdapter } from './src/index.js';
|
|
91
91
|
|
|
92
92
|
const adapter = new OpenClawPluginAdapter({
|
|
93
|
-
baseWsUrl: '
|
|
93
|
+
baseWsUrl: 'wss://glanceup-pre.100credit.cn',
|
|
94
94
|
token: '<JWT_TOKEN>'
|
|
95
95
|
});
|
|
96
96
|
|
|
@@ -100,8 +100,15 @@ await adapter.submitWatchDemand({
|
|
|
100
100
|
productType: 'hk_stock',
|
|
101
101
|
condition: 'price >= threshold',
|
|
102
102
|
variables: { threshold: 8.97 },
|
|
103
|
-
channels: ['openclaw'],
|
|
104
|
-
|
|
103
|
+
channels: ['openclaw', 'email', 'call'], // openclaw 必传,email/call 可选
|
|
104
|
+
emailConfig: {
|
|
105
|
+
to_address: 'demo@example.com',
|
|
106
|
+
template_id: 4
|
|
107
|
+
},
|
|
108
|
+
callConfig: {
|
|
109
|
+
phone: '13800138000',
|
|
110
|
+
customer_name: 'Demo'
|
|
111
|
+
}
|
|
105
112
|
});
|
|
106
113
|
```
|
|
107
114
|
|
|
@@ -118,5 +125,5 @@ await adapter.submitWatchDemand({
|
|
|
118
125
|
|
|
119
126
|
## 说明
|
|
120
127
|
|
|
121
|
-
- 先获取 ws `token`,然后连接 `
|
|
128
|
+
- 先获取 ws `token`,然后连接 `wss://<host>:8005/openclaw/ws`,并在握手 Header 传 `Authorization: Bearer <TOKEN>`。
|
|
122
129
|
- 发布时将导出 `src/` 与 `README.md`(见 `package.json` 的 `files/exports`)。
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import EventEmitter from 'node:events';
|
|
2
2
|
import WebSocket from 'ws';
|
|
3
3
|
|
|
4
|
-
const DEFAULT_BASE_WS_URL = '
|
|
4
|
+
const DEFAULT_BASE_WS_URL = 'wss://glanceup-pre.100credit.cn';
|
|
5
5
|
|
|
6
6
|
function sleep(ms) {
|
|
7
7
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -75,6 +75,28 @@ export class OpenClawPluginAdapter {
|
|
|
75
75
|
* 统一创建盯盘需求接口(适配 OpenClaw 侧参数)。
|
|
76
76
|
*/
|
|
77
77
|
async submitWatchDemand(demand) {
|
|
78
|
+
const channels = Array.isArray(demand.channels)
|
|
79
|
+
? demand.channels
|
|
80
|
+
.filter((x) => typeof x === 'string' && x.trim())
|
|
81
|
+
.map((x) => x.trim().toLowerCase())
|
|
82
|
+
: [];
|
|
83
|
+
const channelConfigs = { ...(demand.channelConfigs || {}) };
|
|
84
|
+
|
|
85
|
+
if (demand.openclawConfig) {
|
|
86
|
+
channelConfigs.openclaw = demand.openclawConfig;
|
|
87
|
+
if (!channels.includes('openclaw')) channels.push('openclaw');
|
|
88
|
+
}
|
|
89
|
+
if (demand.emailConfig) {
|
|
90
|
+
channelConfigs.email = demand.emailConfig;
|
|
91
|
+
if (!channels.includes('email')) channels.push('email');
|
|
92
|
+
}
|
|
93
|
+
if (demand.callConfig) {
|
|
94
|
+
channelConfigs.call = demand.callConfig;
|
|
95
|
+
if (!channels.includes('call')) channels.push('call');
|
|
96
|
+
}
|
|
97
|
+
if (!channels.includes('openclaw')) channels.unshift('openclaw');
|
|
98
|
+
if (!channelConfigs.openclaw) channelConfigs.openclaw = {};
|
|
99
|
+
|
|
78
100
|
const payload = {
|
|
79
101
|
product_code: demand.productCode,
|
|
80
102
|
product_type: demand.productType || 'stock',
|
|
@@ -84,8 +106,8 @@ export class OpenClawPluginAdapter {
|
|
|
84
106
|
variables: demand.variables || {},
|
|
85
107
|
message_template: demand.messageTemplate
|
|
86
108
|
},
|
|
87
|
-
channels
|
|
88
|
-
channel_configs:
|
|
109
|
+
channels,
|
|
110
|
+
channel_configs: channelConfigs
|
|
89
111
|
};
|
|
90
112
|
return this.client.createWatch(payload);
|
|
91
113
|
}
|