@openclaw-china/wecom 0.1.1

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.
@@ -0,0 +1,52 @@
1
+ {
2
+ "id": "wecom",
3
+ "name": "WeCom",
4
+ "description": "企业微信消息渠道插件",
5
+ "version": "0.1.0",
6
+ "channels": ["wecom"],
7
+ "configSchema": {
8
+ "type": "object",
9
+ "additionalProperties": false,
10
+ "properties": {
11
+ "enabled": { "type": "boolean" },
12
+ "name": { "type": "string" },
13
+ "webhookPath": { "type": "string" },
14
+ "token": { "type": "string" },
15
+ "encodingAESKey": { "type": "string" },
16
+ "receiveId": { "type": "string" },
17
+ "welcomeText": { "type": "string" },
18
+ "dmPolicy": { "type": "string", "enum": ["open", "pairing", "allowlist", "disabled"] },
19
+ "allowFrom": { "type": "array", "items": { "type": "string" } },
20
+ "groupPolicy": { "type": "string", "enum": ["open", "allowlist", "disabled"] },
21
+ "groupAllowFrom": { "type": "array", "items": { "type": "string" } },
22
+ "requireMention": { "type": "boolean" },
23
+ "defaultAccount": { "type": "string" },
24
+ "accounts": {
25
+ "type": "object",
26
+ "additionalProperties": {
27
+ "type": "object",
28
+ "additionalProperties": false,
29
+ "properties": {
30
+ "name": { "type": "string" },
31
+ "enabled": { "type": "boolean" },
32
+ "webhookPath": { "type": "string" },
33
+ "token": { "type": "string" },
34
+ "encodingAESKey": { "type": "string" },
35
+ "receiveId": { "type": "string" },
36
+ "welcomeText": { "type": "string" },
37
+ "dmPolicy": { "type": "string", "enum": ["open", "pairing", "allowlist", "disabled"] },
38
+ "allowFrom": { "type": "array", "items": { "type": "string" } },
39
+ "groupPolicy": { "type": "string", "enum": ["open", "allowlist", "disabled"] },
40
+ "groupAllowFrom": { "type": "array", "items": { "type": "string" } },
41
+ "requireMention": { "type": "boolean" }
42
+ }
43
+ }
44
+ }
45
+ }
46
+ },
47
+ "uiHints": {
48
+ "token": { "label": "Token", "sensitive": true },
49
+ "encodingAESKey": { "label": "EncodingAESKey", "sensitive": true },
50
+ "webhookPath": { "label": "Webhook Path" }
51
+ }
52
+ }
@@ -0,0 +1,414 @@
1
+ import { IncomingMessage, ServerResponse } from 'http';
2
+
3
+ type WecomDmPolicy = "open" | "pairing" | "allowlist" | "disabled";
4
+ type WecomGroupPolicy = "open" | "allowlist" | "disabled";
5
+ type WecomAccountConfig = {
6
+ name?: string;
7
+ enabled?: boolean;
8
+ webhookPath?: string;
9
+ token?: string;
10
+ encodingAESKey?: string;
11
+ receiveId?: string;
12
+ welcomeText?: string;
13
+ dmPolicy?: WecomDmPolicy;
14
+ allowFrom?: string[];
15
+ groupPolicy?: WecomGroupPolicy;
16
+ groupAllowFrom?: string[];
17
+ requireMention?: boolean;
18
+ };
19
+ type WecomConfig = WecomAccountConfig & {
20
+ accounts?: Record<string, WecomAccountConfig>;
21
+ defaultAccount?: string;
22
+ };
23
+ type ResolvedWecomAccount = {
24
+ accountId: string;
25
+ name?: string;
26
+ enabled: boolean;
27
+ configured: boolean;
28
+ token?: string;
29
+ encodingAESKey?: string;
30
+ receiveId: string;
31
+ config: WecomAccountConfig;
32
+ };
33
+ type WecomInboundBase = {
34
+ msgid?: string;
35
+ aibotid?: string;
36
+ chattype?: "single" | "group";
37
+ chatid?: string;
38
+ response_url?: string;
39
+ from?: {
40
+ userid?: string;
41
+ corpid?: string;
42
+ };
43
+ msgtype?: string;
44
+ };
45
+ type WecomInboundText = WecomInboundBase & {
46
+ msgtype: "text";
47
+ text?: {
48
+ content?: string;
49
+ };
50
+ quote?: unknown;
51
+ };
52
+ type WecomInboundVoice = WecomInboundBase & {
53
+ msgtype: "voice";
54
+ voice?: {
55
+ content?: string;
56
+ };
57
+ quote?: unknown;
58
+ };
59
+ type WecomInboundStreamRefresh = WecomInboundBase & {
60
+ msgtype: "stream";
61
+ stream?: {
62
+ id?: string;
63
+ };
64
+ };
65
+ type WecomInboundEvent = WecomInboundBase & {
66
+ msgtype: "event";
67
+ create_time?: number;
68
+ event?: {
69
+ eventtype?: string;
70
+ [key: string]: unknown;
71
+ };
72
+ };
73
+ type WecomInboundMessage = WecomInboundText | WecomInboundVoice | WecomInboundStreamRefresh | WecomInboundEvent | (WecomInboundBase & Record<string, unknown>);
74
+
75
+ /** 默认账户 ID */
76
+ declare const DEFAULT_ACCOUNT_ID = "default";
77
+ interface PluginConfig {
78
+ session?: {
79
+ store?: unknown;
80
+ };
81
+ channels?: {
82
+ wecom?: WecomConfig;
83
+ };
84
+ }
85
+
86
+ /**
87
+ * 企业微信 ChannelPlugin 实现
88
+ */
89
+
90
+ declare const wecomPlugin: {
91
+ id: string;
92
+ meta: {
93
+ id: "wecom";
94
+ label: "WeCom";
95
+ selectionLabel: "WeCom (企业微信)";
96
+ docsPath: "/channels/wecom";
97
+ docsLabel: "wecom";
98
+ blurb: "企业微信智能机器人回调";
99
+ aliases: readonly ["wechatwork", "wework", "qywx", "企微", "企业微信"];
100
+ order: 85;
101
+ };
102
+ capabilities: {
103
+ chatTypes: readonly ["direct", "group"];
104
+ media: boolean;
105
+ reactions: boolean;
106
+ threads: boolean;
107
+ edit: boolean;
108
+ reply: boolean;
109
+ polls: boolean;
110
+ };
111
+ configSchema: {
112
+ schema: {
113
+ type: string;
114
+ additionalProperties: boolean;
115
+ properties: {
116
+ name: {
117
+ type: string;
118
+ };
119
+ enabled: {
120
+ type: string;
121
+ };
122
+ webhookPath: {
123
+ type: string;
124
+ };
125
+ token: {
126
+ type: string;
127
+ };
128
+ encodingAESKey: {
129
+ type: string;
130
+ };
131
+ receiveId: {
132
+ type: string;
133
+ };
134
+ welcomeText: {
135
+ type: string;
136
+ };
137
+ dmPolicy: {
138
+ type: string;
139
+ enum: string[];
140
+ };
141
+ allowFrom: {
142
+ type: string;
143
+ items: {
144
+ type: string;
145
+ };
146
+ };
147
+ groupPolicy: {
148
+ type: string;
149
+ enum: string[];
150
+ };
151
+ groupAllowFrom: {
152
+ type: string;
153
+ items: {
154
+ type: string;
155
+ };
156
+ };
157
+ requireMention: {
158
+ type: string;
159
+ };
160
+ defaultAccount: {
161
+ type: string;
162
+ };
163
+ accounts: {
164
+ type: string;
165
+ additionalProperties: {
166
+ type: string;
167
+ additionalProperties: boolean;
168
+ properties: {
169
+ name: {
170
+ type: string;
171
+ };
172
+ enabled: {
173
+ type: string;
174
+ };
175
+ webhookPath: {
176
+ type: string;
177
+ };
178
+ token: {
179
+ type: string;
180
+ };
181
+ encodingAESKey: {
182
+ type: string;
183
+ };
184
+ receiveId: {
185
+ type: string;
186
+ };
187
+ welcomeText: {
188
+ type: string;
189
+ };
190
+ dmPolicy: {
191
+ type: string;
192
+ enum: string[];
193
+ };
194
+ allowFrom: {
195
+ type: string;
196
+ items: {
197
+ type: string;
198
+ };
199
+ };
200
+ groupPolicy: {
201
+ type: string;
202
+ enum: string[];
203
+ };
204
+ groupAllowFrom: {
205
+ type: string;
206
+ items: {
207
+ type: string;
208
+ };
209
+ };
210
+ requireMention: {
211
+ type: string;
212
+ };
213
+ };
214
+ };
215
+ };
216
+ };
217
+ };
218
+ };
219
+ reload: {
220
+ configPrefixes: string[];
221
+ };
222
+ config: {
223
+ listAccountIds: (cfg: PluginConfig) => string[];
224
+ resolveAccount: (cfg: PluginConfig, accountId?: string) => ResolvedWecomAccount;
225
+ defaultAccountId: (cfg: PluginConfig) => string;
226
+ setAccountEnabled: (params: {
227
+ cfg: PluginConfig;
228
+ accountId?: string;
229
+ enabled: boolean;
230
+ }) => PluginConfig;
231
+ deleteAccount: (params: {
232
+ cfg: PluginConfig;
233
+ accountId?: string;
234
+ }) => PluginConfig;
235
+ isConfigured: (account: ResolvedWecomAccount) => boolean;
236
+ describeAccount: (account: ResolvedWecomAccount) => {
237
+ accountId: string;
238
+ name: string | undefined;
239
+ enabled: boolean;
240
+ configured: boolean;
241
+ webhookPath: string;
242
+ };
243
+ resolveAllowFrom: (params: {
244
+ cfg: PluginConfig;
245
+ accountId?: string;
246
+ }) => string[];
247
+ formatAllowFrom: (params: {
248
+ allowFrom: (string | number)[];
249
+ }) => string[];
250
+ };
251
+ groups: {
252
+ resolveRequireMention: (params: {
253
+ cfg: PluginConfig;
254
+ accountId?: string;
255
+ account?: ResolvedWecomAccount;
256
+ }) => boolean;
257
+ };
258
+ outbound: {
259
+ deliveryMode: string;
260
+ sendText: () => Promise<{
261
+ channel: string;
262
+ ok: boolean;
263
+ messageId: string;
264
+ error: Error;
265
+ }>;
266
+ };
267
+ gateway: {
268
+ startAccount: (ctx: {
269
+ cfg: PluginConfig;
270
+ runtime?: unknown;
271
+ abortSignal?: AbortSignal;
272
+ accountId: string;
273
+ setStatus?: (status: Record<string, unknown>) => void;
274
+ log?: {
275
+ info: (msg: string) => void;
276
+ error: (msg: string) => void;
277
+ };
278
+ }) => Promise<void>;
279
+ stopAccount: (ctx: {
280
+ accountId: string;
281
+ setStatus?: (status: Record<string, unknown>) => void;
282
+ }) => Promise<void>;
283
+ };
284
+ };
285
+
286
+ /**
287
+ * 企业微信插件运行时管理
288
+ */
289
+ interface PluginRuntime {
290
+ log?: (msg: string) => void;
291
+ error?: (msg: string) => void;
292
+ channel?: {
293
+ routing?: {
294
+ resolveAgentRoute?: (params: {
295
+ cfg: unknown;
296
+ channel: string;
297
+ peer: {
298
+ kind: string;
299
+ id: string;
300
+ };
301
+ }) => {
302
+ sessionKey: string;
303
+ accountId: string;
304
+ agentId?: string;
305
+ };
306
+ };
307
+ reply?: {
308
+ dispatchReplyFromConfig?: (params: {
309
+ ctx: unknown;
310
+ cfg: unknown;
311
+ dispatcher?: unknown;
312
+ replyOptions?: unknown;
313
+ }) => Promise<{
314
+ queuedFinal: boolean;
315
+ counts: {
316
+ final: number;
317
+ };
318
+ }>;
319
+ dispatchReplyWithBufferedBlockDispatcher?: (params: {
320
+ ctx: unknown;
321
+ cfg: unknown;
322
+ dispatcherOptions: {
323
+ deliver: (payload: {
324
+ text?: string;
325
+ }) => Promise<void>;
326
+ onError?: (err: unknown, info: {
327
+ kind: string;
328
+ }) => void;
329
+ };
330
+ }) => Promise<void>;
331
+ finalizeInboundContext?: (ctx: unknown) => unknown;
332
+ createReplyDispatcher?: (params: unknown) => unknown;
333
+ createReplyDispatcherWithTyping?: (params: unknown) => {
334
+ dispatcher: unknown;
335
+ replyOptions?: unknown;
336
+ markDispatchIdle?: () => void;
337
+ };
338
+ resolveHumanDelayConfig?: (cfg: unknown, agentId?: string) => unknown;
339
+ resolveEnvelopeFormatOptions?: (cfg: unknown) => unknown;
340
+ formatAgentEnvelope?: (params: {
341
+ channel: string;
342
+ from: string;
343
+ previousTimestamp?: number;
344
+ envelope?: unknown;
345
+ body: string;
346
+ }) => string;
347
+ };
348
+ session?: {
349
+ resolveStorePath?: (store: unknown, params: {
350
+ agentId?: string;
351
+ }) => string | undefined;
352
+ readSessionUpdatedAt?: (params: {
353
+ storePath?: string;
354
+ sessionKey: string;
355
+ }) => number | null;
356
+ recordInboundSession?: (params: {
357
+ storePath: string;
358
+ sessionKey: string;
359
+ ctx: unknown;
360
+ onRecordError?: (err: unknown) => void;
361
+ }) => Promise<void>;
362
+ };
363
+ text?: {
364
+ resolveMarkdownTableMode?: (params: {
365
+ cfg: unknown;
366
+ channel: string;
367
+ accountId?: string;
368
+ }) => unknown;
369
+ convertMarkdownTables?: (text: string, mode: unknown) => string;
370
+ };
371
+ };
372
+ system?: {
373
+ enqueueSystemEvent?: (message: string, options?: unknown) => void;
374
+ };
375
+ [key: string]: unknown;
376
+ }
377
+ declare function setWecomRuntime(next: PluginRuntime): void;
378
+ declare function getWecomRuntime(): PluginRuntime;
379
+
380
+ /**
381
+ * @openclaw-china/wecom
382
+ * 企业微信渠道插件入口
383
+ *
384
+ * 导出:
385
+ * - wecomPlugin: ChannelPlugin 实现
386
+ * - DEFAULT_ACCOUNT_ID: 默认账户 ID
387
+ * - setWecomRuntime: 设置 Moltbot 运行时
388
+ */
389
+
390
+ /**
391
+ * Moltbot 插件 API 接口
392
+ */
393
+ interface MoltbotPluginApi {
394
+ registerChannel: (opts: {
395
+ plugin: unknown;
396
+ }) => void;
397
+ registerHttpHandler?: (handler: (req: IncomingMessage, res: ServerResponse) => Promise<boolean> | boolean) => void;
398
+ runtime?: unknown;
399
+ [key: string]: unknown;
400
+ }
401
+
402
+ declare const plugin: {
403
+ id: string;
404
+ name: string;
405
+ description: string;
406
+ configSchema: {
407
+ type: string;
408
+ additionalProperties: boolean;
409
+ properties: {};
410
+ };
411
+ register(api: MoltbotPluginApi): void;
412
+ };
413
+
414
+ export { DEFAULT_ACCOUNT_ID, type MoltbotPluginApi, type ResolvedWecomAccount, type WecomConfig, type WecomInboundMessage, plugin as default, getWecomRuntime, setWecomRuntime, wecomPlugin };