@rlynicrisis/link 0.0.5 → 0.0.6
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 +27 -0
- package/package.json +1 -1
- package/src/bot.ts +5 -0
- package/src/client-manager.ts +2 -1
- package/src/link/client.ts +17 -3
package/README.md
CHANGED
|
@@ -61,6 +61,33 @@ channels:
|
|
|
61
61
|
> - `deviceUID` 将根据机器特征自动生成,确保同一设备上的稳定性。
|
|
62
62
|
> - `host` 参数现已支持 `host:port` 格式,无需单独配置 `port`。
|
|
63
63
|
|
|
64
|
+
## 接入 OpenClaw
|
|
65
|
+
|
|
66
|
+
### 1. 安装插件
|
|
67
|
+
|
|
68
|
+
通过 OpenClaw CLI 安装本插件:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
openclaw plugins install @rlynicrisis/link
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 2. 配置频道
|
|
75
|
+
|
|
76
|
+
使用 OpenClaw CLI 的交互式引导添加频道配置:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
openclaw channels add
|
|
80
|
+
```
|
|
81
|
+
|
|
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 刷新请求。
|
|
88
|
+
|
|
89
|
+
配置完成后,OpenClaw 将自动连接并开始监听消息。
|
|
90
|
+
|
|
64
91
|
## 开发调试
|
|
65
92
|
|
|
66
93
|
### 单元测试
|
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -65,8 +65,11 @@ async function handleLinkMessage(params: {
|
|
|
65
65
|
const { cfg, msg, runtime, accountId, linkCfg } = params;
|
|
66
66
|
const core = getLinkRuntime();
|
|
67
67
|
|
|
68
|
+
console.log(`[LinkBot] Received message: type=${msg.type}, fromId=${msg.fromId}, toId=${msg.toId}`);
|
|
69
|
+
|
|
68
70
|
if (msg.type !== MsgType.TEXT) {
|
|
69
71
|
// Only support text for now
|
|
72
|
+
console.log(`[LinkBot] Ignoring non-text message: type=${msg.type}`);
|
|
70
73
|
return;
|
|
71
74
|
}
|
|
72
75
|
|
|
@@ -77,6 +80,8 @@ async function handleLinkMessage(params: {
|
|
|
77
80
|
const allowedUserId = linkCfg.verifyInfo?.userId;
|
|
78
81
|
const receiverId = msg.toId || "unknown";
|
|
79
82
|
|
|
83
|
+
console.log(`[LinkBot] allowedUserId=${allowedUserId}, senderId=${senderId}, receiverId=${receiverId}`);
|
|
84
|
+
|
|
80
85
|
if (!allowedUserId || senderId !== allowedUserId || receiverId !== allowedUserId) {
|
|
81
86
|
return;
|
|
82
87
|
}
|
package/src/client-manager.ts
CHANGED
|
@@ -31,7 +31,8 @@ export function createLinkClient(accountId: string, config: LinkConfig): LinkCli
|
|
|
31
31
|
accessToken: config.accessToken,
|
|
32
32
|
refreshToken: config.refreshToken,
|
|
33
33
|
ssoUrl: config.ssoUrl,
|
|
34
|
-
verifyInfo
|
|
34
|
+
// Pass verifyInfo reference from config so it can be updated in place by client
|
|
35
|
+
verifyInfo: config.verifyInfo || (config.verifyInfo = {}),
|
|
35
36
|
heartbeatIntervalMs: config.heartbeatIntervalMs
|
|
36
37
|
});
|
|
37
38
|
clients.set(accountId, client);
|
package/src/link/client.ts
CHANGED
|
@@ -121,10 +121,24 @@ export class LinkClient extends EventEmitter {
|
|
|
121
121
|
};
|
|
122
122
|
|
|
123
123
|
if (!this.config.verifyInfo) {
|
|
124
|
-
|
|
124
|
+
// Should not happen if initialized correctly in client-manager
|
|
125
|
+
// But if it is undefined, we can't update the config object passed in constructor if it's readonly
|
|
126
|
+
// However, this.config.verifyInfo is a reference.
|
|
127
|
+
// Let's cast to writable or ensure it is set.
|
|
128
|
+
// Actually, 'config' is readonly, but 'verifyInfo' property inside it is an object reference.
|
|
129
|
+
// If verifyInfo was undefined, we can't assign to it.
|
|
130
|
+
// We need to make sure verifyInfo is initialized in constructor or allow it to be mutable.
|
|
131
|
+
// The best way is to ensure client-manager passes an object reference.
|
|
132
|
+
// But if we are here and it is undefined (which it shouldn't be with the fix), we have a problem.
|
|
133
|
+
// Let's assume the fix in client-manager works.
|
|
134
|
+
// But wait, typescript readonly on config means we can't assign to config.verifyInfo if it's not there.
|
|
135
|
+
// We can assign to properties OF verifyInfo if verifyInfo exists.
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (this.config.verifyInfo) {
|
|
139
|
+
this.config.verifyInfo.userId = info.userId;
|
|
140
|
+
this.config.verifyInfo.deviceUID = info.deviceUID;
|
|
125
141
|
}
|
|
126
|
-
this.config.verifyInfo.userId = info.userId;
|
|
127
|
-
this.config.verifyInfo.deviceUID = info.deviceUID;
|
|
128
142
|
|
|
129
143
|
// Construct verify body JSON with correct key casing for V3
|
|
130
144
|
// Note: Java ClientVerifyUp uses PascalCase for keys in JSON!
|