@satorijs/adapter-dingtalk 2.0.3 → 2.0.5
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/lib/bot.d.ts +1 -1
- package/lib/http.d.ts +3 -2
- package/lib/index.js +35 -14
- package/lib/index.js.map +2 -3
- package/package.json +8 -4
- package/src/api/.eslintrc.yml +2 -0
- package/src/api/alitrip.ts +467 -0
- package/src/api/attendance.ts +81 -0
- package/src/api/badge.ts +285 -0
- package/src/api/blackboard.ts +28 -0
- package/src/api/calendar.ts +817 -0
- package/src/api/card.ts +215 -0
- package/src/api/conference.ts +561 -0
- package/src/api/connector.ts +97 -0
- package/src/api/contact.ts +56 -0
- package/src/api/convFile.ts +166 -0
- package/src/api/crm.ts +830 -0
- package/src/api/customerService.ts +156 -0
- package/src/api/datacenter.ts +672 -0
- package/src/api/devicemng.ts +202 -0
- package/src/api/diot.ts +19 -0
- package/src/api/doc.ts +232 -0
- package/src/api/drive.ts +109 -0
- package/src/api/edu.ts +30 -0
- package/src/api/esign.ts +44 -0
- package/src/api/exclusive.ts +372 -0
- package/src/api/h3yun.ts +537 -0
- package/src/api/hrm.ts +272 -0
- package/src/api/im.ts +978 -0
- package/src/api/industry.ts +153 -0
- package/src/api/jzcrm.ts +304 -0
- package/src/api/link.ts +94 -0
- package/src/api/live.ts +162 -0
- package/src/api/microApp.ts +309 -0
- package/src/api/oapi.ts +4083 -0
- package/src/api/oauth2.ts +146 -0
- package/src/api/pedia.ts +222 -0
- package/src/api/project.ts +1519 -0
- package/src/api/resident.ts +133 -0
- package/src/api/robot.ts +326 -0
- package/src/api/rooms.ts +334 -0
- package/src/api/serviceGroup.ts +216 -0
- package/src/api/storage.ts +1701 -0
- package/src/api/swform.ts +94 -0
- package/src/api/todo.ts +220 -0
- package/src/api/wiki.ts +231 -0
- package/src/api/workbench.ts +73 -0
- package/src/api/yida.ts +2165 -0
- package/src/bot.ts +129 -0
- package/src/http.ts +44 -0
- package/src/index.ts +9 -0
- package/src/internal.ts +47 -0
- package/src/message.ts +141 -0
- package/src/types/index.ts +140 -0
- package/src/utils.ts +53 -0
- package/src/ws.ts +55 -0
package/lib/bot.d.ts
CHANGED
package/lib/http.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Adapter, Context
|
|
1
|
+
import { Adapter, Context } from '@satorijs/satori';
|
|
2
2
|
import { DingtalkBot } from './bot';
|
|
3
3
|
export declare class HttpServer<C extends Context = Context> extends Adapter<C, DingtalkBot<C>> {
|
|
4
4
|
static inject: string[];
|
|
5
|
-
logger
|
|
5
|
+
private logger;
|
|
6
|
+
constructor(ctx: C, bot: DingtalkBot<C>);
|
|
6
7
|
connect(bot: DingtalkBot<C>): Promise<void>;
|
|
7
8
|
}
|
package/lib/index.js
CHANGED
|
@@ -61,10 +61,12 @@ async function decodeMessage(bot, body) {
|
|
|
61
61
|
session.guildId = body.chatbotCorpId;
|
|
62
62
|
if (body.conversationType === "1") {
|
|
63
63
|
session.channelId = session.userId;
|
|
64
|
+
session.isDirect = true;
|
|
64
65
|
} else {
|
|
65
66
|
const atUsers = body.atUsers.filter((v) => v.dingtalkId !== body.chatbotUserId).map((v) => import_satori.h.at(v.staffId));
|
|
66
|
-
session.elements = [import_satori.h.at(body.robotCode), ...atUsers
|
|
67
|
+
session.elements = [import_satori.h.at(body.robotCode), ...atUsers];
|
|
67
68
|
session.channelId = body.conversationId;
|
|
69
|
+
session.isDirect = false;
|
|
68
70
|
}
|
|
69
71
|
if (body.conversationTitle) {
|
|
70
72
|
session.event.channel.name = body.conversationTitle;
|
|
@@ -104,7 +106,11 @@ __name(decodeMessage, "decodeMessage");
|
|
|
104
106
|
|
|
105
107
|
// satori/adapters/dingtalk/src/http.ts
|
|
106
108
|
var _HttpServer = class _HttpServer extends import_satori2.Adapter {
|
|
107
|
-
logger
|
|
109
|
+
logger;
|
|
110
|
+
constructor(ctx, bot) {
|
|
111
|
+
super(ctx);
|
|
112
|
+
this.logger = ctx.logger("dingtalk");
|
|
113
|
+
}
|
|
108
114
|
async connect(bot) {
|
|
109
115
|
await bot.refreshToken();
|
|
110
116
|
await bot.getLogin();
|
|
@@ -279,7 +285,7 @@ var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
|
|
|
279
285
|
this.bot.online();
|
|
280
286
|
this.socket.addEventListener("message", async ({ data }) => {
|
|
281
287
|
const parsed = JSON.parse(data.toString());
|
|
282
|
-
this.
|
|
288
|
+
this.bot.logger.debug(parsed);
|
|
283
289
|
if (parsed.type === "SYSTEM") {
|
|
284
290
|
if (parsed.headers.topic === "ping") {
|
|
285
291
|
this.socket.send(JSON.stringify({
|
|
@@ -290,11 +296,11 @@ var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
|
|
|
290
296
|
}));
|
|
291
297
|
}
|
|
292
298
|
} else if (parsed.type === "CALLBACK") {
|
|
293
|
-
this.
|
|
299
|
+
this.bot.logger.debug(JSON.parse(parsed.data));
|
|
294
300
|
const session = await decodeMessage(this.bot, JSON.parse(parsed.data));
|
|
295
301
|
if (session)
|
|
296
302
|
this.bot.dispatch(session);
|
|
297
|
-
this.
|
|
303
|
+
this.bot.logger.debug(session);
|
|
298
304
|
}
|
|
299
305
|
});
|
|
300
306
|
}
|
|
@@ -360,15 +366,13 @@ __name(_Internal, "Internal");
|
|
|
360
366
|
var Internal = _Internal;
|
|
361
367
|
|
|
362
368
|
// satori/adapters/dingtalk/src/bot.ts
|
|
363
|
-
var logger = new import_satori6.Logger("dingtalk");
|
|
364
369
|
var _DingtalkBot = class _DingtalkBot extends import_satori6.Bot {
|
|
365
370
|
oldHttp;
|
|
366
371
|
http;
|
|
367
372
|
internal;
|
|
368
373
|
refreshTokenTimer;
|
|
369
374
|
constructor(ctx, config) {
|
|
370
|
-
super(ctx, config);
|
|
371
|
-
this.platform = "dingtalk";
|
|
375
|
+
super(ctx, config, "dingtalk");
|
|
372
376
|
this.selfId = config.appkey;
|
|
373
377
|
this.http = ctx.http.extend(config.api);
|
|
374
378
|
this.oldHttp = ctx.http.extend(config.oldApi);
|
|
@@ -380,10 +384,27 @@ var _DingtalkBot = class _DingtalkBot extends import_satori6.Bot {
|
|
|
380
384
|
}
|
|
381
385
|
}
|
|
382
386
|
async getLogin() {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
+
try {
|
|
388
|
+
const { appList } = await this.internal.listAllInnerApps();
|
|
389
|
+
const self2 = appList.find((v) => v.agentId === this.config.agentId);
|
|
390
|
+
if (self2) {
|
|
391
|
+
this.user.name = self2.name;
|
|
392
|
+
this.user.avatar = self2.icon;
|
|
393
|
+
return this.toJSON();
|
|
394
|
+
}
|
|
395
|
+
} catch (e) {
|
|
396
|
+
this.logger.warn(e);
|
|
397
|
+
}
|
|
398
|
+
const data = await this.internal.oapiMicroappList();
|
|
399
|
+
if (!data.appList) {
|
|
400
|
+
this.logger.error("getLogin failed: %o", data);
|
|
401
|
+
return this.toJSON();
|
|
402
|
+
}
|
|
403
|
+
const self = data.appList.find((v) => v.agentId === this.config.agentId);
|
|
404
|
+
if (self) {
|
|
405
|
+
this.user.name = self.name;
|
|
406
|
+
this.user.avatar = self.appIcon;
|
|
407
|
+
}
|
|
387
408
|
return this.toJSON();
|
|
388
409
|
}
|
|
389
410
|
stop() {
|
|
@@ -396,7 +417,7 @@ var _DingtalkBot = class _DingtalkBot extends import_satori6.Bot {
|
|
|
396
417
|
appKey: this.config.appkey,
|
|
397
418
|
appSecret: this.config.secret
|
|
398
419
|
});
|
|
399
|
-
logger.debug("gettoken result: %o", data);
|
|
420
|
+
this.logger.debug("gettoken result: %o", data);
|
|
400
421
|
this.token = data.accessToken;
|
|
401
422
|
this.http = this.http.extend({
|
|
402
423
|
headers: {
|
|
@@ -438,7 +459,7 @@ var DingtalkBot = _DingtalkBot;
|
|
|
438
459
|
}),
|
|
439
460
|
import_satori6.Schema.object({
|
|
440
461
|
secret: import_satori6.Schema.string().required().description("机器人密钥。"),
|
|
441
|
-
agentId: import_satori6.Schema.number().
|
|
462
|
+
agentId: import_satori6.Schema.number().description("AgentId"),
|
|
442
463
|
appkey: import_satori6.Schema.string().required(),
|
|
443
464
|
api: import_satori6.Quester.createConfig("https://api.dingtalk.com/v1.0/"),
|
|
444
465
|
oldApi: import_satori6.Quester.createConfig("https://oapi.dingtalk.com/")
|