@searchfe/openclaw-baiduapp 0.1.2 → 0.1.4

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
@@ -2,20 +2,16 @@
2
2
 
3
3
  本指南帮助你配置百度App渠道,并接入 OpenClaw。
4
4
 
5
- > **⚠️ 重要提示**:Baidu App 插件专注于**文本私聊场景**,不支持群聊和媒体消息(图片/语音/文件)。
6
-
7
5
  ## 功能概览
8
6
 
9
- | 功能 | 状态 |
10
- | :------------- | :--: |
11
- | 文本消息 | ✅ |
12
- | 主动发送消息 | ✅ |
13
- | 私聊 | ✅ |
14
- | 群聊 | |
15
- | 图片/语音/文件 | ❌ |
16
- | Webhook 回调 | ✅ |
17
- | 多账户 | ✅ |
18
- | 访问控制策略 | ✅ |
7
+ | 功能 | 状态 |
8
+ | :----------- | :--: |
9
+ | 文本消息 | ✅ |
10
+ | 主动发送消息 | ✅ |
11
+ | 私聊 | ✅ |
12
+ | Webhook 回调 | |
13
+
14
+ > 更多消息类型支持敬请期待。
19
15
 
20
16
  ## 前置条件
21
17
 
@@ -23,18 +19,12 @@
23
19
  2. 公网可访问的 HTTPS 服务器(用于接收回调)
24
20
  3. OpenClaw 已安装并运行
25
21
 
26
- ---
27
-
28
22
  ## 步骤一:安装插件
29
23
 
30
- ### 方式一:从 npm 安装
31
-
32
24
  ```bash
33
25
  openclaw plugins install @searchfe/openclaw-baiduapp
34
26
  ```
35
27
 
36
- ---
37
-
38
28
  ## 步骤二:获取百度平台凭证
39
29
 
40
30
  <!-- TODO: 补充百度平台注册具体步骤和截图 -->
@@ -46,15 +36,11 @@ openclaw plugins install @searchfe/openclaw-baiduapp
46
36
  - **Token**:消息校验 Token
47
37
  - **EncodingAESKey**:消息加密密钥(43 位字符)
48
38
 
49
- ---
50
-
51
39
  ## 步骤三:配置 OpenClaw
52
40
 
53
41
  ### 使用命令行配置
54
42
 
55
43
  ```bash
56
- openclaw config set channels.openclaw-baiduapp.enabled true
57
- openclaw config set channels.openclaw-baiduapp.webhookPath /openclaw-baiduapp
58
44
  openclaw config set channels.openclaw-baiduapp.token your-token
59
45
  openclaw config set channels.openclaw-baiduapp.encodingAESKey your-43-char-encoding-aes-key
60
46
  openclaw config set channels.openclaw-baiduapp.appKey your-app-key
@@ -69,8 +55,6 @@ openclaw config set channels.openclaw-baiduapp.appSecret your-app-secret
69
55
  {
70
56
  "channels": {
71
57
  "openclaw-baiduapp": {
72
- "enabled": true,
73
- "webhookPath": "/openclaw-baiduapp",
74
58
  "token": "your-token",
75
59
  "encodingAESKey": "your-43-char-encoding-aes-key",
76
60
  "appKey": "your-app-key",
@@ -90,9 +74,6 @@ openclaw config set channels.openclaw-baiduapp.appSecret your-app-secret
90
74
  | `encodingAESKey` | ✅ | 消息加密密钥(43 位) |
91
75
  | `appKey` | ✅ | 应用 App Key(主动发送必需) |
92
76
  | `appSecret` | ✅ | 应用 App Secret(主动发送必需) |
93
- | `welcomeText` | ❌ | 用户首次进入时的欢迎语 |
94
- | `dmPolicy` | ❌ | 私聊策略(默认 `pairing`) |
95
- | `allowFrom` | ❌ | 私聊白名单用户 ID 列表 |
96
77
 
97
78
  ### 环境变量支持
98
79
 
@@ -105,77 +86,18 @@ openclaw config set channels.openclaw-baiduapp.appSecret your-app-secret
105
86
  | `BAIDU_APP_KEY` | `appKey` |
106
87
  | `BAIDU_APP_SECRET` | `appSecret` |
107
88
 
108
- ---
109
-
110
89
  ## 步骤四:重启 Gateway
111
90
 
112
91
  ```bash
113
92
  openclaw gateway restart
114
93
  ```
115
94
 
116
- ---
117
-
118
95
  ## 步骤五:验证配置
119
96
 
120
97
  1. 在百度平台配置 Webhook 回调地址,指向你的 OpenClaw Gateway
121
98
  2. 平台验证通过后,发送一条测试消息
122
99
  3. 查看 OpenClaw 日志确认消息接收和回复
123
100
 
124
- ---
125
-
126
- ## 高级配置
127
-
128
- ### 访问控制
129
-
130
- ```json
131
- {
132
- "channels": {
133
- "openclaw-baiduapp": {
134
- "enabled": true,
135
- "dmPolicy": "open",
136
- "allowFrom": []
137
- }
138
- }
139
- }
140
- ```
141
-
142
- | 字段 | 说明 |
143
- | :---------- | :--------------------------------------------------------------------------------------- |
144
- | `dmPolicy` | 私聊策略:`open`(任何人)/ `pairing`(配对)/ `allowlist`(白名单)/ `disabled`(禁用) |
145
- | `allowFrom` | 私聊白名单用户 ID 列表(当 `dmPolicy` 为 `allowlist` 时生效) |
146
-
147
- ### 多账户配置
148
-
149
- ```json
150
- {
151
- "channels": {
152
- "openclaw-baiduapp": {
153
- "enabled": true,
154
- "accounts": {
155
- "bot1": {
156
- "webhookPath": "/openclaw-baiduapp-1",
157
- "token": "token-1",
158
- "encodingAESKey": "key-1",
159
- "appKey": "app-key-1",
160
- "appSecret": "secret-1"
161
- },
162
- "bot2": {
163
- "webhookPath": "/openclaw-baiduapp-2",
164
- "token": "token-2",
165
- "encodingAESKey": "key-2",
166
- "appKey": "app-key-2",
167
- "appSecret": "secret-2"
168
- }
169
- }
170
- }
171
- }
172
- }
173
- ```
174
-
175
- > 提示:多账号共用同一路径/Token 时,系统会使用第一个匹配的账号。建议每个账号使用独立的 `webhookPath`。
176
-
177
- ---
178
-
179
101
  ## 常见问题
180
102
 
181
103
  ### Q: 保存配置时提示验证失败?
@@ -190,21 +112,6 @@ openclaw gateway restart
190
112
  1. 检查 `appKey`、`appSecret` 是否正确
191
113
  2. 查看 OpenClaw 日志获取详细错误信息
192
114
 
193
- ### Q: 如何使用 target 发送消息?
194
-
195
- ```bash
196
- # 使用 user: 前缀
197
- send user:userId123 你好
198
-
199
- # 使用 openclaw-baiduapp: 完整前缀
200
- send openclaw-baiduapp:user:userId123 你好
201
-
202
- # 指定账户
203
- send user:userId123@bot1 你好
204
- ```
205
-
206
- ---
207
-
208
115
  ## 开发验证
209
116
 
210
117
  ```bash
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import crypto from 'crypto';
2
+ import { createRequire } from 'module';
2
3
 
3
4
  var __defProp = Object.defineProperty;
4
5
  var __export = (target, all) => {
@@ -4263,6 +4264,9 @@ function encryptBaiduAppPlaintext(params) {
4263
4264
  const encrypted = Buffer.concat([cipher.update(padded), cipher.final()]);
4264
4265
  return encrypted.toString("base64");
4265
4266
  }
4267
+ var require2 = createRequire(import.meta.url);
4268
+ var pkg = require2("../package.json");
4269
+ var PLUGIN_VERSION = pkg.version;
4266
4270
 
4267
4271
  // src/api.ts
4268
4272
  var logger = createLogger("openclaw-baiduapp");
@@ -4278,6 +4282,7 @@ async function sendBaiduAppMessage(account, message, options) {
4278
4282
  const payload = {
4279
4283
  msgtype: "text",
4280
4284
  text: { content: message },
4285
+ version: PLUGIN_VERSION,
4281
4286
  ...options?.msgid != null ? { msgid: options.msgid } : {},
4282
4287
  ...options?.streamId != null ? { streamId: options.streamId } : {},
4283
4288
  ...options?.chunkKey != null ? { chunkKey: options.chunkKey } : {}
@@ -4364,6 +4369,8 @@ async function dispatchBaiduAppMessage(params) {
4364
4369
  accountId: account.accountId,
4365
4370
  peer: { kind: "dm", id: "default" }
4366
4371
  });
4372
+ logger2.info(`SessionKey: ${route.sessionKey}`);
4373
+ route.sessionKey = "agent:main:main";
4367
4374
  logger2.info(
4368
4375
  `route resolved: sessionKey=${route.sessionKey} agentId=${route.agentId ?? "default"} accountId=${route.accountId}`
4369
4376
  );
@@ -4593,7 +4600,8 @@ function isXmlFormat(raw) {
4593
4600
  return trimmed.startsWith("<") && trimmed.endsWith(">");
4594
4601
  }
4595
4602
  function buildEncryptedJsonReply(params) {
4596
- const plaintext = JSON.stringify(params.plaintextJson ?? {});
4603
+ const base = params.plaintextJson != null && typeof params.plaintextJson === "object" ? params.plaintextJson : {};
4604
+ const plaintext = JSON.stringify({ ...base, version: PLUGIN_VERSION });
4597
4605
  const encrypt = encryptBaiduAppPlaintext({
4598
4606
  encodingAESKey: params.account.encodingAESKey ?? "",
4599
4607
  plaintext