@chen0825/aiapp-ability 0.1.0 → 0.1.2

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.
Files changed (64) hide show
  1. package/lib/abilities/dingtalk/index.d.ts +92 -0
  2. package/lib/abilities/dingtalk/index.js +242 -0
  3. package/{src/abilities/index.ts → lib/abilities/index.d.ts} +0 -1
  4. package/lib/abilities/index.js +21 -0
  5. package/lib/abilities/registry.d.ts +69 -0
  6. package/lib/abilities/registry.js +111 -0
  7. package/lib/core/environment.d.ts +47 -0
  8. package/lib/core/environment.js +51 -0
  9. package/lib/core/http-client.d.ts +16 -0
  10. package/lib/core/http-client.js +77 -0
  11. package/{src/core/index.ts → lib/core/index.d.ts} +0 -1
  12. package/lib/core/index.js +21 -0
  13. package/lib/index.d.ts +8 -0
  14. package/lib/index.js +30 -0
  15. package/lib/types/dingtalk.d.ts +80 -0
  16. package/lib/types/dingtalk.js +5 -0
  17. package/{src/types/index.ts → lib/types/index.d.ts} +8 -12
  18. package/lib/types/index.js +21 -0
  19. package/lib/utils/index.js +1 -0
  20. package/package.json +9 -7
  21. package/ali-aiapp-ability-0.1.0.tgz +0 -0
  22. package/coverage/clover.xml +0 -226
  23. package/coverage/coverage-final.json +0 -12
  24. package/coverage/lcov-report/abilities/dingtalk/get-access-token.ts.html +0 -244
  25. package/coverage/lcov-report/abilities/dingtalk/get-user-info.ts.html +0 -253
  26. package/coverage/lcov-report/abilities/dingtalk/index.html +0 -146
  27. package/coverage/lcov-report/abilities/dingtalk/send-message.ts.html +0 -259
  28. package/coverage/lcov-report/abilities/index.html +0 -116
  29. package/coverage/lcov-report/abilities/registry.ts.html +0 -484
  30. package/coverage/lcov-report/base.css +0 -224
  31. package/coverage/lcov-report/block-navigation.js +0 -87
  32. package/coverage/lcov-report/favicon.png +0 -0
  33. package/coverage/lcov-report/index.html +0 -176
  34. package/coverage/lcov-report/prettify.css +0 -1
  35. package/coverage/lcov-report/prettify.js +0 -2
  36. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  37. package/coverage/lcov-report/sorter.js +0 -210
  38. package/coverage/lcov-report/src/abilities/dingtalk/get-access-token.ts.html +0 -244
  39. package/coverage/lcov-report/src/abilities/dingtalk/get-user-info.ts.html +0 -253
  40. package/coverage/lcov-report/src/abilities/dingtalk/index.html +0 -161
  41. package/coverage/lcov-report/src/abilities/dingtalk/index.ts.html +0 -106
  42. package/coverage/lcov-report/src/abilities/dingtalk/send-message.ts.html +0 -259
  43. package/coverage/lcov-report/src/abilities/index.html +0 -131
  44. package/coverage/lcov-report/src/abilities/index.ts.html +0 -103
  45. package/coverage/lcov-report/src/abilities/registry.ts.html +0 -484
  46. package/coverage/lcov-report/src/core/environment.ts.html +0 -241
  47. package/coverage/lcov-report/src/core/http-client.ts.html +0 -430
  48. package/coverage/lcov-report/src/core/index.html +0 -146
  49. package/coverage/lcov-report/src/core/index.ts.html +0 -103
  50. package/coverage/lcov-report/src/index.html +0 -116
  51. package/coverage/lcov-report/src/index.ts.html +0 -268
  52. package/coverage/lcov-report/src/utils/index.html +0 -116
  53. package/coverage/lcov-report/src/utils/index.ts.html +0 -385
  54. package/coverage/lcov-report/utils/index.html +0 -116
  55. package/coverage/lcov-report/utils/index.ts.html +0 -385
  56. package/coverage/lcov.info +0 -397
  57. package/src/abilities/dingtalk/index.ts +0 -311
  58. package/src/abilities/registry.ts +0 -134
  59. package/src/core/environment.ts +0 -79
  60. package/src/core/http-client.ts +0 -88
  61. package/src/index.ts +0 -17
  62. package/src/types/dingtalk.ts +0 -91
  63. package/tsconfig.tsbuildinfo +0 -1
  64. /package/{src/utils/index.ts → lib/utils/index.d.ts} +0 -0
@@ -1,397 +0,0 @@
1
- TN:
2
- SF:src/index.ts
3
- FN:32,registerDingtalkAbilities
4
- FN:41,createAbilityContext
5
- FN:54,initAbilityRegistry
6
- FNF:3
7
- FNH:3
8
- FNDA:3,registerDingtalkAbilities
9
- FNDA:2,createAbilityContext
10
- FNDA:2,initAbilityRegistry
11
- DA:7,1
12
- DA:10,1
13
- DA:13,1
14
- DA:16,1
15
- DA:19,1
16
- DA:24,1
17
- DA:25,1
18
- DA:26,1
19
- DA:32,1
20
- DA:33,3
21
- DA:34,3
22
- DA:35,3
23
- DA:41,1
24
- DA:45,2
25
- DA:54,1
26
- DA:58,2
27
- DA:59,2
28
- DA:60,2
29
- LF:18
30
- LH:18
31
- BRDA:32,0,0,0
32
- BRF:1
33
- BRH:0
34
- end_of_record
35
- TN:
36
- SF:src/abilities/index.ts
37
- FNF:0
38
- FNH:0
39
- DA:5,1
40
- DA:6,1
41
- LF:2
42
- LH:2
43
- BRF:0
44
- BRH:0
45
- end_of_record
46
- TN:
47
- SF:src/abilities/registry.ts
48
- FN:14,(anonymous_0)
49
- FN:26,(anonymous_1)
50
- FN:38,(anonymous_2)
51
- FN:48,(anonymous_3)
52
- FN:60,(anonymous_4)
53
- FN:87,(anonymous_5)
54
- FN:94,(anonymous_6)
55
- FN:101,(anonymous_7)
56
- FN:109,(anonymous_8)
57
- FN:120,(anonymous_9)
58
- FN:125,(anonymous_10)
59
- FNF:11
60
- FNH:11
61
- FNDA:26,(anonymous_0)
62
- FNDA:28,(anonymous_1)
63
- FNDA:1,(anonymous_2)
64
- FNDA:5,(anonymous_3)
65
- FNDA:3,(anonymous_4)
66
- FNDA:13,(anonymous_5)
67
- FNDA:3,(anonymous_6)
68
- FNDA:1,(anonymous_7)
69
- FNDA:2,(anonymous_8)
70
- FNDA:1,(anonymous_9)
71
- FNDA:33,(anonymous_10)
72
- DA:10,2
73
- DA:11,26
74
- DA:15,26
75
- DA:27,28
76
- DA:28,1
77
- DA:30,27
78
- DA:31,27
79
- DA:39,1
80
- DA:40,2
81
- DA:51,5
82
- DA:65,3
83
- DA:66,3
84
- DA:67,1
85
- DA:70,2
86
- DA:71,2
87
- DA:73,2
88
- DA:74,2
89
- DA:75,1
90
- DA:76,1
91
- DA:78,1
92
- DA:79,1
93
- DA:88,13
94
- DA:95,3
95
- DA:102,1
96
- DA:110,2
97
- DA:111,2
98
- DA:112,1
99
- DA:114,2
100
- DA:121,1
101
- DA:122,1
102
- DA:126,33
103
- DA:127,4
104
- DA:133,2
105
- LF:33
106
- LH:33
107
- BRDA:14,0,0,23
108
- BRDA:27,1,0,1
109
- BRDA:66,2,0,1
110
- BRDA:111,3,0,1
111
- BRDA:126,4,0,4
112
- BRF:5
113
- BRH:5
114
- end_of_record
115
- TN:
116
- SF:src/abilities/dingtalk/get-access-token.ts
117
- FN:26,(anonymous_0)
118
- FNF:1
119
- FNH:1
120
- FNDA:3,(anonymous_0)
121
- DA:13,2
122
- DA:18,2
123
- DA:30,3
124
- DA:32,3
125
- DA:44,2
126
- DA:45,1
127
- DA:48,1
128
- LF:7
129
- LH:7
130
- BRDA:44,0,0,1
131
- BRF:1
132
- BRH:1
133
- end_of_record
134
- TN:
135
- SF:src/abilities/dingtalk/get-user-info.ts
136
- FN:23,(anonymous_0)
137
- FNF:1
138
- FNH:1
139
- FNDA:4,(anonymous_0)
140
- DA:13,2
141
- DA:18,2
142
- DA:24,4
143
- DA:26,4
144
- DA:44,3
145
- DA:45,1
146
- DA:48,2
147
- LF:7
148
- LH:7
149
- BRDA:44,0,0,1
150
- BRF:1
151
- BRH:1
152
- end_of_record
153
- TN:
154
- SF:src/abilities/dingtalk/index.ts
155
- FNF:0
156
- FNH:0
157
- DA:5,1
158
- DA:6,1
159
- DA:7,1
160
- LF:3
161
- LH:3
162
- BRF:0
163
- BRH:0
164
- end_of_record
165
- TN:
166
- SF:src/abilities/dingtalk/send-message.ts
167
- FN:24,(anonymous_0)
168
- FNF:1
169
- FNH:1
170
- FNDA:6,(anonymous_0)
171
- DA:11,2
172
- DA:16,2
173
- DA:28,6
174
- DA:29,6
175
- DA:32,6
176
- DA:33,1
177
- DA:34,1
178
- DA:35,1
179
- DA:36,1
180
- DA:39,6
181
- DA:40,6
182
- DA:45,4
183
- DA:51,2
184
- LF:13
185
- LH:13
186
- BRDA:32,0,0,1
187
- BRDA:35,1,0,1
188
- BRDA:35,1,1,0
189
- BRDA:54,2,0,1
190
- BRDA:54,2,1,1
191
- BRF:5
192
- BRH:4
193
- end_of_record
194
- TN:
195
- SF:src/core/environment.ts
196
- FN:18,getEnvironment
197
- FN:26,setEnvironment
198
- FN:36,resetEnvironment
199
- FN:43,isProduction
200
- FN:50,isDevelopment
201
- FNF:5
202
- FNH:1
203
- FNDA:2,getEnvironment
204
- FNDA:0,setEnvironment
205
- FNDA:0,resetEnvironment
206
- FNDA:0,isProduction
207
- FNDA:0,isDevelopment
208
- DA:8,1
209
- DA:13,1
210
- DA:18,1
211
- DA:19,2
212
- DA:26,1
213
- DA:27,0
214
- DA:36,1
215
- DA:37,0
216
- DA:43,1
217
- DA:44,0
218
- DA:50,1
219
- DA:51,0
220
- LF:12
221
- LH:8
222
- BRF:0
223
- BRH:0
224
- end_of_record
225
- TN:
226
- SF:src/core/http-client.ts
227
- FN:21,createHttpClient
228
- FN:24,request
229
- FN:46,(anonymous_2)
230
- FN:73,(anonymous_3)
231
- FN:74,(anonymous_4)
232
- FN:76,(anonymous_5)
233
- FN:78,(anonymous_6)
234
- FN:86,buildUrl
235
- FN:104,(anonymous_8)
236
- FNF:9
237
- FNH:1
238
- FNDA:3,createHttpClient
239
- FNDA:0,request
240
- FNDA:0,(anonymous_2)
241
- FNDA:0,(anonymous_3)
242
- FNDA:0,(anonymous_4)
243
- FNDA:0,(anonymous_5)
244
- FNDA:0,(anonymous_6)
245
- FNDA:0,buildUrl
246
- FNDA:0,(anonymous_8)
247
- DA:21,1
248
- DA:22,3
249
- DA:30,0
250
- DA:32,0
251
- DA:41,0
252
- DA:42,0
253
- DA:45,0
254
- DA:46,0
255
- DA:47,0
256
- DA:49,0
257
- DA:50,0
258
- DA:51,0
259
- DA:53,0
260
- DA:54,0
261
- DA:57,0
262
- DA:58,0
263
- DA:59,0
264
- DA:62,0
265
- DA:64,0
266
- DA:65,0
267
- DA:66,0
268
- DA:68,0
269
- DA:72,3
270
- DA:73,0
271
- DA:75,0
272
- DA:77,0
273
- DA:79,0
274
- DA:87,0
275
- DA:88,0
276
- DA:91,0
277
- DA:92,0
278
- DA:93,0
279
- DA:96,0
280
- DA:97,0
281
- DA:103,1
282
- DA:105,0
283
- DA:106,0
284
- DA:107,0
285
- DA:109,0
286
- DA:110,0
287
- DA:115,1
288
- LF:41
289
- LH:5
290
- BRDA:21,0,0,2
291
- BRDA:22,1,0,2
292
- BRDA:22,2,0,2
293
- BRDA:22,3,0,3
294
- BRDA:28,4,0,0
295
- BRDA:41,5,0,0
296
- BRDA:41,6,0,0
297
- BRDA:41,6,1,0
298
- BRDA:46,7,0,0
299
- BRDA:46,7,1,0
300
- BRDA:53,8,0,0
301
- BRDA:58,9,0,0
302
- BRDA:65,10,0,0
303
- BRDA:65,11,0,0
304
- BRDA:65,11,1,0
305
- BRDA:87,12,0,0
306
- BRDA:87,13,0,0
307
- BRDA:87,13,1,0
308
- BRDA:96,14,0,0
309
- BRDA:96,14,1,0
310
- BRF:20
311
- BRH:4
312
- end_of_record
313
- TN:
314
- SF:src/core/index.ts
315
- FNF:0
316
- FNH:0
317
- DA:5,1
318
- DA:6,1
319
- LF:2
320
- LH:2
321
- BRF:0
322
- BRH:0
323
- end_of_record
324
- TN:
325
- SF:src/utils/index.ts
326
- FN:12,generateDingtalkSign
327
- FN:22,getTimestamp
328
- FN:30,delay
329
- FN:31,(anonymous_12)
330
- FN:40,retry
331
- FN:66,safeParseJSON
332
- FN:78,deepClone
333
- FN:86,isEmpty
334
- FNF:8
335
- FNH:8
336
- FNDA:5,generateDingtalkSign
337
- FNDA:1,getTimestamp
338
- FNDA:5,delay
339
- FNDA:5,(anonymous_12)
340
- FNDA:3,retry
341
- FNDA:3,safeParseJSON
342
- FNDA:2,deepClone
343
- FNDA:11,isEmpty
344
- DA:5,2
345
- DA:12,2
346
- DA:13,5
347
- DA:14,5
348
- DA:15,5
349
- DA:16,5
350
- DA:22,2
351
- DA:23,1
352
- DA:30,2
353
- DA:31,5
354
- DA:40,2
355
- DA:47,3
356
- DA:48,7
357
- DA:49,7
358
- DA:51,5
359
- DA:52,5
360
- DA:53,4
361
- DA:58,1
362
- DA:66,2
363
- DA:67,3
364
- DA:68,3
365
- DA:70,1
366
- DA:78,2
367
- DA:79,2
368
- DA:86,2
369
- DA:87,11
370
- DA:88,2
371
- DA:90,9
372
- DA:91,2
373
- DA:93,7
374
- DA:94,1
375
- DA:96,6
376
- DA:97,1
377
- DA:99,5
378
- LF:34
379
- LH:34
380
- BRDA:42,0,0,0
381
- BRDA:43,1,0,0
382
- BRDA:52,2,0,4
383
- BRDA:87,3,0,2
384
- BRDA:87,4,0,11
385
- BRDA:87,4,1,10
386
- BRDA:90,5,0,2
387
- BRDA:90,6,0,9
388
- BRDA:90,6,1,3
389
- BRDA:93,7,0,1
390
- BRDA:93,8,0,7
391
- BRDA:93,8,1,2
392
- BRDA:96,9,0,1
393
- BRDA:96,10,0,6
394
- BRDA:96,10,1,3
395
- BRF:15
396
- BRH:13
397
- end_of_record
@@ -1,311 +0,0 @@
1
- /**
2
- * 钉钉能力模块
3
- */
4
-
5
- import { HttpClient } from '../../core/http-client';
6
- import { getDingTalkEnvConfig } from '../../core/environment';
7
- import {
8
- BatchSendRobotMsgRequest,
9
- BatchSendResponse,
10
- RobotMsgKey,
11
- GetAccessTokenResponse,
12
- } from '../../types/dingtalk';
13
- import { AbilityProvider } from '../../types';
14
-
15
- /** 钉钉API批量发送限制:每次最多20人 */
16
- const BATCH_SEND_LIMIT = 20;
17
-
18
- /**
19
- * 简化的 Markdown 通知参数
20
- */
21
- export interface MarkdownNotificationParams {
22
- /** 接收者用户 ID 列表 */
23
- userIds: string[];
24
- /** 消息标题 */
25
- title: string;
26
- /** Markdown 格式的消息内容 */
27
- text: string;
28
- }
29
-
30
- /**
31
- * 通用批量发送参数
32
- */
33
- export interface BatchNotificationParams<T extends RobotMsgKey = RobotMsgKey> {
34
- /** 接收者用户 ID 列表 */
35
- userIds: string[];
36
- /** 消息类型 */
37
- msgKey: T;
38
- /** 消息参数 */
39
- msgParam: Record<string, unknown>;
40
- }
41
-
42
- /**
43
- * 钉钉能力提供者
44
- *
45
- * 必须配置以下环境变量:
46
- * - DINGTALK_APP_KEY: 钉钉应用 AppKey
47
- * - DINGTALK_APP_SECRET: 钉钉应用 AppSecret
48
- * - DINGTALK_ROBOT_CODE: 钉钉机器人编码
49
- * - DINGTALK_API_URL: 钉钉 API 基础 URL
50
- */
51
- export class DingTalkProvider implements AbilityProvider {
52
- public readonly name = 'dingtalk';
53
- public readonly version = '1.0.0';
54
-
55
- private dingtalkApiClient: HttpClient;
56
-
57
- constructor() {
58
- const envConfig = getDingTalkEnvConfig();
59
- this.dingtalkApiClient = new HttpClient(envConfig.apiUrl);
60
- }
61
-
62
- /**
63
- * 获取 appKey
64
- */
65
- private getAppKey(): string | undefined {
66
- return getDingTalkEnvConfig().appKey;
67
- }
68
-
69
- /**
70
- * 获取 appSecret
71
- */
72
- private getAppSecret(): string | undefined {
73
- return getDingTalkEnvConfig().appSecret;
74
- }
75
-
76
- /**
77
- * 获取机器人编码
78
- */
79
- private getRobotCode(): string | undefined {
80
- return getDingTalkEnvConfig().robotCode;
81
- }
82
-
83
- /**
84
- * 获取 API 基础 URL
85
- */
86
- private getApiUrl(): string {
87
- return getDingTalkEnvConfig().apiUrl;
88
- }
89
-
90
- /**
91
- * 获取企业内部应用的 accessToken(每次调用都重新获取)
92
- */
93
- async getAccessToken(): Promise<{ success: boolean; accessToken?: string; message?: string }> {
94
- const appKey = this.getAppKey();
95
- const appSecret = this.getAppSecret();
96
-
97
- if (!appKey || !appSecret) {
98
- return {
99
- success: false,
100
- message: '未配置环境变量 DINGTALK_APP_KEY 或 DINGTALK_APP_SECRET',
101
- };
102
- }
103
-
104
- try {
105
- const response = await fetch(`${this.getApiUrl()}/v1.0/oauth2/accessToken`, {
106
- method: 'POST',
107
- headers: {
108
- 'Content-Type': 'application/json',
109
- },
110
- body: JSON.stringify({ appKey, appSecret }),
111
- });
112
-
113
- if (!response.ok) {
114
- const errorText = await response.text();
115
- console.error('获取 accessToken 失败:', errorText);
116
- return {
117
- success: false,
118
- message: `获取 accessToken 失败: ${response.status}`,
119
- };
120
- }
121
-
122
- const data: GetAccessTokenResponse = await response.json();
123
-
124
- if (!data.accessToken) {
125
- return {
126
- success: false,
127
- message: '获取 accessToken 失败: 响应中无 accessToken',
128
- };
129
- }
130
-
131
- return {
132
- success: true,
133
- accessToken: data.accessToken,
134
- };
135
- } catch (error) {
136
- console.error('获取 accessToken 异常:', error);
137
- return {
138
- success: false,
139
- message: error instanceof Error ? error.message : '获取 accessToken 异常',
140
- };
141
- }
142
- }
143
-
144
- /**
145
- * 批量发送机器人消息
146
- */
147
- async batchSendRobotMessage<T extends RobotMsgKey>(
148
- params: BatchSendRobotMsgRequest<T>,
149
- ): Promise<BatchSendResponse> {
150
- const tokenResult = await this.getAccessToken();
151
- if (!tokenResult.success || !tokenResult.accessToken) {
152
- return {
153
- success: false,
154
- message: tokenResult.message || '获取 accessToken 失败',
155
- };
156
- }
157
-
158
- if (!params.userIds || params.userIds.length === 0) {
159
- return {
160
- success: false,
161
- message: '接收者列表不能为空',
162
- };
163
- }
164
-
165
- if (params.userIds.length > BATCH_SEND_LIMIT) {
166
- return this.batchSendInChunks(params);
167
- }
168
-
169
- try {
170
- const result = await this.dingtalkApiClient.post<any>(
171
- '/v1.0/robot/oToMessages/batchSend',
172
- params,
173
- {
174
- headers: {
175
- 'x-acs-dingtalk-access-token': tokenResult.accessToken,
176
- },
177
- },
178
- );
179
-
180
- if (!result.success) {
181
- return {
182
- success: false,
183
- message: result.message || '批量发送机器人消息失败',
184
- data: result.data,
185
- };
186
- }
187
-
188
- return {
189
- success: true,
190
- message: '批量发送成功',
191
- data: result.data,
192
- successCount: params.userIds.length,
193
- failCount: 0,
194
- };
195
- } catch (error) {
196
- console.error('批量发送机器人消息异常:', error);
197
- return {
198
- success: false,
199
- message: error instanceof Error ? error.message : '批量发送机器人消息异常',
200
- failedUserIds: params.userIds,
201
- };
202
- }
203
- }
204
-
205
- /**
206
- * 分批发送机器人消息(超过20人时自动分批)
207
- */
208
- private async batchSendInChunks<T extends RobotMsgKey>(
209
- params: BatchSendRobotMsgRequest<T>,
210
- ): Promise<BatchSendResponse> {
211
- const { userIds, ...restParams } = params;
212
- const chunks = this.chunkArray(userIds, BATCH_SEND_LIMIT);
213
- const failedUserIds: string[] = [];
214
- let successCount = 0;
215
- let failCount = 0;
216
-
217
- for (const chunk of chunks) {
218
- const chunkParams: BatchSendRobotMsgRequest<T> = {
219
- ...restParams,
220
- userIds: chunk,
221
- } as BatchSendRobotMsgRequest<T>;
222
-
223
- const result = await this.batchSendRobotMessage(chunkParams);
224
-
225
- if (result.success) {
226
- successCount += chunk.length;
227
- } else {
228
- failCount += chunk.length;
229
- failedUserIds.push(...chunk);
230
- }
231
- }
232
-
233
- const allSuccess = failCount === 0;
234
- return {
235
- success: allSuccess,
236
- message: allSuccess
237
- ? `批量发送成功,共 ${successCount} 人`
238
- : `部分发送失败,成功 ${successCount} 人,失败 ${failCount} 人`,
239
- successCount,
240
- failCount,
241
- failedUserIds: failedUserIds.length > 0 ? failedUserIds : undefined,
242
- };
243
- }
244
-
245
- /**
246
- * 发送 Markdown 消息
247
- */
248
- async sendMarkdownMessage(params: MarkdownNotificationParams): Promise<BatchSendResponse> {
249
- const robotCode = this.getRobotCode();
250
- if (!robotCode) {
251
- return {
252
- success: false,
253
- message: '未配置环境变量 DINGTALK_ROBOT_CODE',
254
- };
255
- }
256
-
257
- return this.batchSendRobotMessage({
258
- robotCode,
259
- userIds: params.userIds,
260
- msgKey: 'sampleMarkdown',
261
- msgParam: JSON.stringify({
262
- title: params.title,
263
- text: params.text,
264
- }),
265
- });
266
- }
267
-
268
- /**
269
- * 通用批量发送接口
270
- */
271
- async sendBatchNotification<T extends RobotMsgKey>(
272
- params: BatchNotificationParams<T>,
273
- ): Promise<BatchSendResponse> {
274
- const robotCode = this.getRobotCode();
275
- if (!robotCode) {
276
- return {
277
- success: false,
278
- message: '未配置环境变量 DINGTALK_ROBOT_CODE',
279
- };
280
- }
281
-
282
- return this.batchSendRobotMessage({
283
- robotCode,
284
- userIds: params.userIds,
285
- msgKey: params.msgKey,
286
- msgParam: JSON.stringify(params.msgParam),
287
- });
288
- }
289
-
290
- /**
291
- * 初始化(重新加载环境变量配置)
292
- */
293
- async initialize(): Promise<void> {
294
- const envConfig = getDingTalkEnvConfig();
295
- this.dingtalkApiClient = new HttpClient(envConfig.apiUrl);
296
- }
297
-
298
- /**
299
- * 将数组分割成指定大小的块
300
- */
301
- private chunkArray<T>(array: T[], size: number): T[][] {
302
- const chunks: T[][] = [];
303
- for (let i = 0; i < array.length; i += size) {
304
- chunks.push(array.slice(i, i + size));
305
- }
306
- return chunks;
307
- }
308
- }
309
-
310
- /** 默认钉钉提供者实例 */
311
- export const dingtalkProvider = new DingTalkProvider();