@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.
Files changed (56) hide show
  1. package/lib/bot.d.ts +1 -1
  2. package/lib/http.d.ts +3 -2
  3. package/lib/index.js +35 -14
  4. package/lib/index.js.map +2 -3
  5. package/package.json +8 -4
  6. package/src/api/.eslintrc.yml +2 -0
  7. package/src/api/alitrip.ts +467 -0
  8. package/src/api/attendance.ts +81 -0
  9. package/src/api/badge.ts +285 -0
  10. package/src/api/blackboard.ts +28 -0
  11. package/src/api/calendar.ts +817 -0
  12. package/src/api/card.ts +215 -0
  13. package/src/api/conference.ts +561 -0
  14. package/src/api/connector.ts +97 -0
  15. package/src/api/contact.ts +56 -0
  16. package/src/api/convFile.ts +166 -0
  17. package/src/api/crm.ts +830 -0
  18. package/src/api/customerService.ts +156 -0
  19. package/src/api/datacenter.ts +672 -0
  20. package/src/api/devicemng.ts +202 -0
  21. package/src/api/diot.ts +19 -0
  22. package/src/api/doc.ts +232 -0
  23. package/src/api/drive.ts +109 -0
  24. package/src/api/edu.ts +30 -0
  25. package/src/api/esign.ts +44 -0
  26. package/src/api/exclusive.ts +372 -0
  27. package/src/api/h3yun.ts +537 -0
  28. package/src/api/hrm.ts +272 -0
  29. package/src/api/im.ts +978 -0
  30. package/src/api/industry.ts +153 -0
  31. package/src/api/jzcrm.ts +304 -0
  32. package/src/api/link.ts +94 -0
  33. package/src/api/live.ts +162 -0
  34. package/src/api/microApp.ts +309 -0
  35. package/src/api/oapi.ts +4083 -0
  36. package/src/api/oauth2.ts +146 -0
  37. package/src/api/pedia.ts +222 -0
  38. package/src/api/project.ts +1519 -0
  39. package/src/api/resident.ts +133 -0
  40. package/src/api/robot.ts +326 -0
  41. package/src/api/rooms.ts +334 -0
  42. package/src/api/serviceGroup.ts +216 -0
  43. package/src/api/storage.ts +1701 -0
  44. package/src/api/swform.ts +94 -0
  45. package/src/api/todo.ts +220 -0
  46. package/src/api/wiki.ts +231 -0
  47. package/src/api/workbench.ts +73 -0
  48. package/src/api/yida.ts +2165 -0
  49. package/src/bot.ts +129 -0
  50. package/src/http.ts +44 -0
  51. package/src/index.ts +9 -0
  52. package/src/internal.ts +47 -0
  53. package/src/message.ts +141 -0
  54. package/src/types/index.ts +140 -0
  55. package/src/utils.ts +53 -0
  56. package/src/ws.ts +55 -0
package/lib/bot.d.ts CHANGED
@@ -21,7 +21,7 @@ export declare namespace DingtalkBot {
21
21
  secret: string;
22
22
  protocol: string;
23
23
  appkey: string;
24
- agentId: number;
24
+ agentId?: number;
25
25
  api: Quester.Config;
26
26
  oldApi: Quester.Config;
27
27
  }
package/lib/http.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { Adapter, Context, Logger } from '@satorijs/satori';
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: 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, ...session.elements];
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 = new import_satori2.Logger("dingtalk");
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.ctx.logger("dingtalk").debug(parsed);
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.ctx.logger("dingtalk").debug(JSON.parse(parsed.data));
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.ctx.logger("dingtalk").debug(session);
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
- const { appList } = await this.internal.oapiMicroappList();
384
- const self = appList.find((v) => v.agentId === this.config.agentId);
385
- this.user.name = self.name;
386
- this.user.avatar = self.appIcon;
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().required().description("AgentId"),
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/")