@zhin.js/adapter-weixin-ilink 1.1.25 → 1.1.27
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/CHANGELOG.md +80 -0
- package/LICENSE +21 -0
- package/README.md +7 -1
- package/lib/client.js +36 -1
- package/lib/console-spec.js +12 -1
- package/lib/ilink-redact.d.ts +0 -5
- package/lib/ilink-redact.js +0 -12
- package/lib/ilink-types.d.ts +0 -5
- package/lib/ilink-types.js +0 -5
- package/lib/weixin-inbound.d.ts +1 -22
- package/lib/weixin-inbound.js +0 -41
- package/package.json +15 -14
- package/schema.json +0 -56
- package/src/client.ts +32 -1
- package/src/console-spec.ts +12 -1
- package/src/ilink-redact.ts +0 -11
- package/src/ilink-types.ts +0 -6
- package/src/weixin-inbound.ts +1 -65
- package/lib/types.d.ts +0 -2
- package/lib/types.js +0 -1
- package/src/types.ts +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,85 @@
|
|
|
1
1
|
# @zhin.js/adapter-weixin-ilink
|
|
2
2
|
|
|
3
|
+
## 1.1.27
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e1fda87: fix: 按审计待审清单处理(安全、功能、清理)
|
|
8
|
+
|
|
9
|
+
**行为变更(升级前请阅读)**
|
|
10
|
+
|
|
11
|
+
- kernel / core / zhin.js:出站文本中的 `${…}` 不再用 `vm` 求值,只替换 `TemplateContext` 上能解析到值的属性路径(如 `${sender.name}`);表达式、函数调用、未知名字原样保留。整套 vm 沙箱(`evaluate` / `execute` / `compiler` / `getValueWithRuntime`)已移除。
|
|
12
|
+
- kernel / core / zhin.js:移除零引用的遗留导出——`Scheduler`、错误管理器与 `ZhinError` 子类、`compose`、`segment.from/toString`、AI 触发/准入函数、`@zhin.js/core/queue-im-field-contract`、`zhin.js/contexts`。
|
|
13
|
+
- agent:readonly 执行预设不再放行重定向、后台 `&`、进程替换、`find -delete/-exec`、`sed -i`、`sort -o`、`tee`、`xargs`、awk;curl/wget 校验每个 URL 与裸主机并识别更多上传参数;自定义 `execAllowlist` 中的只读命令带写入风险时改走审批。沙箱超时/取消会杀掉进程组或具名容器,默认镜像改为 `node:22-bookworm-slim` + `bash`。移除无生产调用的 `AuditLogger`、`AnomalyDetector`、旧 vision 回合等导出。
|
|
14
|
+
- ai:移除 `storage`、`FileStateCache`、`CostTracker`、`model-name-utils`、`./agent-step-checkpoint` 子路径、`ContextManager` 及旧压缩管线;延迟工具快照改为有界 LRU。
|
|
15
|
+
- cli:`zhin send` / `watch` / `schedule` 改为与运行中的 Host 通信(新增 `POST /message/send` 与 `/assistant/jobs` 写接口),`schedule` 不再支持离线改文件;移除 `zhin uninstall service`(用 `zhin service uninstall`)、`build --analyze`、`install -S`;`zhin stop` 杀不掉进程时保留 pid 文件并以非零退出;`runtime migrate` 新增 `verify`;未设置 `TZ` 时调度默认时区改为系统时区;不带 `ZHIN_SUPERVISOR_PID` 的进程被 init 接管后不再自行退出。
|
|
16
|
+
- schedule:后台 reconcile 出错不再产生未处理 rejection(新增 `onStoreError`);启动途中 `stop()` 不再遗留定时器。
|
|
17
|
+
- schema:元组校验与 `safeParse`、JSON Schema 一致(空数组不通过,缺省的可选元组为 `undefined`)。
|
|
18
|
+
- client / contract:删除无后端路由的 agent-stream API、未使用的 `definePage` 与旧 PageManager 类型;`@zhin.js/contract` 不再依赖 `@zhin.js/ai`;客户端收到 401 会清除已保存的凭据;安装/更新/卸载 RPC 默认超时 120 秒。
|
|
19
|
+
- a2a:流式响应中途出错写入 SSE error 并结束;未配置 token 的非生产环境只接受本机请求;任务存储有上限与过期;Mailbox 凭据回退与生产环境缺密钥检查修复。
|
|
20
|
+
- speech:`provider: openai` 不再套用 Ollama 的默认 host/model;识别语言改为可配置,不再写死 `zh`。
|
|
21
|
+
- adapter-lark:支持 `encryptKey` 加密事件解密。adapter-github:Device Flow 可取消、带超时并回复失败原因。adapter-wecom / dingtalk:请求加超时并校验 HTTP 状态。adapter-weixin-ilink:输入关闭期间暂停轮询。adapter-milky:SSE 支持 CRLF、缓冲上限与空闲重连。adapter-onebot-events:好友删除通知改为 `notice.friend.decrease`。
|
|
22
|
+
- plugin-group-suite:`teachAllowRegex` 默认关闭,正则安全检查更严格。plugin-qrcode:改为本地生成,回复 data URL 图片。plugin-rss / short-url / link-poster:拒绝解析到内网的地址;rss 修复条目每周重复推送;short-url 的 Console 创建改为真实调用 is.gd。plugin-lottery:按 `historyLimit` 同步。
|
|
23
|
+
|
|
24
|
+
**其余**
|
|
25
|
+
|
|
26
|
+
- host-http:插件市场详情加缓存与包名校验,SSE 回放容忍背压。host-http-contract:新增 `readTextBody()`,九个适配器改用它。
|
|
27
|
+
- pagemanager:页面外壳 importmap 升级到 React 19.2.8 / react-router 7.12.0。console-contract:`definePage` 接受 `description` / `group` / `parent` / `fullWidth`。
|
|
28
|
+
- command:进度提示本地化,匹配不再重复拷贝消息段。runtime:源码监听降级后退避重试原生监听。
|
|
29
|
+
- html-renderer:删除未接线的 `aiTextAsImage`。create-zhin-app / scaffold-wizard:移除不起作用的"全局安装 CLI"与运行时选择提示。
|
|
30
|
+
- 依赖声明清理、发布清单不再携带解析不到的 `src` 目录、移除未使用的 Skill 挂载、README 与示例配置按当前实现更正。
|
|
31
|
+
|
|
32
|
+
- 120e225: 聊天角色(ADR 0056,2026-11-12 修订):zhin 角色 owner / admin / trusted 分四级、只来自授予;发言者的平台身份与机器人自身的平台身份是独立维度,命令、Agent 工具 / 技能、中间件与按钮按三条维度共用一个评估器过滤。升级说明见 docs/migrations/chat-roles.md。
|
|
33
|
+
|
|
34
|
+
- zhin.js:实例首次启动把适配器 `master` / `trusted`、`endpoints[i].master|trusted` 与 `ai.trigger.masters|trusted` 迁入项目数据库 `chat_roles`(先记入 `.zhin/chat-roles-migration.json`,再从配置移除并记日志);之后配置再出现这些字段时启动报错并指向升级指南。平台身份不再映射为 zhin 角色:删除 `roles.mappings`(适配器块与 `endpoints[i].roles` 出现即启动报错)、`chat_role_mappings` 表与 Console `chat-roles.mappings` / `chat-roles.set-mappings`;`features.selfService.platformAdmins|roles|allowUsers` 删除;群内「功能」「角色」命令只认 zhin 角色,平台群主不再自动具备;聊天改配置、聊天重启、Agent 主人审批按 zhin `owner` 判断。
|
|
35
|
+
- @zhin.js/core(minor,破坏性):角色模型与解析移入 core(`ChatRoleService`、`createChatRoleSenderEnricher`),入站消息带 `sender.chatRole` 与归一的 `sender.platform`;删除 `SenderRole`、`senderRolesFromMessage`、`roleSatisfies` 等,`master` 改名 `owner`;删除映射规则 API(`createMappingChatRoleSource`、`DEFAULT_CHAT_ROLE_MAPPINGS` 等)与 `ChatRoleSource`;`createSenderEnricher` / `createConfigurationChatAuthorizer` 改为基于聊天角色。IM Runtime 为 PermissionHost 提供机器人自身身份(经 Adapter 索引缓存),机器人的角色变化事件使缓存失效;命令拒绝回复说明缺少的平台 / 机器人条件;`<Button permit>` 按点击者鉴权;场景治理工具工厂同时要求 `platform:*` 与 `bot:*`;`ai.trigger.masters|trusted` 删除。
|
|
36
|
+
- @zhin.js/permission(minor,破坏性):permit 语法 `owner` / `admin` / `trusted` / `role(...)`(zhin 角色)、`platform:owner|admin`、`platform-role:<id>`、`platform-permission:<name>`(发言者平台身份),新增 `bot:owner|admin`、`bot-role:<id>`、`bot-permission:<name>`(机器人自身平台身份,`PermissionSubject.bot`);`PermissionHost` 新增 `setBotStandingResolver`、`withBotStanding`、`firstDenied`,`checkAll` 可带 `source` 解析机器人身份;新增 `describeDeniedPermit`、`permitsNeedBotStanding`。删除 `role(master)`、`scene_admin`、`scene_owner`、`platform(adapter,perm)` 及 `registerPlatform`、`createSceneRolePlatformChecker`、`platformPermission`、`definePlatformPermission`,定义时报错并给出替代写法。
|
|
37
|
+
- @zhin.js/command(minor,破坏性):命令会话的发送者改为 `chatRole` / `platform`,不再从 metadata 读角色;`CONVERSATION_MANAGER_PERMIT` 改为 `admin`(平台群主不再自动满足);分发结果 `denied` 带 `denial`(第一条不满足的规则与原因);指令菜单只列出当前发送者在本会话可用的命令。
|
|
38
|
+
- @zhin.js/agent(minor,破坏性):危险工具、文件 / exec 策略、主人审批、Agent 回合主体只读 zhin 角色(`principal.roles` 只含展开的聊天角色,平台地位在 `principal.platform`);`SenderRole` → `PrincipalRole`,`SELF_CHANGE_MASTER_ROLE` → `SELF_CHANGE_OWNER_ROLE`;回合开始时读取机器人自身身份(`contextState.bot.platform`),按三条维度过滤 tool / skill / Agent 包后才披露,执行工具时再校验一次;群规「群主和管理员豁免」改为平台群主 / 管理员与 zhin `owner`。
|
|
39
|
+
- @zhin.js/feature-kit:`OperationSession.sender` 改为 `chatRole` / `platform`。
|
|
40
|
+
- @zhin.js/im-contract:新增 `PlatformStanding`、`SelfStandingRequest`、`standingFromMemberRole`。
|
|
41
|
+
- @zhin.js/adapter:入站 sender 可带 `platform`;账号管理命令需要聊天角色 `owner`;`EndpointManagement` 新增可选 `inspectSelfStanding`,能力画像新增 `scene.selfStanding`(声明即须实现),`AdapterIndex.selfStanding` / `invalidateSelfStanding` 按会话缓存机器人自身身份。
|
|
42
|
+
- @zhin.js/middleware:入站中间件可声明 `permit`,不满足时跳过该中间件(机器人身份只读缓存)。
|
|
43
|
+
- @zhin.js/tool:定义工具时拒绝已移除的 permit 写法。
|
|
44
|
+
- @zhin.js/ai:注释更新。
|
|
45
|
+
- @zhin.js/console-protocol:`chat-roles.list|grant|revoke`(`iam.manage`);`ConsoleChatRoleSource` 只有 `grant`。
|
|
46
|
+
- @zhin.js/runtime:Host 配置 Schema 删除 `features.selfService.platformAdmins|roles|allowUsers`。
|
|
47
|
+
- @zhin.js/testing:伪造消息与 `PluginTestKit` 用 `sender.chatRole` 声明测试身份。
|
|
48
|
+
- @zhin.js/scaffold-wizard:ICQQ 向导不再写 `master`,完成后提示在 Console 账号「角色」页签或聊天 `角色 授予` 设置 owner。
|
|
49
|
+
- 适配器:配置 Schema 删除 `master` / `trusted`(以及预览版的 `roles`);群管理类工具同时声明发言者条件与机器人条件(如 `platform:admin` + `bot:admin`、`bot-permission:manage_roles`),NapCat / OneBot11 工具不再使用已移除的 `platform(adapter,…)` 写法。
|
|
50
|
+
- 插件:内容审核以 `inbound.bypass`(permit 列表,默认 `owner` 或 `platform:admin`)取代 `masters` / `inbound.bypassMasters`;群管、音乐、日历、地震、B 站、轮盘赌的权限改用 zhin 角色,订阅类命令只认 zhin `admin` / `owner`。
|
|
51
|
+
|
|
52
|
+
- Updated dependencies [53932e5]
|
|
53
|
+
- Updated dependencies [57c6cdc]
|
|
54
|
+
- Updated dependencies [e1fda87]
|
|
55
|
+
- Updated dependencies [a9c7a13]
|
|
56
|
+
- Updated dependencies [120e225]
|
|
57
|
+
- Updated dependencies [c2bbdcf]
|
|
58
|
+
- Updated dependencies [63595fc]
|
|
59
|
+
- Updated dependencies [fd055d2]
|
|
60
|
+
- Updated dependencies [c2bbdcf]
|
|
61
|
+
- Updated dependencies [663473b]
|
|
62
|
+
- Updated dependencies [c606d51]
|
|
63
|
+
- Updated dependencies [5cd9d3d]
|
|
64
|
+
- Updated dependencies [d655ef0]
|
|
65
|
+
- Updated dependencies [1e54b1e]
|
|
66
|
+
- @zhin.js/adapter@1.1.33
|
|
67
|
+
- @zhin.js/core@1.2.0
|
|
68
|
+
- @zhin.js/logger@1.1.3
|
|
69
|
+
- @zhin.js/feature-kit@1.1.16
|
|
70
|
+
- @zhin.js/console-contract@1.1.6
|
|
71
|
+
- @zhin.js/im-contract@1.1.14
|
|
72
|
+
- @zhin.js/page@1.1.18
|
|
73
|
+
|
|
74
|
+
## 1.1.26
|
|
75
|
+
|
|
76
|
+
### Patch Changes
|
|
77
|
+
|
|
78
|
+
- 0d76a7c: Overhaul Console interactive workbenches, platform-specific adapter account onboarding/login flows, DeclarativePageView visual/interactive capabilities, and official utility plugin Console pages.
|
|
79
|
+
- Updated dependencies [0d76a7c]
|
|
80
|
+
- @zhin.js/adapter@1.1.32
|
|
81
|
+
- @zhin.js/core@1.1.60
|
|
82
|
+
|
|
3
83
|
## 1.1.25
|
|
4
84
|
|
|
5
85
|
### Patch Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 凉菜
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -20,6 +20,12 @@
|
|
|
20
20
|
- 微信客户端需已灰度 **ClawBot** 入口(最新版微信 + 灰度资格)
|
|
21
21
|
- Node.js >=22.19.0
|
|
22
22
|
|
|
23
|
+
## 安装
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm add @zhin.js/adapter-weixin-ilink
|
|
27
|
+
```
|
|
28
|
+
|
|
23
29
|
## 最小配置
|
|
24
30
|
|
|
25
31
|
```yaml
|
|
@@ -72,7 +78,7 @@ data/weixin-ilink/<id>/credentials.json
|
|
|
72
78
|
|
|
73
79
|
新增仅保存,需手动启动;运行账号的普通配置更新只重连该账号。身份变化走明确替换,新账号不会继承旧 Session 或登录状态。账号凭据变化先按平台实际只读接口核验;平台无法核验时需明确替换。空白或遮蔽的密码不会覆盖既有密码。
|
|
74
80
|
|
|
75
|
-
读取需要 `weixin-ilink:read
|
|
81
|
+
读取需要 `weixin-ilink:read`(`read` 级别,内置角色 `viewer` 及以上都有),写入需要 `weixin-ilink:write`(`operate` 级别,`operator` 及以上都有,绑定到本适配器的角色也算);首次迁移还需管理员身份,见[插件权限的级别](https://zhin.js.org/console/#插件权限的级别)。无持久化存储时管理操作不可用,提交结果未知时先刷新核实,不重复提交。
|
|
76
82
|
|
|
77
83
|
未提供 `botToken` 时,启动沿既有凭据文件或日志二维码登录流程;本平台当前没有 Console 二维码待办。新账号的状态目录按内部实例身份隔离。
|
|
78
84
|
|
package/lib/client.js
CHANGED
|
@@ -42,6 +42,9 @@ export class WeixinIlinkClient extends EventEmitter {
|
|
|
42
42
|
#metadata;
|
|
43
43
|
#creds = null;
|
|
44
44
|
#pollAbort;
|
|
45
|
+
/** Aborts the in-flight long poll when input closes. */
|
|
46
|
+
#pollRequestAbort;
|
|
47
|
+
#openWaiters = [];
|
|
45
48
|
#pollPromise;
|
|
46
49
|
#loginAbort;
|
|
47
50
|
#configManager;
|
|
@@ -208,11 +211,31 @@ export class WeixinIlinkClient extends EventEmitter {
|
|
|
208
211
|
}
|
|
209
212
|
openInput() {
|
|
210
213
|
this.#open = true;
|
|
214
|
+
for (const resume of this.#openWaiters.splice(0))
|
|
215
|
+
resume();
|
|
211
216
|
if (this.#pollAbort && !this.#pollPromise)
|
|
212
217
|
this.#pollPromise = this.#pollLoop(this.#pollAbort.signal);
|
|
213
218
|
}
|
|
214
219
|
closeInput() {
|
|
215
220
|
this.#open = false;
|
|
221
|
+
// Nothing can be admitted while closed: stop the long poll instead of re-fetching the same batch.
|
|
222
|
+
this.#pollRequestAbort?.abort();
|
|
223
|
+
}
|
|
224
|
+
/** Resolves on the next openInput(), or when the poll loop is aborted. */
|
|
225
|
+
#waitForOpen(abortSignal) {
|
|
226
|
+
if (this.#open || abortSignal.aborted)
|
|
227
|
+
return Promise.resolve();
|
|
228
|
+
return new Promise((resolve) => {
|
|
229
|
+
const done = () => {
|
|
230
|
+
abortSignal.removeEventListener('abort', done);
|
|
231
|
+
const index = this.#openWaiters.indexOf(done);
|
|
232
|
+
if (index >= 0)
|
|
233
|
+
this.#openWaiters.splice(index, 1);
|
|
234
|
+
resolve();
|
|
235
|
+
};
|
|
236
|
+
this.#openWaiters.push(done);
|
|
237
|
+
abortSignal.addEventListener('abort', done, { once: true });
|
|
238
|
+
});
|
|
216
239
|
}
|
|
217
240
|
disconnectTransport() { return this.#disconnecting ??= this.#disconnectNative(); }
|
|
218
241
|
async #disconnectNative() {
|
|
@@ -357,10 +380,16 @@ export class WeixinIlinkClient extends EventEmitter {
|
|
|
357
380
|
let nextTimeoutMs = this.#options.config.longPollTimeoutMs;
|
|
358
381
|
let consecutiveFailures = 0;
|
|
359
382
|
while (!abortSignal.aborted) {
|
|
383
|
+
if (!this.#open) {
|
|
384
|
+
await this.#waitForOpen(abortSignal);
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
360
387
|
if (this.#sessionGuard.paused) {
|
|
361
388
|
await sleep(this.#sessionGuard.remainingMs, abortSignal);
|
|
362
389
|
continue;
|
|
363
390
|
}
|
|
391
|
+
const request = new AbortController();
|
|
392
|
+
this.#pollRequestAbort = request;
|
|
364
393
|
try {
|
|
365
394
|
const resp = await this.#getUpdates({
|
|
366
395
|
baseUrl: this.apiBaseUrl,
|
|
@@ -368,9 +397,12 @@ export class WeixinIlinkClient extends EventEmitter {
|
|
|
368
397
|
token: this.#creds.botToken,
|
|
369
398
|
get_updates_buf: getUpdatesBuf,
|
|
370
399
|
timeoutMs: nextTimeoutMs,
|
|
371
|
-
abortSignal,
|
|
400
|
+
abortSignal: AbortSignal.any([abortSignal, request.signal]),
|
|
372
401
|
});
|
|
373
402
|
abortSignal.throwIfAborted();
|
|
403
|
+
// Closed while polling: drop the batch without advancing the cursor; it is re-fetched after reopen.
|
|
404
|
+
if (!this.#open)
|
|
405
|
+
continue;
|
|
374
406
|
if (resp.longpolling_timeout_ms != null && resp.longpolling_timeout_ms > 0) {
|
|
375
407
|
nextTimeoutMs = resp.longpolling_timeout_ms;
|
|
376
408
|
}
|
|
@@ -408,6 +440,9 @@ export class WeixinIlinkClient extends EventEmitter {
|
|
|
408
440
|
catch (err) {
|
|
409
441
|
if (abortSignal.aborted)
|
|
410
442
|
return;
|
|
443
|
+
// Input closed mid-request or mid-batch is a pause, not a failure.
|
|
444
|
+
if (!this.#open)
|
|
445
|
+
continue;
|
|
411
446
|
consecutiveFailures += 1;
|
|
412
447
|
this.#logger.error(formatCompact({
|
|
413
448
|
op: 'poll',
|
package/lib/console-spec.js
CHANGED
|
@@ -2,7 +2,18 @@ export const weixinIlinkConsoleSpec = {
|
|
|
2
2
|
adapterKey: 'weixin-ilink',
|
|
3
3
|
adapterDisplayName: '微信 iLink',
|
|
4
4
|
fields: [
|
|
5
|
-
{
|
|
5
|
+
{
|
|
6
|
+
key: 'botToken',
|
|
7
|
+
env: true,
|
|
8
|
+
label: 'iLink Bot Token',
|
|
9
|
+
labelI18n: { en: 'iLink Bot Token' },
|
|
10
|
+
group: '企业应用凭证',
|
|
11
|
+
groupI18n: { en: 'Enterprise App Credentials' },
|
|
12
|
+
placeholder: '扫码授权获取的 iLink Bot Token',
|
|
13
|
+
placeholderI18n: { en: 'iLink bot token obtained via QR auth' },
|
|
14
|
+
description: '微信 iLink 机器人凭证(也可通过命令扫码自动写入)',
|
|
15
|
+
descriptionI18n: { en: 'iLink bot token' },
|
|
16
|
+
},
|
|
6
17
|
],
|
|
7
18
|
docsUrl: 'https://zhin.js.org/adapters/weixin-ilink',
|
|
8
19
|
readPermission: 'weixin-ilink:read',
|
package/lib/ilink-redact.d.ts
CHANGED
|
@@ -3,11 +3,6 @@
|
|
|
3
3
|
* Returns `""` for empty/undefined input.
|
|
4
4
|
*/
|
|
5
5
|
export declare function truncate(s: string | undefined, max: number): string;
|
|
6
|
-
/**
|
|
7
|
-
* Redact a token/secret: show only the first few chars + total length.
|
|
8
|
-
* Returns `"(none)"` when absent.
|
|
9
|
-
*/
|
|
10
|
-
export declare function redactToken(token: string | undefined, prefixLen?: number): string;
|
|
11
6
|
/**
|
|
12
7
|
* Truncate a JSON body string to `maxLen` chars for safe logging.
|
|
13
8
|
* Redacts known sensitive fields before truncating.
|
package/lib/ilink-redact.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const DEFAULT_BODY_MAX_LEN = 200;
|
|
2
|
-
const DEFAULT_TOKEN_PREFIX_LEN = 6;
|
|
3
2
|
/**
|
|
4
3
|
* Truncate a string, appending a length indicator when trimmed.
|
|
5
4
|
* Returns `""` for empty/undefined input.
|
|
@@ -11,17 +10,6 @@ export function truncate(s, max) {
|
|
|
11
10
|
return s;
|
|
12
11
|
return `${s.slice(0, max)}…(len=${s.length})`;
|
|
13
12
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Redact a token/secret: show only the first few chars + total length.
|
|
16
|
-
* Returns `"(none)"` when absent.
|
|
17
|
-
*/
|
|
18
|
-
export function redactToken(token, prefixLen = DEFAULT_TOKEN_PREFIX_LEN) {
|
|
19
|
-
if (!token)
|
|
20
|
-
return "(none)";
|
|
21
|
-
if (token.length <= prefixLen)
|
|
22
|
-
return `****(len=${token.length})`;
|
|
23
|
-
return `${token.slice(0, prefixLen)}…(len=${token.length})`;
|
|
24
|
-
}
|
|
25
13
|
/** Field names whose values should be masked in logged JSON bodies. */
|
|
26
14
|
const SENSITIVE_FIELDS = /\b(context_token|bot_token|token|authorization|Authorization)\b/;
|
|
27
15
|
/**
|
package/lib/ilink-types.d.ts
CHANGED
|
@@ -189,11 +189,6 @@ export interface SendMessageReq {
|
|
|
189
189
|
}
|
|
190
190
|
export interface SendMessageResp {
|
|
191
191
|
}
|
|
192
|
-
/** Typing status: 1 = typing (default), 2 = cancel typing. */
|
|
193
|
-
export declare const TypingStatus: {
|
|
194
|
-
readonly TYPING: 1;
|
|
195
|
-
readonly CANCEL: 2;
|
|
196
|
-
};
|
|
197
192
|
/** SendTyping request: send a typing indicator to a user. */
|
|
198
193
|
export interface SendTypingReq {
|
|
199
194
|
ilink_user_id?: string;
|
package/lib/ilink-types.js
CHANGED
package/lib/weixin-inbound.d.ts
CHANGED
|
@@ -1,23 +1,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export type WeixinMsgContext = {
|
|
3
|
-
Body: string;
|
|
4
|
-
From: string;
|
|
5
|
-
To: string;
|
|
6
|
-
AccountId: string;
|
|
7
|
-
OriginatingChannel: 'openclaw-weixin';
|
|
8
|
-
OriginatingTo: string;
|
|
9
|
-
MessageSid: string;
|
|
10
|
-
Timestamp?: number;
|
|
11
|
-
Provider: 'openclaw-weixin';
|
|
12
|
-
ChatType: 'direct';
|
|
13
|
-
SessionKey?: string;
|
|
14
|
-
context_token?: string;
|
|
15
|
-
MediaUrl?: string;
|
|
16
|
-
MediaPath?: string;
|
|
17
|
-
MediaType?: string;
|
|
18
|
-
CommandBody?: string;
|
|
19
|
-
CommandAuthorized?: boolean;
|
|
20
|
-
};
|
|
1
|
+
import { type MessageItem } from './ilink-types.js';
|
|
21
2
|
export declare function isMediaItem(item: MessageItem): boolean;
|
|
22
3
|
export declare function bodyFromItemList(itemList?: MessageItem[]): string;
|
|
23
4
|
export type WeixinInboundMediaOpts = {
|
|
@@ -28,5 +9,3 @@ export type WeixinInboundMediaOpts = {
|
|
|
28
9
|
fileMediaType?: string;
|
|
29
10
|
decryptedVideoPath?: string;
|
|
30
11
|
};
|
|
31
|
-
export declare function weixinMessageToMsgContext(msg: WeixinMessage, accountId: string, opts?: WeixinInboundMediaOpts): WeixinMsgContext;
|
|
32
|
-
export declare function getContextTokenFromMsgContext(ctx: WeixinMsgContext): string | undefined;
|
package/lib/weixin-inbound.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { generateId } from './ilink-random.js';
|
|
2
1
|
import { MessageItemType } from './ilink-types.js';
|
|
3
|
-
function generateMessageSid() {
|
|
4
|
-
return generateId('openclaw-weixin');
|
|
5
|
-
}
|
|
6
2
|
export function isMediaItem(item) {
|
|
7
3
|
return item.type === MessageItemType.IMAGE
|
|
8
4
|
|| item.type === MessageItemType.VIDEO
|
|
@@ -22,40 +18,3 @@ export function bodyFromItemList(itemList) {
|
|
|
22
18
|
}
|
|
23
19
|
return '';
|
|
24
20
|
}
|
|
25
|
-
export function weixinMessageToMsgContext(msg, accountId, opts) {
|
|
26
|
-
const fromUserId = msg.from_user_id ?? '';
|
|
27
|
-
const ctx = {
|
|
28
|
-
Body: bodyFromItemList(msg.item_list),
|
|
29
|
-
From: fromUserId,
|
|
30
|
-
To: fromUserId,
|
|
31
|
-
AccountId: accountId,
|
|
32
|
-
OriginatingChannel: 'openclaw-weixin',
|
|
33
|
-
OriginatingTo: fromUserId,
|
|
34
|
-
MessageSid: generateMessageSid(),
|
|
35
|
-
Timestamp: msg.create_time_ms,
|
|
36
|
-
Provider: 'openclaw-weixin',
|
|
37
|
-
ChatType: 'direct',
|
|
38
|
-
};
|
|
39
|
-
if (msg.context_token)
|
|
40
|
-
ctx.context_token = msg.context_token;
|
|
41
|
-
if (opts?.decryptedPicPath) {
|
|
42
|
-
ctx.MediaPath = opts.decryptedPicPath;
|
|
43
|
-
ctx.MediaType = 'image/*';
|
|
44
|
-
}
|
|
45
|
-
else if (opts?.decryptedVideoPath) {
|
|
46
|
-
ctx.MediaPath = opts.decryptedVideoPath;
|
|
47
|
-
ctx.MediaType = 'video/mp4';
|
|
48
|
-
}
|
|
49
|
-
else if (opts?.decryptedFilePath) {
|
|
50
|
-
ctx.MediaPath = opts.decryptedFilePath;
|
|
51
|
-
ctx.MediaType = opts.fileMediaType ?? 'application/octet-stream';
|
|
52
|
-
}
|
|
53
|
-
else if (opts?.decryptedVoicePath) {
|
|
54
|
-
ctx.MediaPath = opts.decryptedVoicePath;
|
|
55
|
-
ctx.MediaType = opts.voiceMediaType ?? 'audio/wav';
|
|
56
|
-
}
|
|
57
|
-
return ctx;
|
|
58
|
-
}
|
|
59
|
-
export function getContextTokenFromMsgContext(ctx) {
|
|
60
|
-
return ctx.context_token;
|
|
61
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-weixin-ilink",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.27",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Zhin.js Weixin iLink (ClawBot) adapter for Plugin Runtime (long-poll)",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -49,19 +49,19 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@zhin.js/adapter": "1.1.
|
|
53
|
-
"@zhin.js/console-contract": "1.1.
|
|
54
|
-
"@zhin.js/core": "1.
|
|
55
|
-
"@zhin.js/feature-kit": "1.1.
|
|
56
|
-
"@zhin.js/im-contract": "1.1.
|
|
57
|
-
"@zhin.js/logger": "1.1.
|
|
58
|
-
"@zhin.js/page": "1.1.
|
|
52
|
+
"@zhin.js/adapter": "1.1.33",
|
|
53
|
+
"@zhin.js/console-contract": "1.1.6",
|
|
54
|
+
"@zhin.js/core": "1.2.0",
|
|
55
|
+
"@zhin.js/feature-kit": "1.1.16",
|
|
56
|
+
"@zhin.js/im-contract": "1.1.14",
|
|
57
|
+
"@zhin.js/logger": "1.1.3",
|
|
58
|
+
"@zhin.js/page": "1.1.18"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"@zhin.js/adapter": "^1.1.
|
|
62
|
-
"@zhin.js/command": "^1.
|
|
63
|
-
"@zhin.js/core": "^1.
|
|
64
|
-
"zhin.js": "^1.1.
|
|
61
|
+
"@zhin.js/adapter": "^1.1.33",
|
|
62
|
+
"@zhin.js/command": "^1.2.0",
|
|
63
|
+
"@zhin.js/core": "^1.2.0",
|
|
64
|
+
"zhin.js": "^1.1.26"
|
|
65
65
|
},
|
|
66
66
|
"peerDependenciesMeta": {
|
|
67
67
|
"@zhin.js/command": {
|
|
@@ -75,7 +75,8 @@
|
|
|
75
75
|
"@types/node": "^26.1.2",
|
|
76
76
|
"typescript": "^6.0.3",
|
|
77
77
|
"vitest": "^4.1.10",
|
|
78
|
-
"zhin.js": "1.
|
|
78
|
+
"@zhin.js/host-http": "1.2.0",
|
|
79
|
+
"zhin.js": "1.1.26"
|
|
79
80
|
},
|
|
80
81
|
"ilink_appid": "bot",
|
|
81
82
|
"engines": {
|
|
@@ -106,6 +107,6 @@
|
|
|
106
107
|
"scripts": {
|
|
107
108
|
"build": "tsc",
|
|
108
109
|
"clean": "rimraf lib",
|
|
109
|
-
"test": "
|
|
110
|
+
"test": "vitest run --root ../../.. plugins/adapters/weixin-ilink/tests"
|
|
110
111
|
}
|
|
111
112
|
}
|
package/schema.json
CHANGED
|
@@ -24,34 +24,6 @@
|
|
|
24
24
|
"default": "data/weixin-ilink",
|
|
25
25
|
"description": "Endpoint state root for credentials, cursors, context tokens, and media"
|
|
26
26
|
},
|
|
27
|
-
"master": {
|
|
28
|
-
"type": [
|
|
29
|
-
"string",
|
|
30
|
-
"number"
|
|
31
|
-
],
|
|
32
|
-
"description": "框架 master(Weixin user id;AI/工具权限、endpoint 管理)。endpoints[i].master 可逐项覆盖",
|
|
33
|
-
"x-i18n": {
|
|
34
|
-
"en": {
|
|
35
|
-
"description": "Framework masters (Weixin user id; AI/tool permissions and endpoint management). endpoints[i].master can override this value."
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
"trusted": {
|
|
40
|
-
"type": "array",
|
|
41
|
-
"items": {
|
|
42
|
-
"type": [
|
|
43
|
-
"string",
|
|
44
|
-
"number"
|
|
45
|
-
],
|
|
46
|
-
"description": "Trusted Weixin user id"
|
|
47
|
-
},
|
|
48
|
-
"description": "框架 trusted 用户列表(弱于 master)。endpoints[i].trusted 可逐项追加",
|
|
49
|
-
"x-i18n": {
|
|
50
|
-
"en": {
|
|
51
|
-
"description": "Framework trusted users, below master authority. endpoints[i].trusted can add users."
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
27
|
"endpoints": {
|
|
56
28
|
"type": "array",
|
|
57
29
|
"minItems": 1,
|
|
@@ -60,34 +32,6 @@
|
|
|
60
32
|
"type": "object",
|
|
61
33
|
"additionalProperties": false,
|
|
62
34
|
"properties": {
|
|
63
|
-
"master": {
|
|
64
|
-
"type": [
|
|
65
|
-
"string",
|
|
66
|
-
"number"
|
|
67
|
-
],
|
|
68
|
-
"description": "本 endpoint 的框架 master(Weixin user id);覆盖顶层 master",
|
|
69
|
-
"x-i18n": {
|
|
70
|
-
"en": {
|
|
71
|
-
"description": "Framework masters for this endpoint (Weixin user id), overriding the top-level master list."
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
"trusted": {
|
|
76
|
-
"type": "array",
|
|
77
|
-
"items": {
|
|
78
|
-
"type": [
|
|
79
|
-
"string",
|
|
80
|
-
"number"
|
|
81
|
-
],
|
|
82
|
-
"description": "Trusted Weixin user id"
|
|
83
|
-
},
|
|
84
|
-
"description": "本 endpoint 的 trusted 列表",
|
|
85
|
-
"x-i18n": {
|
|
86
|
-
"en": {
|
|
87
|
-
"description": "Trusted users for this endpoint."
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
35
|
"botToken": {
|
|
92
36
|
"type": "string",
|
|
93
37
|
"description": "iLink bot token; omit to load endpoint state or start QR login"
|
package/src/client.ts
CHANGED
|
@@ -112,6 +112,9 @@ export class WeixinIlinkClient extends EventEmitter {
|
|
|
112
112
|
readonly #metadata: IlinkClientMetadata;
|
|
113
113
|
#creds: WeixinIlinkCredentials | null = null;
|
|
114
114
|
#pollAbort?: AbortController;
|
|
115
|
+
/** Aborts the in-flight long poll when input closes. */
|
|
116
|
+
#pollRequestAbort?: AbortController;
|
|
117
|
+
#openWaiters: (() => void)[] = [];
|
|
115
118
|
#pollPromise?: Promise<void>;
|
|
116
119
|
#loginAbort?: AbortController;
|
|
117
120
|
#configManager?: WeixinConfigManager;
|
|
@@ -291,11 +294,29 @@ export class WeixinIlinkClient extends EventEmitter {
|
|
|
291
294
|
|
|
292
295
|
protected openInput(): void {
|
|
293
296
|
this.#open = true;
|
|
297
|
+
for (const resume of this.#openWaiters.splice(0)) resume();
|
|
294
298
|
if (this.#pollAbort && !this.#pollPromise) this.#pollPromise = this.#pollLoop(this.#pollAbort.signal);
|
|
295
299
|
}
|
|
296
300
|
|
|
297
301
|
protected closeInput(): void {
|
|
298
302
|
this.#open = false;
|
|
303
|
+
// Nothing can be admitted while closed: stop the long poll instead of re-fetching the same batch.
|
|
304
|
+
this.#pollRequestAbort?.abort();
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** Resolves on the next openInput(), or when the poll loop is aborted. */
|
|
308
|
+
#waitForOpen(abortSignal: AbortSignal): Promise<void> {
|
|
309
|
+
if (this.#open || abortSignal.aborted) return Promise.resolve();
|
|
310
|
+
return new Promise((resolve) => {
|
|
311
|
+
const done = (): void => {
|
|
312
|
+
abortSignal.removeEventListener('abort', done);
|
|
313
|
+
const index = this.#openWaiters.indexOf(done);
|
|
314
|
+
if (index >= 0) this.#openWaiters.splice(index, 1);
|
|
315
|
+
resolve();
|
|
316
|
+
};
|
|
317
|
+
this.#openWaiters.push(done);
|
|
318
|
+
abortSignal.addEventListener('abort', done, { once: true });
|
|
319
|
+
});
|
|
299
320
|
}
|
|
300
321
|
|
|
301
322
|
protected disconnectTransport(): Promise<void> { return this.#disconnecting ??= this.#disconnectNative(); }
|
|
@@ -449,11 +470,17 @@ export class WeixinIlinkClient extends EventEmitter {
|
|
|
449
470
|
let consecutiveFailures = 0;
|
|
450
471
|
|
|
451
472
|
while (!abortSignal.aborted) {
|
|
473
|
+
if (!this.#open) {
|
|
474
|
+
await this.#waitForOpen(abortSignal);
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
452
477
|
if (this.#sessionGuard.paused) {
|
|
453
478
|
await sleep(this.#sessionGuard.remainingMs, abortSignal);
|
|
454
479
|
continue;
|
|
455
480
|
}
|
|
456
481
|
|
|
482
|
+
const request = new AbortController();
|
|
483
|
+
this.#pollRequestAbort = request;
|
|
457
484
|
try {
|
|
458
485
|
const resp = await this.#getUpdates({
|
|
459
486
|
baseUrl: this.apiBaseUrl,
|
|
@@ -461,10 +488,12 @@ export class WeixinIlinkClient extends EventEmitter {
|
|
|
461
488
|
token: this.#creds.botToken,
|
|
462
489
|
get_updates_buf: getUpdatesBuf,
|
|
463
490
|
timeoutMs: nextTimeoutMs,
|
|
464
|
-
abortSignal,
|
|
491
|
+
abortSignal: AbortSignal.any([abortSignal, request.signal]),
|
|
465
492
|
});
|
|
466
493
|
|
|
467
494
|
abortSignal.throwIfAborted();
|
|
495
|
+
// Closed while polling: drop the batch without advancing the cursor; it is re-fetched after reopen.
|
|
496
|
+
if (!this.#open) continue;
|
|
468
497
|
if (resp.longpolling_timeout_ms != null && resp.longpolling_timeout_ms > 0) {
|
|
469
498
|
nextTimeoutMs = resp.longpolling_timeout_ms;
|
|
470
499
|
}
|
|
@@ -504,6 +533,8 @@ export class WeixinIlinkClient extends EventEmitter {
|
|
|
504
533
|
}
|
|
505
534
|
} catch (err) {
|
|
506
535
|
if (abortSignal.aborted) return;
|
|
536
|
+
// Input closed mid-request or mid-batch is a pause, not a failure.
|
|
537
|
+
if (!this.#open) continue;
|
|
507
538
|
consecutiveFailures += 1;
|
|
508
539
|
this.#logger.error(formatCompact({
|
|
509
540
|
op: 'poll',
|
package/src/console-spec.ts
CHANGED
|
@@ -7,7 +7,18 @@ export const weixinIlinkConsoleSpec = {
|
|
|
7
7
|
adapterKey: 'weixin-ilink',
|
|
8
8
|
adapterDisplayName: '微信 iLink',
|
|
9
9
|
fields: [
|
|
10
|
-
{
|
|
10
|
+
{
|
|
11
|
+
key: 'botToken',
|
|
12
|
+
env: true,
|
|
13
|
+
label: 'iLink Bot Token',
|
|
14
|
+
labelI18n: { en: 'iLink Bot Token' },
|
|
15
|
+
group: '企业应用凭证',
|
|
16
|
+
groupI18n: { en: 'Enterprise App Credentials' },
|
|
17
|
+
placeholder: '扫码授权获取的 iLink Bot Token',
|
|
18
|
+
placeholderI18n: { en: 'iLink bot token obtained via QR auth' },
|
|
19
|
+
description: '微信 iLink 机器人凭证(也可通过命令扫码自动写入)',
|
|
20
|
+
descriptionI18n: { en: 'iLink bot token' },
|
|
21
|
+
},
|
|
11
22
|
] as readonly AdapterConsoleField[],
|
|
12
23
|
docsUrl: 'https://zhin.js.org/adapters/weixin-ilink',
|
|
13
24
|
readPermission: 'weixin-ilink:read',
|
package/src/ilink-redact.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const DEFAULT_BODY_MAX_LEN = 200;
|
|
2
|
-
const DEFAULT_TOKEN_PREFIX_LEN = 6;
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Truncate a string, appending a length indicator when trimmed.
|
|
@@ -11,16 +10,6 @@ export function truncate(s: string | undefined, max: number): string {
|
|
|
11
10
|
return `${s.slice(0, max)}…(len=${s.length})`;
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
/**
|
|
15
|
-
* Redact a token/secret: show only the first few chars + total length.
|
|
16
|
-
* Returns `"(none)"` when absent.
|
|
17
|
-
*/
|
|
18
|
-
export function redactToken(token: string | undefined, prefixLen = DEFAULT_TOKEN_PREFIX_LEN): string {
|
|
19
|
-
if (!token) return "(none)";
|
|
20
|
-
if (token.length <= prefixLen) return `****(len=${token.length})`;
|
|
21
|
-
return `${token.slice(0, prefixLen)}…(len=${token.length})`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
13
|
/** Field names whose values should be masked in logged JSON bodies. */
|
|
25
14
|
const SENSITIVE_FIELDS = /\b(context_token|bot_token|token|authorization|Authorization)\b/;
|
|
26
15
|
|
package/src/ilink-types.ts
CHANGED
|
@@ -211,12 +211,6 @@ export interface SendMessageResp {
|
|
|
211
211
|
// empty
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
/** Typing status: 1 = typing (default), 2 = cancel typing. */
|
|
215
|
-
export const TypingStatus = {
|
|
216
|
-
TYPING: 1,
|
|
217
|
-
CANCEL: 2,
|
|
218
|
-
} as const;
|
|
219
|
-
|
|
220
214
|
/** SendTyping request: send a typing indicator to a user. */
|
|
221
215
|
export interface SendTypingReq {
|
|
222
216
|
ilink_user_id?: string;
|
package/src/weixin-inbound.ts
CHANGED
|
@@ -1,29 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MessageItemType, type WeixinMessage, type MessageItem } from './ilink-types.js';
|
|
3
|
-
|
|
4
|
-
function generateMessageSid(): string {
|
|
5
|
-
return generateId('openclaw-weixin');
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export type WeixinMsgContext = {
|
|
9
|
-
Body: string;
|
|
10
|
-
From: string;
|
|
11
|
-
To: string;
|
|
12
|
-
AccountId: string;
|
|
13
|
-
OriginatingChannel: 'openclaw-weixin';
|
|
14
|
-
OriginatingTo: string;
|
|
15
|
-
MessageSid: string;
|
|
16
|
-
Timestamp?: number;
|
|
17
|
-
Provider: 'openclaw-weixin';
|
|
18
|
-
ChatType: 'direct';
|
|
19
|
-
SessionKey?: string;
|
|
20
|
-
context_token?: string;
|
|
21
|
-
MediaUrl?: string;
|
|
22
|
-
MediaPath?: string;
|
|
23
|
-
MediaType?: string;
|
|
24
|
-
CommandBody?: string;
|
|
25
|
-
CommandAuthorized?: boolean;
|
|
26
|
-
};
|
|
1
|
+
import { MessageItemType, type MessageItem } from './ilink-types.js';
|
|
27
2
|
|
|
28
3
|
export function isMediaItem(item: MessageItem): boolean {
|
|
29
4
|
return item.type === MessageItemType.IMAGE
|
|
@@ -54,42 +29,3 @@ export type WeixinInboundMediaOpts = {
|
|
|
54
29
|
decryptedVideoPath?: string;
|
|
55
30
|
};
|
|
56
31
|
|
|
57
|
-
export function weixinMessageToMsgContext(
|
|
58
|
-
msg: WeixinMessage,
|
|
59
|
-
accountId: string,
|
|
60
|
-
opts?: WeixinInboundMediaOpts,
|
|
61
|
-
): WeixinMsgContext {
|
|
62
|
-
const fromUserId = msg.from_user_id ?? '';
|
|
63
|
-
const ctx: WeixinMsgContext = {
|
|
64
|
-
Body: bodyFromItemList(msg.item_list),
|
|
65
|
-
From: fromUserId,
|
|
66
|
-
To: fromUserId,
|
|
67
|
-
AccountId: accountId,
|
|
68
|
-
OriginatingChannel: 'openclaw-weixin',
|
|
69
|
-
OriginatingTo: fromUserId,
|
|
70
|
-
MessageSid: generateMessageSid(),
|
|
71
|
-
Timestamp: msg.create_time_ms,
|
|
72
|
-
Provider: 'openclaw-weixin',
|
|
73
|
-
ChatType: 'direct',
|
|
74
|
-
};
|
|
75
|
-
if (msg.context_token) ctx.context_token = msg.context_token;
|
|
76
|
-
|
|
77
|
-
if (opts?.decryptedPicPath) {
|
|
78
|
-
ctx.MediaPath = opts.decryptedPicPath;
|
|
79
|
-
ctx.MediaType = 'image/*';
|
|
80
|
-
} else if (opts?.decryptedVideoPath) {
|
|
81
|
-
ctx.MediaPath = opts.decryptedVideoPath;
|
|
82
|
-
ctx.MediaType = 'video/mp4';
|
|
83
|
-
} else if (opts?.decryptedFilePath) {
|
|
84
|
-
ctx.MediaPath = opts.decryptedFilePath;
|
|
85
|
-
ctx.MediaType = opts.fileMediaType ?? 'application/octet-stream';
|
|
86
|
-
} else if (opts?.decryptedVoicePath) {
|
|
87
|
-
ctx.MediaPath = opts.decryptedVoicePath;
|
|
88
|
-
ctx.MediaType = opts.voiceMediaType ?? 'audio/wav';
|
|
89
|
-
}
|
|
90
|
-
return ctx;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function getContextTokenFromMsgContext(ctx: WeixinMsgContext): string | undefined {
|
|
94
|
-
return ctx.context_token;
|
|
95
|
-
}
|
package/lib/types.d.ts
DELETED
package/lib/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|