@imweapp/openclaw-imwe 2026.4.12-alpha.1 → 2026.4.12-alpha.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 +20 -125
- package/package.json +2 -2
- package/src/send.ts +5 -4
package/README.md
CHANGED
|
@@ -2,73 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
imwe 即时通讯渠道插件,AppKey/AppSecret HMAC-SHA256 签名认证,支持多账号、私聊文字消息。
|
|
4
4
|
|
|
5
|
-
## 目录结构
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
extensions/imwe/
|
|
9
|
-
├── proto/ # Protobuf 消息定义(语言无关的契约文件)
|
|
10
|
-
│ ├── PbPacket.proto # 传输层:PbPacket / PbRequest / PbResponse
|
|
11
|
-
│ ├── PbChatDeliverMsg.proto # 投递层:PbChatMsgDeliverBody
|
|
12
|
-
│ ├── PbChatMsg.proto # 信封层:PbChatMsgEnvelope / PbMsgRspBody
|
|
13
|
-
│ ├── PbChatTextContent.proto # 内容层:PbChatTextContent / BodyRange
|
|
14
|
-
│ ├── PbSingleChatMsg.proto # 发送层:PbSingleChatMsgReqBody
|
|
15
|
-
│ └── PbBoxPullProto.proto # 事件箱:PbBoxPullReq / PbBoxPullRsp
|
|
16
|
-
├── index.ts # 插件主入口(defineChannelPluginEntry)
|
|
17
|
-
├── setup-entry.ts # 轻量入口(setup-only 模式)
|
|
18
|
-
├── package.json # npm 包配置
|
|
19
|
-
└── src/
|
|
20
|
-
├── proto/ # Protobuf 编解码层(TypeScript)
|
|
21
|
-
│ ├── codec.ts # encode/decode 统一导出入口
|
|
22
|
-
│ ├── registry.ts # protobufjs 类型注册表(单例)
|
|
23
|
-
│ ├── proto-types.ts # decode 结果的 TypeScript 接口(仅用于类型断言)
|
|
24
|
-
│ ├── inbound.codec.ts # 入站消息四层解包
|
|
25
|
-
│ └── send.codec.ts # 出站消息编码 + 发送响应解码
|
|
26
|
-
├── types.ts # 类型定义(三层:Config / ImweConfig / ResolvedAccount)
|
|
27
|
-
├── accounts.ts # 账号解析(listAccountIds / resolveImweAccount)
|
|
28
|
-
├── config-schema.ts # Zod 配置 schema
|
|
29
|
-
├── api-client.ts # HTTP API 客户端(签名 + protobuf 传输)
|
|
30
|
-
├── monitor.ts # 事件箱短轮询消息监听器
|
|
31
|
-
├── send.ts # 发送文字消息(outbound 适配器入口)
|
|
32
|
-
├── setup-core.ts # setup 适配器(openclaw setup imwe)
|
|
33
|
-
├── channel.ts # ChannelPlugin 主对象(组装所有适配器)
|
|
34
|
-
└── channel.runtime.ts # 运行时模块统一导出(懒加载目标)
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## 认证方式
|
|
38
|
-
|
|
39
|
-
每次 HTTP 请求携带以下签名头(对应文档 §1):
|
|
40
|
-
|
|
41
|
-
```
|
|
42
|
-
X-Api-Key: <appKey>
|
|
43
|
-
X-Timestamp: <毫秒时间戳>
|
|
44
|
-
X-Signature: Base64(HMAC-SHA256(appSecret, signString))
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
签名原文(signString):
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
{METHOD}&{PATH}&{TIMESTAMP}&{BODY_HASH}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
- `METHOD`:HTTP 方法大写,固定为 `POST`
|
|
54
|
-
- `PATH`:请求路径,如 `/api/im/open/bot/sendMessage`
|
|
55
|
-
- `TIMESTAMP`:与 `X-Timestamp` 相同的毫秒时间戳字符串
|
|
56
|
-
- `BODY_HASH`:`hex(SHA-256(body))`,body 为空时对空字符串 `""` 哈希
|
|
57
|
-
|
|
58
|
-
无需登录流程,无需持久化任何凭证,AppKey/AppSecret 写入 config 即可。
|
|
59
|
-
|
|
60
|
-
## 数据流
|
|
61
|
-
|
|
62
|
-
```
|
|
63
|
-
用户消息
|
|
64
|
-
→ imwe 平台
|
|
65
|
-
→ monitor.ts (long polling POST /messages/poll)
|
|
66
|
-
→ channelRuntime.reply.dispatchReply(...)
|
|
67
|
-
→ OpenClaw AI 推理
|
|
68
|
-
→ outbound.sendText(...)
|
|
69
|
-
→ api-client.sendTextMessage (POST /messages/send + HMAC 签名)
|
|
70
|
-
→ imwe 平台 → 用户
|
|
71
|
-
```
|
|
72
5
|
|
|
73
6
|
## 配置示例
|
|
74
7
|
|
|
@@ -81,7 +14,10 @@ X-Signature: Base64(HMAC-SHA256(appSecret, signString))
|
|
|
81
14
|
"apiBaseUrl": "https://api.imwe.example.com",
|
|
82
15
|
"appKey": "your-app-key",
|
|
83
16
|
"appSecret": "your-app-secret",
|
|
84
|
-
"dmPolicy": "
|
|
17
|
+
"dmPolicy": "open",
|
|
18
|
+
"allowFrom": [
|
|
19
|
+
"*"
|
|
20
|
+
],
|
|
85
21
|
}
|
|
86
22
|
}
|
|
87
23
|
}
|
|
@@ -94,18 +30,25 @@ X-Signature: Base64(HMAC-SHA256(appSecret, signString))
|
|
|
94
30
|
"channels": {
|
|
95
31
|
"imwe": {
|
|
96
32
|
"apiBaseUrl": "https://api.imwe.example.com",
|
|
97
|
-
"defaultAccount": "
|
|
33
|
+
"defaultAccount": "default",
|
|
98
34
|
"accounts": {
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"
|
|
35
|
+
"default": {
|
|
36
|
+
"apiBaseUrl": "https://api.imwe.example.com",
|
|
37
|
+
"appKey": "your-app-key",
|
|
38
|
+
"appSecret": "your-app-secret",
|
|
39
|
+
"dmPolicy": "open",
|
|
40
|
+
"allowFrom": [
|
|
41
|
+
"*"
|
|
42
|
+
],
|
|
103
43
|
},
|
|
104
44
|
"bot2": {
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
45
|
+
"apiBaseUrl": "https://api.imwe.example.com",
|
|
46
|
+
"appKey": "your-app-key",
|
|
47
|
+
"appSecret": "your-app-secret",
|
|
48
|
+
"dmPolicy": "open",
|
|
49
|
+
"allowFrom": [
|
|
50
|
+
"*"
|
|
51
|
+
],
|
|
109
52
|
}
|
|
110
53
|
}
|
|
111
54
|
}
|
|
@@ -121,52 +64,4 @@ IMWE_APP_KEY=your-app-key
|
|
|
121
64
|
IMWE_APP_SECRET=your-app-secret
|
|
122
65
|
```
|
|
123
66
|
|
|
124
|
-
## E2EE 端到端加密
|
|
125
|
-
|
|
126
|
-
单聊消息默认启用 E2EE(端到端加密),与 imwe iOS 客户端完全互通。无需额外配置,插件启动时自动完成密钥协商。
|
|
127
|
-
|
|
128
|
-
### 安全边界
|
|
129
|
-
|
|
130
|
-
- **加密范围**:单聊文本 / Markdown / 媒体消息的 `PbChatMsgEnvelope`(含 URL、caption、blurHash 等元数据)均经 E2EE 加密
|
|
131
|
-
- **不在加密范围内**:媒体文件正文(CDN 资源本身以明文上传/下载,仅信令层走 E2EE);typing signal 保持明文
|
|
132
|
-
- 加解密失败时消息**不会降级为明文**发送或投递
|
|
133
|
-
|
|
134
|
-
### 本地状态
|
|
135
|
-
|
|
136
|
-
首次启动时,插件会在以下路径创建 E2EE 状态目录:
|
|
137
|
-
|
|
138
|
-
```
|
|
139
|
-
~/.openclaw/channel-data/imwe/<accountId>/e2ee/
|
|
140
|
-
├── state.json # 密钥、session、PreKey 批次等持久化状态
|
|
141
|
-
├── state.json.tmp # 两阶段写临时文件
|
|
142
|
-
└── state.lock # proper-lockfile 进程锁
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
`state.json` 损坏时会自动重命名为 `state.json.corrupt-<timestamp>` 并重新 bootstrap。
|
|
146
|
-
|
|
147
|
-
### Mock Server(开发/测试)
|
|
148
|
-
|
|
149
|
-
项目提供了一个轻量 mock E2EE 服务端,用于本地开发与集成测试:
|
|
150
|
-
|
|
151
|
-
```bash
|
|
152
|
-
# 启动(默认端口 3456)
|
|
153
|
-
node tests/mock-server/server.js
|
|
154
|
-
|
|
155
|
-
# 自定义端口
|
|
156
|
-
PORT=4000 node tests/mock-server/server.js
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
mock server 覆盖 `getMe` / `pullMessages` / `sendMessage` + 5 个 E2EE 端点(create / replenish / apply / queryRequireNum / query),状态机行为详见 `tests/mock-server/README.md`。
|
|
160
|
-
|
|
161
|
-
在集成测试中可 programmatic 引入:
|
|
162
|
-
|
|
163
|
-
```js
|
|
164
|
-
import { server, PORT, resetState } from './tests/mock-server/server.js';
|
|
165
|
-
```
|
|
166
|
-
|
|
167
67
|
## 安装与配置
|
|
168
|
-
|
|
169
|
-
```bash
|
|
170
|
-
openclaw plugins install @openclaw/imwe
|
|
171
|
-
openclaw setup imwe --http-url https://api.imwe.example.com --token <appKey> --private-key <appSecret>
|
|
172
|
-
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imweapp/openclaw-imwe",
|
|
3
|
-
"version": "2026.4.12-alpha.
|
|
3
|
+
"version": "2026.4.12-alpha.2",
|
|
4
4
|
"description": "OpenClaw imwe 渠道插件 —— AppKey/AppSecret 签名认证,支持多账号、私聊文字消息",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"pluginApi": ">=2026.4.11"
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "a47db5b9829b4e94f68a7016f024164faa6e09ad"
|
|
73
73
|
}
|
package/src/send.ts
CHANGED
|
@@ -211,14 +211,15 @@ async function encryptAndSendWithRetry(
|
|
|
211
211
|
return await encryptAndSend(outbound, to, envelopeBytes, clientMsgId);
|
|
212
212
|
} catch (err) {
|
|
213
213
|
if (err instanceof DeviceNotMatchError && outbound.e2eeService) {
|
|
214
|
-
// DEVICE_NOT_MATCH 重试:handleDeviceNotMatch →
|
|
214
|
+
// DEVICE_NOT_MATCH 重试:handleDeviceNotMatch → 生成新 clientMsgId 重发一次
|
|
215
|
+
const retryClientMsgId = genClientMsgId();
|
|
215
216
|
outbound.log?.info?.(
|
|
216
|
-
`${prefix}: DEVICE_NOT_MATCH,执行单次重试, to=${to},
|
|
217
|
+
`${prefix}: DEVICE_NOT_MATCH,执行单次重试, to=${to}, oldClientMsgId=${clientMsgId}, newClientMsgId=${retryClientMsgId}, errData=${JSON.stringify(err.data)}`,
|
|
217
218
|
);
|
|
218
219
|
await outbound.e2eeService.handleDeviceNotMatch(err.data);
|
|
219
|
-
const result = await encryptAndSend(outbound, to, envelopeBytes,
|
|
220
|
+
const result = await encryptAndSend(outbound, to, envelopeBytes, retryClientMsgId);
|
|
220
221
|
outbound.log?.info?.(
|
|
221
|
-
`${prefix}: DEVICE_NOT_MATCH 重试成功, to=${to}, clientMsgId=${
|
|
222
|
+
`${prefix}: DEVICE_NOT_MATCH 重试成功, to=${to}, clientMsgId=${retryClientMsgId}`,
|
|
222
223
|
);
|
|
223
224
|
return result;
|
|
224
225
|
}
|