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 1/2] 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/'), From 0644155241e4740171d6bfc101b8b26328ee1216 Mon Sep 17 00:00:00 2001 From: LittleC <26459759+XxLittleCxX@users.noreply.github.com> Date: Mon, 20 Nov 2023 21:40:06 +0800 Subject: [PATCH 2/2] fix(dingtalk): add missing `isDirect` --- adapters/dingtalk/src/utils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adapters/dingtalk/src/utils.ts b/adapters/dingtalk/src/utils.ts index 702bee1e..7ce656f7 100644 --- a/adapters/dingtalk/src/utils.ts +++ b/adapters/dingtalk/src/utils.ts @@ -10,10 +10,12 @@ export async function decodeMessage(bot: DingtalkBot, body if (body.conversationType === '1') { session.channelId = session.userId + session.isDirect = true } else { const atUsers = body.atUsers.filter(v => v.dingtalkId !== body.chatbotUserId).map(v => h.at(v.staffId)) - session.elements = [h.at(body.robotCode), ...atUsers, ...session.elements] + session.elements = [h.at(body.robotCode), ...atUsers] session.channelId = body.conversationId + session.isDirect = false } if (body.conversationTitle) { session.event.channel.name = body.conversationTitle