@rlynicrisis/link 0.1.1 → 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 CHANGED
@@ -7,13 +7,25 @@
7
7
  - **协议支持**: 基于 TCP 的私有协议 (EMB Protocol V3),支持 Protobuf 消息序列化。
8
8
  - **消息类型**:
9
9
  - ✅ 文本消息 (Text)
10
- - ✅ 文件消息 (File) - *需配合文件上传服务使用*
11
- - **安全机制**:
12
- - 🔒 **仅限己方消息**: 插件默认仅处理当前登录用户发送给自己的消息(即“文件传输助手”模式),忽略群聊和其他用户的私聊,确保数据安全。
10
+ - **接入模式**:
11
+ - 📁 **FileHelper 模式(默认)**: 仅处理当前登录用户发送给自己的消息,忽略群聊和其他私聊,确保数据安全。
12
+ - 👥 **群组模式**: 配置 `groupId` 后监听指定群的消息,由群机器人 Webhook(HTTP POST)回复。
13
13
  - **连接管理**:
14
14
  - 💓 自动心跳保活
15
15
  - 🔄 断线自动重连
16
- - 🎫 **Token 自动刷新**: 支持配置 `refreshToken` 和 `ssoUrl`,在 Token 过期时自动通过 SSO 接口刷新并重连。
16
+ - 🎫 **Token 自动刷新**: 支持配置 `refreshToken`,在 Token 过期时自动通过 SSO 接口刷新并重连。
17
+
18
+ ## 默认值
19
+
20
+ 以下字段均有默认值,可以省略不填:
21
+
22
+ | 字段 | 默认值 |
23
+ |------|--------|
24
+ | `host` | `embtcp.bingolink.biz:20081` |
25
+ | `ssoUrl` | `https://www.bingolink.biz:443/sso` |
26
+ | `notificationApiUrl` | `https://notificationapi.bingolink.biz:443/notificationapi` |
27
+
28
+ **必填字段只有 `accessToken`**(群组模式还需额外填写 `groupId` 和 `botToken`)。
17
29
 
18
30
  ## 安装与配置
19
31
 
@@ -32,68 +44,65 @@ npm run build
32
44
 
33
45
  在您的 OpenClaw 主配置文件(通常是 `config.yaml` 或 `config.json`)中,添加以下内容:
34
46
 
35
- #### 频道配置 (Channel Config)
36
-
37
- 在 `channels` 部分添加 `link` 配置:
47
+ #### 最简配置(FileHelper 模式)
38
48
 
39
49
  ```yaml
40
50
  channels:
41
51
  link:
42
- enabled: true
43
- # Link 服务地址 (格式: host:port)
44
- host: "embtcpbeta.bingolink.biz:20081"
45
-
46
- # 鉴权信息 (必填)
52
+ # 必填:鉴权 Token
47
53
  accessToken: "your_access_token_here"
48
-
49
- # Token 自动刷新配置 (可选,推荐配置)
50
- refreshToken: "your_refresh_token_here"
51
- ssoUrl: "https://sso.example.com" # SSO 服务地址
52
-
53
- # 高级配置 (可选)
54
- # heartbeatIntervalMs: 30000 # 心跳间隔,默认 30秒
55
- # verifyInfo: # 如果需要覆盖默认生成的设备信息,可在此配置
56
- # deviceName: "CustomBotName"
54
+
55
+ # 以下均可省略,使用默认值:
56
+ # host: "embtcp.bingolink.biz:20081"
57
+ # ssoUrl: "https://www.bingolink.biz:443/sso"
58
+
59
+ # Token 自动刷新(可选,推荐配置)
60
+ # refreshToken: "your_refresh_token_here"
61
+ ```
62
+
63
+ #### 完整配置参考
64
+
65
+ ```yaml
66
+ channels:
67
+ link:
68
+ host: "embtcp.bingolink.biz:20081" # 消息服务地址,可省略
69
+ accessToken: "your_access_token_here" # 必填
70
+ refreshToken: "your_refresh_token_here" # 可选,用于 Token 自动刷新
71
+ ssoUrl: "https://www.bingolink.biz:443/sso" # 可省略,刷新 Token 时使用
72
+ heartbeatIntervalMs: 30000 # 心跳间隔,默认 30 秒
57
73
  ```
58
74
 
59
75
  > **注意**:
60
76
  > - `userId` 将自动从 `accessToken` (JWT) 中解析。
61
- > - `deviceUID` 将根据机器特征自动生成,确保同一设备上的稳定性。
62
- > - `host` 参数现已支持 `host:port` 格式,无需单独配置 `port`。
77
+ > - `deviceUID` 将根据机器特征自动生成。
78
+ > - `host` 支持 `host:port` 格式,默认端口 `20081`。
63
79
 
64
80
  ## 接入 OpenClaw
65
81
 
66
82
  ### 1. 安装插件
67
83
 
68
- 通过 OpenClaw CLI 安装本插件:
69
-
70
84
  ```bash
71
85
  openclaw plugins install @rlynicrisis/link
72
86
  ```
73
87
 
74
88
  ### 2. 配置频道
75
89
 
76
- 使用 OpenClaw CLI 的交互式引导添加频道配置:
77
-
78
90
  ```bash
79
91
  openclaw channels add
80
92
  ```
81
93
 
82
- 在引导过程中选择 **Link**,并按照提示输入以下信息:
83
-
84
- 1. **Link Server Host**: 输入消息服务地址(例如 `embtcpbeta.bingolink.biz:20081`)。
85
- 2. **User Access Token**: 输入初始的 Access Token。
86
- 3. **Refresh Token** (可选): 输入 Refresh Token,用于 Token 自动刷新。
87
- 4. **SSO URL** (可选): 输入 SSO 认证服务地址(例如 `https://sso.example.com`),用于 Token 刷新请求。
94
+ 在引导过程中选择 **Link**,按提示输入:
88
95
 
89
- 配置完成后,OpenClaw 将自动连接并开始监听消息。
96
+ 1. **User Access Token**(必填)
97
+ 2. **Refresh Token**(可选,推荐填写,用于 Token 自动刷新)
98
+ 3. 其余字段均有默认值,直接回车跳过即可
90
99
 
91
100
  ### 3. 获取 Token 示例
92
101
 
93
- 您可以使用以下命令通过账号密码获取初始的 Access Token 和 Refresh Token:
102
+ 通过账号密码获取 Access Token 和 Refresh Token:
94
103
 
95
104
  ```bash
96
- curl --location --request POST 'https://www.bingolink.biz/sso/oauth2/token' \
105
+ curl --location --request POST 'https://www.bingolink.biz:443/sso/oauth2/token' \
97
106
  --header 'Authorization: Basic Y2xpZW50SWQ6Y2xpZW50U2VjcmV0' \
98
107
  --header 'Content-Type: application/x-www-form-urlencoded' \
99
108
  --data-urlencode 'grant_type=password' \
@@ -101,121 +110,114 @@ curl --location --request POST 'https://www.bingolink.biz/sso/oauth2/token' \
101
110
  --data-urlencode 'password=个人密码'
102
111
  ```
103
112
 
104
- > **提示**: 请将 `username` 和 `password` 替换为您的实际账号信息。响应结果将包含 `access_token` 和 `refresh_token`。
113
+ 响应结果中的 `access_token` 和 `refresh_token` 即为所需的 Token。
114
+
115
+ ## 群组接入模式
116
+
117
+ 在 FileHelper 模式之外,插件还支持监听指定群的消息,并通过**群机器人 Webhook** 回复。
118
+
119
+ ### 工作原理
105
120
 
106
- ## 多账号支持 (Multi-Account Support)
121
+ - **接收**:建立 TCP 长连接,过滤出发往 `groupId` 的群消息,触发 OpenClaw 的 Agent 处理流程。
122
+ - **发送**:Agent 回复内容通过 HTTP POST 发送到群机器人 Webhook 地址,而非 TCP 自发自收。
123
+
124
+ ### 配置示例
125
+
126
+ ```yaml
127
+ channels:
128
+ link:
129
+ accounts:
130
+ mygroup:
131
+ accessToken: "your_access_token_here"
132
+ refreshToken: "your_refresh_token_here" # 可选
133
+
134
+ # 群组接入配置
135
+ groupId: "3ab33646-3a55-46fd-97ba-868d4bf29915" # 要监听的群 ID
136
+ botToken: "xxxxxxxxxxxxxxxx" # 群机器人 Webhook Token
137
+
138
+ # notificationApiUrl 可省略,默认:
139
+ # https://notificationapi.bingolink.biz:443/notificationapi
140
+
141
+ bindings:
142
+ - agentId: "group-agent"
143
+ match:
144
+ channel: "link"
145
+ accountId: "mygroup"
146
+ ```
147
+
148
+ ### 配置字段说明
149
+
150
+ | 字段 | 必填 | 说明 |
151
+ |------|------|------|
152
+ | `groupId` | 群组模式必填 | 要监听的群 ID |
153
+ | `botToken` | 群组模式必填 | 群机器人 Webhook Token |
154
+ | `notificationApiUrl` | 可省略 | Webhook 服务基础地址,默认 `https://notificationapi.bingolink.biz:443/notificationapi` |
155
+
156
+ > **说明**:`groupId` + `botToken` 同时存在时自动启用群组模式,否则退回到 FileHelper 模式。
157
+
158
+ ## 多账号支持
107
159
 
108
160
  插件支持在同一个 OpenClaw 实例中同时连接多个 Link 账号,每个账号独立维护连接和消息路由。
109
161
 
110
162
  ### 配置格式
111
163
 
112
- 在 `channels.link` 下添加 `accounts` 字段,以账号 ID 为键,每个账号独立配置:
113
-
114
164
  ```yaml
115
165
  channels:
116
166
  link:
117
167
  accounts:
168
+ # FileHelper 账号(最简配置)
118
169
  default:
119
- host: "embtcp.bingolink.biz:20081"
120
170
  accessToken: "token_for_default_account"
121
171
  refreshToken: "refresh_token_for_default"
122
- ssoUrl: "https://www.bingolink.biz/sso"
123
- work:
124
- host: "embtcp.bingolink.biz:20081"
125
- accessToken: "token_for_work_account"
126
- refreshToken: "refresh_token_for_work"
127
- ssoUrl: "https://www.bingolink.biz/sso"
128
- ```
129
-
130
- ### 绑定配置
131
172
 
132
- 使用 `bindings` 将不同账号路由到不同的 Agent:
173
+ # 群组账号
174
+ mygroup:
175
+ accessToken: "token_for_group_account"
176
+ groupId: "3ab33646-3a55-46fd-97ba-868d4bf29915"
177
+ botToken: "xxxxxxxxxxxxxxxx"
133
178
 
134
- ```yaml
135
179
  bindings:
136
180
  - agentId: "main"
137
181
  match:
138
182
  channel: "link"
139
183
  accountId: "default"
140
- - agentId: "work-agent"
184
+ - agentId: "group-agent"
141
185
  match:
142
186
  channel: "link"
143
- accountId: "work"
187
+ accountId: "mygroup"
144
188
  ```
145
189
 
146
- ### JSON 格式示例
147
-
148
- ```json
149
- {
150
- "channels": {
151
- "link": {
152
- "accounts": {
153
- "default": {
154
- "host": "embtcp.bingolink.biz:20081",
155
- "accessToken": "xxx",
156
- "refreshToken": "xxx",
157
- "ssoUrl": "https://www.bingolink.biz/sso"
158
- },
159
- "work": {
160
- "host": "embtcp.bingolink.biz:20081",
161
- "accessToken": "yyy",
162
- "refreshToken": "yyy",
163
- "ssoUrl": "https://www.bingolink.biz/sso"
164
- }
165
- }
166
- }
167
- },
168
- "bindings": [
169
- { "agentId": "main", "match": { "channel": "link", "accountId": "default" } },
170
- { "agentId": "work-agent", "match": { "channel": "link", "accountId": "work" } }
171
- ]
172
- }
173
- ```
174
-
175
- ### 向后兼容 (Backward Compatibility)
190
+ ### 向后兼容
176
191
 
177
- **无需修改现有配置**。如果没有 `accounts` 字段,插件会将根级别的 `host`、`accessToken` 等字段视为 `accountId = "default"` 的账号,行为与之前完全一致:
192
+ **无需修改现有配置**。如果没有 `accounts` 字段,插件会将根级别的字段视为 `accountId = "default"` 的账号:
178
193
 
179
194
  ```yaml
180
195
  # 旧配置格式,继续有效
181
196
  channels:
182
197
  link:
183
- host: "embtcp.bingolink.biz:20081"
184
198
  accessToken: "your_token"
185
199
  refreshToken: "your_refresh_token"
186
- ssoUrl: "https://www.bingolink.biz/sso"
187
200
  ```
188
201
 
189
- > **注意**: `accounts` 字段与根级别的 `host`/`accessToken` 互斥。当 `accounts` 存在时,根级别字段会被忽略。
202
+ > `accounts` 字段与根级别的 `accessToken` 互斥。当 `accounts` 存在时,根级别字段会被忽略。
190
203
 
191
204
  ## 开发调试
192
205
 
193
206
  ### 单元测试
194
207
 
195
- 运行所有单元测试:
196
-
197
208
  ```bash
198
209
  npm test
199
210
  ```
200
211
 
201
212
  ### 手动连接测试
202
213
 
203
- 可以使用 `test/manual-connect.ts` 脚本单独测试连接和基本消息收发:
204
-
205
214
  ```bash
206
215
  npx tsx test/manual-connect.ts
207
216
  ```
208
217
 
209
- ### 发送文件消息测试
210
-
211
- 测试发送文件类型消息(构造虚拟文件信息):
212
-
213
- ```bash
214
- npx tsx test/send-file.ts
215
- ```
216
-
217
218
  ## 常见问题
218
219
 
219
- - **消息发送失败 (Protobuf Error)**: 确保服务端支持 V3 协议,且 `MsgType` 枚举值与服务端定义一致(如 File=3)。
220
- - **Token 过期**: 如果配置了 `refreshToken` 和 `ssoUrl`,插件会自动尝试刷新。否则需手动更新配置文件中的 `accessToken`。
221
- - **无法收到消息**: 检查 `bot.ts` 中的安全过滤逻辑,确保发送者和接收者均为当前登录用户。
220
+ - **Token 过期**: 配置了 `refreshToken` 后,插件会在收到服务端刷新信号时自动续期。否则需手动更新 `accessToken`。
221
+ - **收不到群消息**: 确认 `groupId` 和 `botToken` 均已配置,且 `groupId` 与实际群 ID 一致。
222
+ - **Webhook 调用失败**: 检查 `notificationApiUrl` 是否可访问,以及 `botToken` 是否有效。
223
+ - **FileHelper 模式收不到消息**: 发送者和接收者必须均为当前登录用户自身(自发自收)。
@@ -8,12 +8,12 @@
8
8
  "type": "object",
9
9
  "additionalProperties": false,
10
10
  "properties": {
11
- "host": { "type": "string", "description": "Link Server Host", "default": "embtcp.bingolink.biz:20081" },
12
- "ssoUrl": { "type": "string", "description": "SSO URL for refreshing token", "default": "https://www.bingolink.biz:443/sso" },
13
11
  "accessToken": { "type": "string", "description": "User Access Token" },
14
12
  "refreshToken": { "type": "string", "description": "User Refresh Token (Optional)" },
15
13
  "groupId": { "type": "string", "description": "Group ID to monitor (enables group bot mode)" },
16
14
  "botToken": { "type": "string", "description": "Group bot webhook token" },
15
+ "host": { "type": "string", "description": "Link Server Host", "default": "embtcp.bingolink.biz:20081" },
16
+ "ssoUrl": { "type": "string", "description": "SSO URL for refreshing token", "default": "https://www.bingolink.biz:443/sso" },
17
17
  "notificationApiUrl": { "type": "string", "description": "Webhook base URL", "default": "https://notificationapi.bingolink.biz:443/notificationapi" },
18
18
  "accounts": {
19
19
  "type": "object",
@@ -23,12 +23,12 @@
23
23
  "additionalProperties": false,
24
24
  "required": ["accessToken"],
25
25
  "properties": {
26
- "host": { "type": "string", "description": "Link Server Host", "default": "embtcp.bingolink.biz:20081" },
27
26
  "accessToken": { "type": "string", "description": "User Access Token" },
28
27
  "refreshToken": { "type": "string", "description": "User Refresh Token (Optional)" },
29
- "ssoUrl": { "type": "string", "description": "SSO URL for refreshing token", "default": "https://www.bingolink.biz:443/sso" },
30
28
  "groupId": { "type": "string", "description": "Group ID to monitor (enables group bot mode)" },
31
29
  "botToken": { "type": "string", "description": "Group bot webhook token" },
30
+ "host": { "type": "string", "description": "Link Server Host", "default": "embtcp.bingolink.biz:20081" },
31
+ "ssoUrl": { "type": "string", "description": "SSO URL for refreshing token", "default": "https://www.bingolink.biz:443/sso" },
32
32
  "notificationApiUrl": { "type": "string", "description": "Webhook base URL", "default": "https://notificationapi.bingolink.biz:443/notificationapi" }
33
33
  }
34
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rlynicrisis/link",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "description": "OpenClaw Link channel plugin",
6
6
  "files": [