@openclaw-china/wecom-app 0.1.5 → 0.1.7
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/dist/index.d.ts +32 -66
- package/dist/index.js +164 -236
- package/dist/index.js.map +1 -1
- package/openclaw.plugin.json +3 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,6 @@ import { IncomingMessage, ServerResponse } from 'http';
|
|
|
5
5
|
*/
|
|
6
6
|
/** DM 消息策略 */
|
|
7
7
|
type WecomAppDmPolicy = "open" | "pairing" | "allowlist" | "disabled";
|
|
8
|
-
/** 群组消息策略 */
|
|
9
|
-
type WecomAppGroupPolicy = "open" | "allowlist" | "disabled";
|
|
10
8
|
/**
|
|
11
9
|
* 企业微信自建应用账户配置
|
|
12
10
|
* 相比普通 wecom 智能机器人,增加了 corpId, corpSecret, agentId 用于主动发送消息
|
|
@@ -28,6 +26,8 @@ type WecomAppAccountConfig = {
|
|
|
28
26
|
corpSecret?: string;
|
|
29
27
|
/** 应用 AgentId (用于主动发送) */
|
|
30
28
|
agentId?: number;
|
|
29
|
+
/** 企业微信 API 基础地址(可选,默认 https://qyapi.weixin.qq.com) */
|
|
30
|
+
apiBaseUrl?: string;
|
|
31
31
|
/** 入站媒体(图片/文件)落盘设置 */
|
|
32
32
|
inboundMedia?: {
|
|
33
33
|
/** 是否启用入站媒体落盘(默认 true) */
|
|
@@ -57,12 +57,6 @@ type WecomAppAccountConfig = {
|
|
|
57
57
|
dmPolicy?: WecomAppDmPolicy;
|
|
58
58
|
/** DM 允许列表 */
|
|
59
59
|
allowFrom?: string[];
|
|
60
|
-
/** 群组策略 */
|
|
61
|
-
groupPolicy?: WecomAppGroupPolicy;
|
|
62
|
-
/** 群组允许列表 */
|
|
63
|
-
groupAllowFrom?: string[];
|
|
64
|
-
/** 是否需要 @ 提及 */
|
|
65
|
-
requireMention?: boolean;
|
|
66
60
|
};
|
|
67
61
|
/**
|
|
68
62
|
* 企业微信自建应用配置 (顶层)
|
|
@@ -97,10 +91,8 @@ type ResolvedWecomAppAccount = {
|
|
|
97
91
|
};
|
|
98
92
|
/** 消息发送目标 */
|
|
99
93
|
type WecomAppSendTarget = {
|
|
100
|
-
/** 用户 ID
|
|
101
|
-
userId
|
|
102
|
-
/** 群聊 ID (与 userId 二选一) */
|
|
103
|
-
chatid?: string;
|
|
94
|
+
/** 用户 ID */
|
|
95
|
+
userId: string;
|
|
104
96
|
};
|
|
105
97
|
/** Access Token 缓存条目 */
|
|
106
98
|
type AccessTokenCacheEntry = {
|
|
@@ -111,8 +103,6 @@ type WecomAppInboundBase = {
|
|
|
111
103
|
MsgId?: string;
|
|
112
104
|
msgid?: string;
|
|
113
105
|
aibotid?: string;
|
|
114
|
-
chattype?: "single" | "group";
|
|
115
|
-
chatid?: string;
|
|
116
106
|
response_url?: string;
|
|
117
107
|
from?: {
|
|
118
108
|
userid?: string;
|
|
@@ -231,7 +221,7 @@ declare const wecomAppPlugin: {
|
|
|
231
221
|
order: 84;
|
|
232
222
|
};
|
|
233
223
|
capabilities: {
|
|
234
|
-
chatTypes: readonly ["direct"
|
|
224
|
+
chatTypes: readonly ["direct"];
|
|
235
225
|
media: boolean;
|
|
236
226
|
reactions: boolean;
|
|
237
227
|
threads: boolean;
|
|
@@ -273,6 +263,9 @@ declare const wecomAppPlugin: {
|
|
|
273
263
|
agentId: {
|
|
274
264
|
type: string;
|
|
275
265
|
};
|
|
266
|
+
apiBaseUrl: {
|
|
267
|
+
type: string;
|
|
268
|
+
};
|
|
276
269
|
inboundMedia: {
|
|
277
270
|
type: string;
|
|
278
271
|
additionalProperties: boolean;
|
|
@@ -317,19 +310,6 @@ declare const wecomAppPlugin: {
|
|
|
317
310
|
type: string;
|
|
318
311
|
};
|
|
319
312
|
};
|
|
320
|
-
groupPolicy: {
|
|
321
|
-
type: string;
|
|
322
|
-
enum: string[];
|
|
323
|
-
};
|
|
324
|
-
groupAllowFrom: {
|
|
325
|
-
type: string;
|
|
326
|
-
items: {
|
|
327
|
-
type: string;
|
|
328
|
-
};
|
|
329
|
-
};
|
|
330
|
-
requireMention: {
|
|
331
|
-
type: string;
|
|
332
|
-
};
|
|
333
313
|
maxFileSizeMB: {
|
|
334
314
|
type: string;
|
|
335
315
|
};
|
|
@@ -369,6 +349,9 @@ declare const wecomAppPlugin: {
|
|
|
369
349
|
agentId: {
|
|
370
350
|
type: string;
|
|
371
351
|
};
|
|
352
|
+
apiBaseUrl: {
|
|
353
|
+
type: string;
|
|
354
|
+
};
|
|
372
355
|
inboundMedia: {
|
|
373
356
|
type: string;
|
|
374
357
|
additionalProperties: boolean;
|
|
@@ -455,22 +438,13 @@ declare const wecomAppPlugin: {
|
|
|
455
438
|
allowFrom: (string | number)[];
|
|
456
439
|
}) => string[];
|
|
457
440
|
};
|
|
458
|
-
groups: {
|
|
459
|
-
resolveRequireMention: (params: {
|
|
460
|
-
cfg: PluginConfig;
|
|
461
|
-
accountId?: string;
|
|
462
|
-
account?: ResolvedWecomAppAccount;
|
|
463
|
-
}) => boolean;
|
|
464
|
-
};
|
|
465
441
|
/**
|
|
466
442
|
* 目录解析 - 用于将 wecom-app:XXX 格式的 target 解析为可投递目标
|
|
467
443
|
*
|
|
468
444
|
* 支持的输入格式:
|
|
469
445
|
* - "wecom-app:user:xxx" → { channel: "wecom-app", to: "user:xxx" }
|
|
470
|
-
* - "wecom-app:group:xxx" → { channel: "wecom-app", to: "group:xxx" }
|
|
471
446
|
* - "wecom-app:xxx" → { channel: "wecom-app", to: "user:xxx" }
|
|
472
447
|
* - "user:xxx" → { channel: "wecom-app", to: "user:xxx" }
|
|
473
|
-
* - "group:xxx" → { channel: "wecom-app", to: "group:xxx" }
|
|
474
448
|
* - "xxx" (裸ID) → { channel: "wecom-app", to: "user:xxx" }
|
|
475
449
|
* - 带 accountId: "user:xxx@account1" → { channel: "wecom-app", accountId: "account1", to: "user:xxx" }
|
|
476
450
|
*/
|
|
@@ -485,6 +459,13 @@ declare const wecomAppPlugin: {
|
|
|
485
459
|
/**
|
|
486
460
|
* 解析单个目标地址
|
|
487
461
|
* 将各种格式的 target 解析为可用的投递对象
|
|
462
|
+
*
|
|
463
|
+
* IMPORTANT: 返回的 `to` 字段必须是纯 ID(不含 user:/group: 前缀),
|
|
464
|
+
* 因为 OpenClaw 框架会用这个值来匹配 inbound context 中的 From/To 字段。
|
|
465
|
+
*
|
|
466
|
+
* 例如:如果 inbound context 的 From 是 "wecom-app:user:CaiHongYu",
|
|
467
|
+
* 那么 resolveTarget 必须返回 { channel: "wecom-app", to: "CaiHongYu" },
|
|
468
|
+
* 而不是 { channel: "wecom-app", to: "user:CaiHongYu" }。
|
|
488
469
|
*/
|
|
489
470
|
resolveTarget: (params: {
|
|
490
471
|
cfg: PluginConfig;
|
|
@@ -509,6 +490,9 @@ declare const wecomAppPlugin: {
|
|
|
509
490
|
/**
|
|
510
491
|
* 获取此通道支持的目标格式说明
|
|
511
492
|
* 用于帮助信息和错误提示
|
|
493
|
+
*
|
|
494
|
+
* 注意:虽然支持多种输入格式,但 resolveTarget 返回的 `to` 字段
|
|
495
|
+
* 始终是纯 ID(不含前缀),以便框架正确匹配 inbound context。
|
|
512
496
|
*/
|
|
513
497
|
getTargetFormats: () => string[];
|
|
514
498
|
};
|
|
@@ -582,6 +566,7 @@ interface PluginRuntime {
|
|
|
582
566
|
resolveAgentRoute?: (params: {
|
|
583
567
|
cfg: unknown;
|
|
584
568
|
channel: string;
|
|
569
|
+
accountId?: string;
|
|
585
570
|
peer: {
|
|
586
571
|
kind: string;
|
|
587
572
|
id: string;
|
|
@@ -709,7 +694,7 @@ type SendMessageResult = {
|
|
|
709
694
|
* 发送企业微信应用消息
|
|
710
695
|
*
|
|
711
696
|
* @param account - 已解析的账户配置
|
|
712
|
-
* @param target - 发送目标 (userId
|
|
697
|
+
* @param target - 发送目标 (userId)
|
|
713
698
|
* @param message - 消息内容 (会自动移除 Markdown 格式)
|
|
714
699
|
*/
|
|
715
700
|
declare function sendWecomAppMessage(account: ResolvedWecomAppAccount, target: WecomAppSendTarget, message: string): Promise<SendMessageResult>;
|
|
@@ -739,7 +724,6 @@ declare function downloadAndSendImage(account: ResolvedWecomAppAccount, target:
|
|
|
739
724
|
*
|
|
740
725
|
* 使用示例:
|
|
741
726
|
* - 私聊:sendWecomDM("caihongyu", { text: "Hello" })
|
|
742
|
-
* - 群聊:sendWecomGroup("wrkxxxxxxx", { text: "Hello" })
|
|
743
727
|
*/
|
|
744
728
|
|
|
745
729
|
/**
|
|
@@ -764,14 +748,12 @@ type SendResult = {
|
|
|
764
748
|
*
|
|
765
749
|
* 输入格式(用户侧传入):
|
|
766
750
|
* - 私聊:"caihongyu" 或 "user:caihongyu"
|
|
767
|
-
* -
|
|
768
|
-
* - 带 channel 前缀:"wecom-app:user:caihongyu" 或 "wecom-app:group:xxx"
|
|
751
|
+
* - 带 channel 前缀:"wecom-app:user:caihongyu"
|
|
769
752
|
*
|
|
770
753
|
* 输出格式(OpenClaw 标准):
|
|
771
754
|
* - 私聊:"user:caihongyu"
|
|
772
|
-
* - 群聊:"group:wrkxxxxxx"
|
|
773
755
|
*/
|
|
774
|
-
declare function normalizeTarget(target: string, type: "user"
|
|
756
|
+
declare function normalizeTarget(target: string, type: "user"): string;
|
|
775
757
|
/**
|
|
776
758
|
* 将规范化的 target 字符串解析为 WecomAppSendTarget
|
|
777
759
|
*/
|
|
@@ -800,31 +782,15 @@ declare function parseTarget(target: string): WecomAppSendTarget;
|
|
|
800
782
|
*/
|
|
801
783
|
declare function sendWecomDM(account: ResolvedWecomAppAccount, userId: string, options: SendMessageOptions): Promise<SendResult>;
|
|
802
784
|
/**
|
|
803
|
-
*
|
|
804
|
-
*
|
|
805
|
-
* @param account - 已解析的账户配置
|
|
806
|
-
* @param chatId - 群聊 ID(如 "wrkxxxxxx"),支持带 "group:" 前缀
|
|
807
|
-
* @param options - 消息选项
|
|
808
|
-
*
|
|
809
|
-
* @example
|
|
810
|
-
* ```ts
|
|
811
|
-
* // 发送文本
|
|
812
|
-
* await sendWecomGroup(account, "wrkxxxxxx", { text: "Hello group!" });
|
|
813
|
-
*
|
|
814
|
-
* // 发送图片
|
|
815
|
-
* await sendWecomGroup(account, "wrkxxxxxx", { mediaPath: "/path/to/image.jpg" });
|
|
816
|
-
* ```
|
|
817
|
-
*/
|
|
818
|
-
declare function sendWecomGroup(account: ResolvedWecomAppAccount, chatId: string, options: SendMessageOptions): Promise<SendResult>;
|
|
819
|
-
/**
|
|
820
|
-
* 发送消息(自动识别目标类型)
|
|
785
|
+
* 发送消息(自动识别目标格式)
|
|
821
786
|
*
|
|
822
|
-
*
|
|
823
|
-
* - "user:xxx"
|
|
824
|
-
* - "
|
|
787
|
+
* 支持多种 target 格式:
|
|
788
|
+
* - "user:xxx" → 私聊
|
|
789
|
+
* - "wecom-app:user:xxx" → 私聊(带 channel 前缀)
|
|
790
|
+
* - "xxx" → 私聊(裸 ID,默认当作用户)
|
|
825
791
|
*
|
|
826
792
|
* @param account - 已解析的账户配置
|
|
827
|
-
* @param target - 目标(支持 "user:xxx"、"
|
|
793
|
+
* @param target - 目标(支持 "user:xxx"、"wecom-app:user:xxx"、"xxx" 格式)
|
|
828
794
|
* @param options - 消息选项
|
|
829
795
|
*/
|
|
830
796
|
declare function sendWecom(account: ResolvedWecomAppAccount, target: string, options: SendMessageOptions): Promise<SendResult>;
|
|
@@ -865,4 +831,4 @@ declare const plugin: {
|
|
|
865
831
|
register(api: MoltbotPluginApi): void;
|
|
866
832
|
};
|
|
867
833
|
|
|
868
|
-
export { type AccessTokenCacheEntry, DEFAULT_ACCOUNT_ID, type MoltbotPluginApi, type ResolvedWecomAppAccount, type SendMessageOptions, type SendResult, type WecomAppConfig, type WecomAppDmPolicy, type
|
|
834
|
+
export { type AccessTokenCacheEntry, DEFAULT_ACCOUNT_ID, type MoltbotPluginApi, type ResolvedWecomAppAccount, type SendMessageOptions, type SendResult, type WecomAppConfig, type WecomAppDmPolicy, type WecomAppInboundMessage, type WecomAppSendTarget, clearAccessTokenCache, clearAllAccessTokenCache, plugin as default, downloadAndSendImage, getAccessToken, getWecomAppRuntime, normalizeTarget, parseTarget, sendWecom, sendWecomAppImageMessage, sendWecomAppMarkdownMessage, sendWecomAppMessage, sendWecomDM, setWecomAppRuntime, stripMarkdown, wecomAppPlugin };
|