@openclaw-china/dingtalk 0.1.0
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/clawdbot.plugin.json +28 -0
- package/dist/index.d.ts +607 -0
- package/moltbot.plugin.json +28 -0
- package/package.json +92 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "dingtalk",
|
|
3
|
+
"name": "DingTalk",
|
|
4
|
+
"description": "钉钉消息渠道插件",
|
|
5
|
+
"version": "0.1.1",
|
|
6
|
+
"channels": ["dingtalk"],
|
|
7
|
+
"configSchema": {
|
|
8
|
+
"type": "object",
|
|
9
|
+
"additionalProperties": false,
|
|
10
|
+
"properties": {
|
|
11
|
+
"enabled": { "type": "boolean" },
|
|
12
|
+
"clientId": { "type": "string" },
|
|
13
|
+
"clientSecret": { "type": "string" },
|
|
14
|
+
"connectionMode": { "type": "string", "enum": ["stream", "webhook"] },
|
|
15
|
+
"dmPolicy": { "type": "string", "enum": ["open", "pairing", "allowlist"] },
|
|
16
|
+
"groupPolicy": { "type": "string", "enum": ["open", "allowlist", "disabled"] },
|
|
17
|
+
"requireMention": { "type": "boolean" },
|
|
18
|
+
"allowFrom": { "type": "array", "items": { "type": "string" } },
|
|
19
|
+
"groupAllowFrom": { "type": "array", "items": { "type": "string" } },
|
|
20
|
+
"historyLimit": { "type": "integer", "minimum": 0 },
|
|
21
|
+
"textChunkLimit": { "type": "integer", "minimum": 1 }
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"uiHints": {
|
|
25
|
+
"clientId": { "label": "Client ID (AppKey)" },
|
|
26
|
+
"clientSecret": { "label": "Client Secret (AppSecret)", "sensitive": true }
|
|
27
|
+
}
|
|
28
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
var __createBinding = (undefined && undefined.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __exportStar = (undefined && undefined.__exportStar) || function(m, exports$1) {
|
|
13
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports$1, p)) __createBinding(exports$1, m, p);
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
__exportStar(require("./errors.cjs"), exports);
|
|
17
|
+
__exportStar(require("./helpers/parseUtil.cjs"), exports);
|
|
18
|
+
__exportStar(require("./helpers/typeAliases.cjs"), exports);
|
|
19
|
+
__exportStar(require("./helpers/util.cjs"), exports);
|
|
20
|
+
__exportStar(require("./types.cjs"), exports);
|
|
21
|
+
__exportStar(require("./ZodError.cjs"), exports);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 钉钉渠道配置 Schema
|
|
25
|
+
*
|
|
26
|
+
* 配置字段说明:
|
|
27
|
+
* - enabled: 是否启用该渠道
|
|
28
|
+
* - clientId: 钉钉应用的 AppKey
|
|
29
|
+
* - clientSecret: 钉钉应用的 AppSecret
|
|
30
|
+
* - dmPolicy: 单聊策略 (open=开放, pairing=配对, allowlist=白名单)
|
|
31
|
+
* - groupPolicy: 群聊策略 (open=开放, allowlist=白名单, disabled=禁用)
|
|
32
|
+
* - requireMention: 群聊是否需要 @机器人
|
|
33
|
+
* - allowFrom: 单聊白名单用户 ID 列表
|
|
34
|
+
* - groupAllowFrom: 群聊白名单会话 ID 列表
|
|
35
|
+
* - historyLimit: 历史消息数量限制
|
|
36
|
+
* - textChunkLimit: 文本分块大小限制
|
|
37
|
+
*/
|
|
38
|
+
declare const DingtalkConfigSchema: undefined<{
|
|
39
|
+
/** 是否启用钉钉渠道 */
|
|
40
|
+
enabled: undefined<undefined<undefined>>;
|
|
41
|
+
/** 钉钉应用 AppKey (clientId) */
|
|
42
|
+
clientId: undefined<undefined>;
|
|
43
|
+
/** 钉钉应用 AppSecret (clientSecret) */
|
|
44
|
+
clientSecret: undefined<undefined>;
|
|
45
|
+
/** 单聊策略: open=开放, pairing=配对, allowlist=白名单 */
|
|
46
|
+
dmPolicy: undefined<undefined<undefined<["open", "pairing", "allowlist"]>>>;
|
|
47
|
+
/** 群聊策略: open=开放, allowlist=白名单, disabled=禁用 */
|
|
48
|
+
groupPolicy: undefined<undefined<undefined<["open", "allowlist", "disabled"]>>>;
|
|
49
|
+
/** 群聊是否需要 @机器人才响应 */
|
|
50
|
+
requireMention: undefined<undefined<undefined>>;
|
|
51
|
+
/** 单聊白名单: 允许的用户 ID 列表 */
|
|
52
|
+
allowFrom: undefined<undefined<undefined, "many">>;
|
|
53
|
+
/** 群聊白名单: 允许的会话 ID 列表 */
|
|
54
|
+
groupAllowFrom: undefined<undefined<undefined, "many">>;
|
|
55
|
+
/** 历史消息数量限制 */
|
|
56
|
+
historyLimit: undefined<undefined<undefined>>;
|
|
57
|
+
/** 文本分块大小限制 (钉钉单条消息最大 4000 字符) */
|
|
58
|
+
textChunkLimit: undefined<undefined<undefined>>;
|
|
59
|
+
}, "strip", undefined, {
|
|
60
|
+
enabled: boolean;
|
|
61
|
+
dmPolicy: "open" | "pairing" | "allowlist";
|
|
62
|
+
groupPolicy: "open" | "allowlist" | "disabled";
|
|
63
|
+
requireMention: boolean;
|
|
64
|
+
historyLimit: number;
|
|
65
|
+
textChunkLimit: number;
|
|
66
|
+
clientId?: string | undefined;
|
|
67
|
+
clientSecret?: string | undefined;
|
|
68
|
+
allowFrom?: string[] | undefined;
|
|
69
|
+
groupAllowFrom?: string[] | undefined;
|
|
70
|
+
}, {
|
|
71
|
+
enabled?: boolean | undefined;
|
|
72
|
+
clientId?: string | undefined;
|
|
73
|
+
clientSecret?: string | undefined;
|
|
74
|
+
dmPolicy?: "open" | "pairing" | "allowlist" | undefined;
|
|
75
|
+
groupPolicy?: "open" | "allowlist" | "disabled" | undefined;
|
|
76
|
+
requireMention?: boolean | undefined;
|
|
77
|
+
allowFrom?: string[] | undefined;
|
|
78
|
+
groupAllowFrom?: string[] | undefined;
|
|
79
|
+
historyLimit?: number | undefined;
|
|
80
|
+
textChunkLimit?: number | undefined;
|
|
81
|
+
}>;
|
|
82
|
+
type DingtalkConfig = undefined<typeof DingtalkConfigSchema>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 发送消息结果
|
|
86
|
+
*/
|
|
87
|
+
interface DingtalkSendResult {
|
|
88
|
+
/** 消息 ID */
|
|
89
|
+
messageId: string;
|
|
90
|
+
/** 会话 ID */
|
|
91
|
+
conversationId: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 解析后的钉钉账户配置
|
|
95
|
+
* 用于 ChannelPlugin config 适配器
|
|
96
|
+
*/
|
|
97
|
+
interface ResolvedDingtalkAccount {
|
|
98
|
+
/** 账户 ID */
|
|
99
|
+
accountId: string;
|
|
100
|
+
/** 是否启用 */
|
|
101
|
+
enabled: boolean;
|
|
102
|
+
/** 是否已配置(有凭证) */
|
|
103
|
+
configured: boolean;
|
|
104
|
+
/** 客户端 ID */
|
|
105
|
+
clientId?: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 钉钉出站适配器
|
|
110
|
+
*
|
|
111
|
+
* 实现 ChannelOutboundAdapter 接口,提供:
|
|
112
|
+
* - sendText: 发送文本消息
|
|
113
|
+
* - sendMedia: 发送媒体消息(含回退逻辑)
|
|
114
|
+
* - chunker: 长消息分块(利用 Moltbot 核心的 markdown-aware 分块)
|
|
115
|
+
*
|
|
116
|
+
* 配置:
|
|
117
|
+
* - deliveryMode: "direct" (直接发送,不使用队列)
|
|
118
|
+
* - textChunkLimit: 4000 (钉钉 Markdown 消息最大字符数)
|
|
119
|
+
* - chunkerMode: "markdown" (使用 markdown 感知的分块模式)
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 出站适配器配置类型
|
|
124
|
+
* 简化版本,仅包含必要字段
|
|
125
|
+
*/
|
|
126
|
+
interface OutboundConfig {
|
|
127
|
+
channels?: {
|
|
128
|
+
dingtalk?: DingtalkConfig;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 发送结果类型
|
|
133
|
+
*/
|
|
134
|
+
interface SendResult {
|
|
135
|
+
channel: string;
|
|
136
|
+
messageId: string;
|
|
137
|
+
chatId?: string;
|
|
138
|
+
conversationId?: string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** 默认账户 ID */
|
|
142
|
+
declare const DEFAULT_ACCOUNT_ID = "default";
|
|
143
|
+
/**
|
|
144
|
+
* 配置接口类型(简化版)
|
|
145
|
+
*/
|
|
146
|
+
interface PluginConfig {
|
|
147
|
+
channels?: {
|
|
148
|
+
dingtalk?: DingtalkConfig;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* 钉钉渠道插件
|
|
153
|
+
*
|
|
154
|
+
* 实现 ChannelPlugin 接口,提供完整的钉钉消息渠道功能
|
|
155
|
+
*/
|
|
156
|
+
declare const dingtalkPlugin: {
|
|
157
|
+
id: string;
|
|
158
|
+
/**
|
|
159
|
+
* 渠道元数据
|
|
160
|
+
* Requirements: 1.2
|
|
161
|
+
*/
|
|
162
|
+
meta: {
|
|
163
|
+
id: "dingtalk";
|
|
164
|
+
label: "DingTalk";
|
|
165
|
+
selectionLabel: "DingTalk (钉钉)";
|
|
166
|
+
docsPath: "/channels/dingtalk";
|
|
167
|
+
docsLabel: "dingtalk";
|
|
168
|
+
blurb: "钉钉企业消息";
|
|
169
|
+
aliases: readonly ["ding"];
|
|
170
|
+
order: 71;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* 渠道能力声明
|
|
174
|
+
* Requirements: 1.3
|
|
175
|
+
*/
|
|
176
|
+
capabilities: {
|
|
177
|
+
chatTypes: readonly ["direct", "channel"];
|
|
178
|
+
media: boolean;
|
|
179
|
+
reactions: boolean;
|
|
180
|
+
threads: boolean;
|
|
181
|
+
edit: boolean;
|
|
182
|
+
reply: boolean;
|
|
183
|
+
polls: boolean;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* 配置 Schema
|
|
187
|
+
* Requirements: 1.4
|
|
188
|
+
*/
|
|
189
|
+
configSchema: {
|
|
190
|
+
schema: {
|
|
191
|
+
type: string;
|
|
192
|
+
additionalProperties: boolean;
|
|
193
|
+
properties: {
|
|
194
|
+
enabled: {
|
|
195
|
+
type: string;
|
|
196
|
+
};
|
|
197
|
+
clientId: {
|
|
198
|
+
type: string;
|
|
199
|
+
};
|
|
200
|
+
clientSecret: {
|
|
201
|
+
type: string;
|
|
202
|
+
};
|
|
203
|
+
dmPolicy: {
|
|
204
|
+
type: string;
|
|
205
|
+
enum: string[];
|
|
206
|
+
};
|
|
207
|
+
groupPolicy: {
|
|
208
|
+
type: string;
|
|
209
|
+
enum: string[];
|
|
210
|
+
};
|
|
211
|
+
requireMention: {
|
|
212
|
+
type: string;
|
|
213
|
+
};
|
|
214
|
+
allowFrom: {
|
|
215
|
+
type: string;
|
|
216
|
+
items: {
|
|
217
|
+
type: string;
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
groupAllowFrom: {
|
|
221
|
+
type: string;
|
|
222
|
+
items: {
|
|
223
|
+
type: string;
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
historyLimit: {
|
|
227
|
+
type: string;
|
|
228
|
+
minimum: number;
|
|
229
|
+
};
|
|
230
|
+
textChunkLimit: {
|
|
231
|
+
type: string;
|
|
232
|
+
minimum: number;
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* 配置重载触发器
|
|
239
|
+
*/
|
|
240
|
+
reload: {
|
|
241
|
+
configPrefixes: string[];
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* 账户配置适配器
|
|
245
|
+
* Requirements: 2.1, 2.2, 2.3
|
|
246
|
+
*/
|
|
247
|
+
config: {
|
|
248
|
+
/**
|
|
249
|
+
* 列出所有账户 ID
|
|
250
|
+
* Requirements: 2.1
|
|
251
|
+
*/
|
|
252
|
+
listAccountIds: (_cfg: PluginConfig) => string[];
|
|
253
|
+
/**
|
|
254
|
+
* 解析账户配置
|
|
255
|
+
* Requirements: 2.2
|
|
256
|
+
*/
|
|
257
|
+
resolveAccount: (cfg: PluginConfig, accountId?: string) => ResolvedDingtalkAccount;
|
|
258
|
+
/**
|
|
259
|
+
* 获取默认账户 ID
|
|
260
|
+
*/
|
|
261
|
+
defaultAccountId: () => string;
|
|
262
|
+
/**
|
|
263
|
+
* 设置账户启用状态
|
|
264
|
+
*/
|
|
265
|
+
setAccountEnabled: (params: {
|
|
266
|
+
cfg: PluginConfig;
|
|
267
|
+
enabled: boolean;
|
|
268
|
+
}) => PluginConfig;
|
|
269
|
+
/**
|
|
270
|
+
* 删除账户配置
|
|
271
|
+
*/
|
|
272
|
+
deleteAccount: (params: {
|
|
273
|
+
cfg: PluginConfig;
|
|
274
|
+
}) => PluginConfig;
|
|
275
|
+
/**
|
|
276
|
+
* 检查账户是否已配置
|
|
277
|
+
* Requirements: 2.3
|
|
278
|
+
*/
|
|
279
|
+
isConfigured: (_account: ResolvedDingtalkAccount, cfg: PluginConfig) => boolean;
|
|
280
|
+
/**
|
|
281
|
+
* 描述账户信息
|
|
282
|
+
*/
|
|
283
|
+
describeAccount: (account: ResolvedDingtalkAccount) => {
|
|
284
|
+
accountId: string;
|
|
285
|
+
enabled: boolean;
|
|
286
|
+
configured: boolean;
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* 解析白名单
|
|
290
|
+
*/
|
|
291
|
+
resolveAllowFrom: (params: {
|
|
292
|
+
cfg: PluginConfig;
|
|
293
|
+
}) => string[];
|
|
294
|
+
/**
|
|
295
|
+
* 格式化白名单条目
|
|
296
|
+
*/
|
|
297
|
+
formatAllowFrom: (params: {
|
|
298
|
+
allowFrom: (string | number)[];
|
|
299
|
+
}) => string[];
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* 安全警告收集器
|
|
303
|
+
*/
|
|
304
|
+
security: {
|
|
305
|
+
collectWarnings: (params: {
|
|
306
|
+
cfg: PluginConfig;
|
|
307
|
+
}) => string[];
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* 设置向导适配器
|
|
311
|
+
*/
|
|
312
|
+
setup: {
|
|
313
|
+
resolveAccountId: () => string;
|
|
314
|
+
applyAccountConfig: (params: {
|
|
315
|
+
cfg: PluginConfig;
|
|
316
|
+
}) => PluginConfig;
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* 出站消息适配器
|
|
320
|
+
* Requirements: 7.1, 7.6
|
|
321
|
+
*/
|
|
322
|
+
outbound: {
|
|
323
|
+
deliveryMode: "direct";
|
|
324
|
+
textChunkLimit: number;
|
|
325
|
+
chunkerMode: "markdown";
|
|
326
|
+
chunker: (text: string, limit: number) => string[];
|
|
327
|
+
sendText: (params: {
|
|
328
|
+
cfg: OutboundConfig;
|
|
329
|
+
to: string;
|
|
330
|
+
text: string;
|
|
331
|
+
}) => Promise<SendResult>;
|
|
332
|
+
sendMedia: (params: {
|
|
333
|
+
cfg: OutboundConfig;
|
|
334
|
+
to: string;
|
|
335
|
+
text?: string;
|
|
336
|
+
mediaUrl?: string;
|
|
337
|
+
}) => Promise<SendResult>;
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* Gateway 连接管理适配器
|
|
341
|
+
* Requirements: 3.1
|
|
342
|
+
*/
|
|
343
|
+
gateway: {
|
|
344
|
+
/**
|
|
345
|
+
* 启动账户连接
|
|
346
|
+
* Requirements: 3.1
|
|
347
|
+
*/
|
|
348
|
+
startAccount: (ctx: {
|
|
349
|
+
cfg: PluginConfig;
|
|
350
|
+
runtime?: unknown;
|
|
351
|
+
abortSignal?: AbortSignal;
|
|
352
|
+
accountId: string;
|
|
353
|
+
setStatus?: (status: Record<string, unknown>) => void;
|
|
354
|
+
log?: {
|
|
355
|
+
info: (msg: string) => void;
|
|
356
|
+
error: (msg: string) => void;
|
|
357
|
+
};
|
|
358
|
+
}) => Promise<void>;
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* 钉钉发送消息 API
|
|
364
|
+
*
|
|
365
|
+
* 提供:
|
|
366
|
+
* - sendMessageDingtalk: 发送 Markdown 消息(单聊/群聊)
|
|
367
|
+
*
|
|
368
|
+
* API 文档:
|
|
369
|
+
* - 单聊: https://open.dingtalk.com/document/orgapp/chatbots-send-one-on-one-chat-messages-in-batches
|
|
370
|
+
* - 群聊: https://open.dingtalk.com/document/orgapp/the-robot-sends-a-group-message
|
|
371
|
+
*/
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* 发送消息参数
|
|
375
|
+
*/
|
|
376
|
+
interface SendMessageParams {
|
|
377
|
+
/** 钉钉配置 */
|
|
378
|
+
cfg: DingtalkConfig;
|
|
379
|
+
/** 目标 ID(用户 ID 或会话 ID) */
|
|
380
|
+
to: string;
|
|
381
|
+
/** 消息文本内容 */
|
|
382
|
+
text: string;
|
|
383
|
+
/** 聊天类型 */
|
|
384
|
+
chatType: "direct" | "group";
|
|
385
|
+
/** Markdown 消息标题(可选) */
|
|
386
|
+
title?: string;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* 发送 Markdown 消息到钉钉
|
|
390
|
+
*
|
|
391
|
+
* 根据 chatType 调用不同的 API:
|
|
392
|
+
* - direct: /v1.0/robot/oToMessages/batchSend (单聊批量发送)
|
|
393
|
+
* - group: /v1.0/robot/groupMessages/send (群聊发送)
|
|
394
|
+
*
|
|
395
|
+
* 始终使用 sampleMarkdown 模板,支持表格、代码块等格式
|
|
396
|
+
*
|
|
397
|
+
* @param params 发送参数
|
|
398
|
+
* @returns 发送结果
|
|
399
|
+
* @throws Error 如果凭证未配置或 API 调用失败
|
|
400
|
+
*/
|
|
401
|
+
declare function sendMessageDingtalk(params: SendMessageParams): Promise<DingtalkSendResult>;
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* 钉钉插件运行时管理
|
|
405
|
+
*
|
|
406
|
+
* 提供对 Moltbot 核心运行时的访问。
|
|
407
|
+
*
|
|
408
|
+
* 重要:这个模块存储完整的 PluginRuntime,包含 core.channel.routing、
|
|
409
|
+
* core.channel.reply 等 API,用于消息分发到 Agent。
|
|
410
|
+
*
|
|
411
|
+
* 使用方式:
|
|
412
|
+
* 1. 插件注册时调用 setDingtalkRuntime(runtime) 设置完整 runtime
|
|
413
|
+
* 2. 消息处理时调用 getDingtalkRuntime() 获取 runtime 进行分发
|
|
414
|
+
*/
|
|
415
|
+
/**
|
|
416
|
+
* Moltbot 插件运行时接口
|
|
417
|
+
*
|
|
418
|
+
* 包含 Moltbot 核心 API,用于:
|
|
419
|
+
* - 路由解析 (channel.routing.resolveAgentRoute)
|
|
420
|
+
* - 消息分发 (channel.reply.dispatchReplyFromConfig)
|
|
421
|
+
* - 系统事件 (system.enqueueSystemEvent)
|
|
422
|
+
*/
|
|
423
|
+
interface PluginRuntime {
|
|
424
|
+
/** 日志函数 */
|
|
425
|
+
log?: (msg: string) => void;
|
|
426
|
+
/** 错误日志函数 */
|
|
427
|
+
error?: (msg: string) => void;
|
|
428
|
+
/** Moltbot 核心 API */
|
|
429
|
+
channel?: {
|
|
430
|
+
routing?: {
|
|
431
|
+
resolveAgentRoute?: (params: {
|
|
432
|
+
cfg: unknown;
|
|
433
|
+
channel: string;
|
|
434
|
+
peer: {
|
|
435
|
+
kind: string;
|
|
436
|
+
id: string;
|
|
437
|
+
};
|
|
438
|
+
}) => {
|
|
439
|
+
sessionKey: string;
|
|
440
|
+
accountId: string;
|
|
441
|
+
agentId?: string;
|
|
442
|
+
};
|
|
443
|
+
};
|
|
444
|
+
reply?: {
|
|
445
|
+
dispatchReplyFromConfig?: (params: {
|
|
446
|
+
ctx: unknown;
|
|
447
|
+
cfg: unknown;
|
|
448
|
+
dispatcher?: unknown;
|
|
449
|
+
replyOptions?: unknown;
|
|
450
|
+
}) => Promise<{
|
|
451
|
+
queuedFinal: boolean;
|
|
452
|
+
counts: {
|
|
453
|
+
final: number;
|
|
454
|
+
};
|
|
455
|
+
}>;
|
|
456
|
+
finalizeInboundContext?: (ctx: unknown) => unknown;
|
|
457
|
+
createReplyDispatcher?: (params: unknown) => unknown;
|
|
458
|
+
createReplyDispatcherWithTyping?: (params: unknown) => {
|
|
459
|
+
dispatcher: unknown;
|
|
460
|
+
replyOptions?: unknown;
|
|
461
|
+
markDispatchIdle?: () => void;
|
|
462
|
+
};
|
|
463
|
+
resolveHumanDelayConfig?: (cfg: unknown, agentId?: string) => unknown;
|
|
464
|
+
resolveEnvelopeFormatOptions?: (cfg: unknown) => unknown;
|
|
465
|
+
formatAgentEnvelope?: (params: unknown) => string;
|
|
466
|
+
};
|
|
467
|
+
text?: {
|
|
468
|
+
resolveTextChunkLimit?: (params: {
|
|
469
|
+
cfg: unknown;
|
|
470
|
+
channel: string;
|
|
471
|
+
defaultLimit?: number;
|
|
472
|
+
}) => number;
|
|
473
|
+
resolveChunkMode?: (cfg: unknown, channel: string) => unknown;
|
|
474
|
+
resolveMarkdownTableMode?: (params: {
|
|
475
|
+
cfg: unknown;
|
|
476
|
+
channel: string;
|
|
477
|
+
}) => unknown;
|
|
478
|
+
convertMarkdownTables?: (text: string, mode: unknown) => string;
|
|
479
|
+
chunkTextWithMode?: (text: string, limit: number, mode: unknown) => string[];
|
|
480
|
+
/** Markdown 感知的文本分块,不会在代码块中间断开 */
|
|
481
|
+
chunkMarkdownText?: (text: string, limit: number) => string[];
|
|
482
|
+
};
|
|
483
|
+
};
|
|
484
|
+
system?: {
|
|
485
|
+
enqueueSystemEvent?: (message: string, options?: unknown) => void;
|
|
486
|
+
};
|
|
487
|
+
[key: string]: unknown;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* 设置钉钉插件运行时
|
|
491
|
+
*
|
|
492
|
+
* 在插件注册时由 Moltbot 调用,传入完整的 PluginRuntime。
|
|
493
|
+
*
|
|
494
|
+
* @param next Moltbot 插件运行时实例(完整版,包含 core API)
|
|
495
|
+
*/
|
|
496
|
+
declare function setDingtalkRuntime(next: PluginRuntime): void;
|
|
497
|
+
/**
|
|
498
|
+
* 获取钉钉插件运行时
|
|
499
|
+
*
|
|
500
|
+
* 在消息处理时调用,获取完整的 runtime 用于分发消息到 Agent。
|
|
501
|
+
*
|
|
502
|
+
* @returns Moltbot 插件运行时实例
|
|
503
|
+
* @throws Error 如果运行时未初始化(插件未正确注册)
|
|
504
|
+
*/
|
|
505
|
+
declare function getDingtalkRuntime(): PluginRuntime;
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* @openclaw-china/dingtalk
|
|
509
|
+
* 钉钉渠道插件入口
|
|
510
|
+
*
|
|
511
|
+
* 导出:
|
|
512
|
+
* - dingtalkPlugin: ChannelPlugin 实现
|
|
513
|
+
* - sendMessageDingtalk: 发送消息函数
|
|
514
|
+
* - DEFAULT_ACCOUNT_ID: 默认账户 ID
|
|
515
|
+
*
|
|
516
|
+
* Requirements: 1.1
|
|
517
|
+
*/
|
|
518
|
+
/**
|
|
519
|
+
* Moltbot 插件 API 接口
|
|
520
|
+
*
|
|
521
|
+
* 包含:
|
|
522
|
+
* - registerChannel: 注册渠道插件
|
|
523
|
+
* - runtime: 完整的 Moltbot 运行时(包含 core API)
|
|
524
|
+
*/
|
|
525
|
+
interface MoltbotPluginApi {
|
|
526
|
+
registerChannel: (opts: {
|
|
527
|
+
plugin: unknown;
|
|
528
|
+
}) => void;
|
|
529
|
+
/** Moltbot 运行时,包含 channel.routing、channel.reply 等核心 API */
|
|
530
|
+
runtime?: unknown;
|
|
531
|
+
[key: string]: unknown;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* 钉钉插件定义
|
|
536
|
+
*
|
|
537
|
+
* 包含:
|
|
538
|
+
* - id: 插件标识符
|
|
539
|
+
* - name: 插件名称
|
|
540
|
+
* - description: 插件描述
|
|
541
|
+
* - configSchema: 配置 JSON Schema
|
|
542
|
+
* - register: 注册函数,调用 api.registerChannel 并设置 runtime
|
|
543
|
+
*
|
|
544
|
+
* Requirements: 1.1
|
|
545
|
+
*/
|
|
546
|
+
declare const plugin: {
|
|
547
|
+
id: string;
|
|
548
|
+
name: string;
|
|
549
|
+
description: string;
|
|
550
|
+
configSchema: {
|
|
551
|
+
type: string;
|
|
552
|
+
additionalProperties: boolean;
|
|
553
|
+
properties: {
|
|
554
|
+
enabled: {
|
|
555
|
+
type: string;
|
|
556
|
+
};
|
|
557
|
+
clientId: {
|
|
558
|
+
type: string;
|
|
559
|
+
};
|
|
560
|
+
clientSecret: {
|
|
561
|
+
type: string;
|
|
562
|
+
};
|
|
563
|
+
dmPolicy: {
|
|
564
|
+
type: string;
|
|
565
|
+
enum: string[];
|
|
566
|
+
};
|
|
567
|
+
groupPolicy: {
|
|
568
|
+
type: string;
|
|
569
|
+
enum: string[];
|
|
570
|
+
};
|
|
571
|
+
requireMention: {
|
|
572
|
+
type: string;
|
|
573
|
+
};
|
|
574
|
+
allowFrom: {
|
|
575
|
+
type: string;
|
|
576
|
+
items: {
|
|
577
|
+
type: string;
|
|
578
|
+
};
|
|
579
|
+
};
|
|
580
|
+
groupAllowFrom: {
|
|
581
|
+
type: string;
|
|
582
|
+
items: {
|
|
583
|
+
type: string;
|
|
584
|
+
};
|
|
585
|
+
};
|
|
586
|
+
historyLimit: {
|
|
587
|
+
type: string;
|
|
588
|
+
minimum: number;
|
|
589
|
+
};
|
|
590
|
+
textChunkLimit: {
|
|
591
|
+
type: string;
|
|
592
|
+
minimum: number;
|
|
593
|
+
};
|
|
594
|
+
};
|
|
595
|
+
};
|
|
596
|
+
/**
|
|
597
|
+
* 注册钉钉渠道插件
|
|
598
|
+
*
|
|
599
|
+
* 1. 设置完整的 Moltbot 运行时(包含 core API)
|
|
600
|
+
* 2. 调用 api.registerChannel 将 dingtalkPlugin 注册到 Moltbot
|
|
601
|
+
*
|
|
602
|
+
* Requirements: 1.1
|
|
603
|
+
*/
|
|
604
|
+
register(api: MoltbotPluginApi): void;
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
export { DEFAULT_ACCOUNT_ID, type DingtalkConfig, type DingtalkSendResult, type MoltbotPluginApi, type ResolvedDingtalkAccount, plugin as default, dingtalkPlugin, getDingtalkRuntime, sendMessageDingtalk, setDingtalkRuntime };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "dingtalk",
|
|
3
|
+
"name": "DingTalk",
|
|
4
|
+
"description": "钉钉消息渠道插件",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"channels": ["dingtalk"],
|
|
7
|
+
"configSchema": {
|
|
8
|
+
"type": "object",
|
|
9
|
+
"additionalProperties": false,
|
|
10
|
+
"properties": {
|
|
11
|
+
"enabled": { "type": "boolean" },
|
|
12
|
+
"clientId": { "type": "string" },
|
|
13
|
+
"clientSecret": { "type": "string" },
|
|
14
|
+
"connectionMode": { "type": "string", "enum": ["stream", "webhook"] },
|
|
15
|
+
"dmPolicy": { "type": "string", "enum": ["open", "pairing", "allowlist"] },
|
|
16
|
+
"groupPolicy": { "type": "string", "enum": ["open", "allowlist", "disabled"] },
|
|
17
|
+
"requireMention": { "type": "boolean" },
|
|
18
|
+
"allowFrom": { "type": "array", "items": { "type": "string" } },
|
|
19
|
+
"groupAllowFrom": { "type": "array", "items": { "type": "string" } },
|
|
20
|
+
"historyLimit": { "type": "integer", "minimum": 0 },
|
|
21
|
+
"textChunkLimit": { "type": "integer", "minimum": 1 }
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"uiHints": {
|
|
25
|
+
"clientId": { "label": "Client ID (AppKey)" },
|
|
26
|
+
"clientSecret": { "label": "Client Secret (AppSecret)", "sensitive": true }
|
|
27
|
+
}
|
|
28
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openclaw-china/dingtalk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Moltbot DingTalk channel plugin",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"moltbot.plugin.json",
|
|
10
|
+
"clawdbot.plugin.json"
|
|
11
|
+
],
|
|
12
|
+
"moltbot": {
|
|
13
|
+
"extensions": [
|
|
14
|
+
"./dist/index.js"
|
|
15
|
+
],
|
|
16
|
+
"channel": {
|
|
17
|
+
"id": "dingtalk",
|
|
18
|
+
"label": "DingTalk",
|
|
19
|
+
"selectionLabel": "DingTalk (钉钉)",
|
|
20
|
+
"docsPath": "/channels/dingtalk",
|
|
21
|
+
"blurb": "钉钉企业消息",
|
|
22
|
+
"aliases": [
|
|
23
|
+
"ding"
|
|
24
|
+
],
|
|
25
|
+
"order": 71
|
|
26
|
+
},
|
|
27
|
+
"install": {
|
|
28
|
+
"npmSpec": "@openclaw-china/dingtalk",
|
|
29
|
+
"localPath": ".",
|
|
30
|
+
"defaultChoice": "npm"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"clawdbot": {
|
|
34
|
+
"extensions": [
|
|
35
|
+
"./dist/index.js"
|
|
36
|
+
],
|
|
37
|
+
"channel": {
|
|
38
|
+
"id": "dingtalk",
|
|
39
|
+
"label": "DingTalk",
|
|
40
|
+
"selectionLabel": "DingTalk (钉钉)",
|
|
41
|
+
"docsPath": "/channels/dingtalk",
|
|
42
|
+
"blurb": "钉钉企业消息",
|
|
43
|
+
"aliases": [
|
|
44
|
+
"ding"
|
|
45
|
+
],
|
|
46
|
+
"order": 71
|
|
47
|
+
},
|
|
48
|
+
"install": {
|
|
49
|
+
"npmSpec": "@openclaw-china/dingtalk",
|
|
50
|
+
"localPath": ".",
|
|
51
|
+
"defaultChoice": "npm"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"main": "./dist/index.js",
|
|
55
|
+
"types": "./dist/index.d.ts",
|
|
56
|
+
"exports": {
|
|
57
|
+
".": {
|
|
58
|
+
"types": "./dist/index.d.ts",
|
|
59
|
+
"default": "./dist/index.js"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsup",
|
|
64
|
+
"dev": "tsup --watch",
|
|
65
|
+
"test": "vitest --run",
|
|
66
|
+
"test:watch": "vitest",
|
|
67
|
+
"release": "npm run build && npm publish",
|
|
68
|
+
"release:patch": "npm run build && npm version patch && npm publish",
|
|
69
|
+
"release:minor": "npm run build && npm version minor && npm publish",
|
|
70
|
+
"release:major": "npm run build && npm version major && npm publish"
|
|
71
|
+
},
|
|
72
|
+
"dependencies": {
|
|
73
|
+
"@openclaw-china/shared": "0.1.0",
|
|
74
|
+
"dingtalk-stream": "^2.1.4"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"@types/node": "^22.0.0",
|
|
78
|
+
"fast-check": "^3.22.0",
|
|
79
|
+
"tsup": "^8.2.0",
|
|
80
|
+
"typescript": "^5.7.0",
|
|
81
|
+
"vitest": "^2.1.0",
|
|
82
|
+
"zod": "^3.23.0"
|
|
83
|
+
},
|
|
84
|
+
"peerDependencies": {
|
|
85
|
+
"moltbot": ">=0.1.0"
|
|
86
|
+
},
|
|
87
|
+
"peerDependenciesMeta": {
|
|
88
|
+
"moltbot": {
|
|
89
|
+
"optional": true
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|