From 1f07c98943fb0b84e8546b953ab578893f3a3ea2 Mon Sep 17 00:00:00 2001 From: LittleC <26459759+XxLittleCxX@users.noreply.github.com> Date: Mon, 20 Nov 2023 09:20:09 +0800 Subject: [PATCH] feat(dingtalk): migrate dingtalk api --- adapters/dingtalk/src/bot.ts | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/adapters/dingtalk/src/bot.ts b/adapters/dingtalk/src/bot.ts index d543b842..6ae9c317 100644 --- a/adapters/dingtalk/src/bot.ts +++ b/adapters/dingtalk/src/bot.ts @@ -28,10 +28,28 @@ export class DingtalkBot extends Bot v.agentId === this.config.agentId) - this.user.name = self.name - this.user.avatar = self.appIcon + try { + const { appList } = await this.internal.listAllInnerApps() + const self = appList.find(v => v.agentId === this.config.agentId) + if (self) { + this.user.name = self.name + this.user.avatar = self.icon + return this.toJSON() + } + } catch (e) { + this.logger.warn(e) + } + + const data = await this.internal.oapiMicroappList() + if (!data.appList) { + this.logger.error('getLogin failed: %o', data) + return this.toJSON() + } + const self = data.appList.find(v => v.agentId === this.config.agentId) + if (self) { + this.user.name = self.name + this.user.avatar = self.appIcon + } return this.toJSON() } @@ -88,7 +106,7 @@ export namespace DingtalkBot { secret: string protocol: string appkey: string - agentId: number + agentId?: number api: Quester.Config oldApi: Quester.Config } @@ -101,7 +119,7 @@ export namespace DingtalkBot { }), Schema.object({ secret: Schema.string().required().description('机器人密钥。'), - agentId: Schema.number().required().description('AgentId'), + agentId: Schema.number().description('AgentId'), appkey: Schema.string().required(), api: Quester.createConfig('https://api.dingtalk.com/v1.0/'), oldApi: Quester.createConfig('https://oapi.dingtalk.com/'),