From e0d10848d8df8f9275de78bf7fef484908693040 Mon Sep 17 00:00:00 2001 From: Shigma Date: Thu, 31 Oct 2024 18:57:08 +0800 Subject: [PATCH] fix(lark): set isDirent on interaction events --- adapters/lark/src/message.ts | 13 ++++++++----- adapters/lark/src/types/api.ts | 2 ++ adapters/lark/src/types/message/index.ts | 16 ++++++++++++++++ adapters/lark/src/utils.ts | 12 ++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/adapters/lark/src/message.ts b/adapters/lark/src/message.ts index ada13f4c..be452bbb 100644 --- a/adapters/lark/src/message.ts +++ b/adapters/lark/src/message.ts @@ -4,7 +4,7 @@ import { BaseResponse, Lark, MessageContent } from './types' import { extractIdType } from './utils' export class LarkMessageEncoder extends MessageEncoder> { - private quote: string | undefined + private quote: Dict | undefined private textContent = '' private richContent: MessageContent.RichText.Paragraph[] = [] private card: MessageContent.Card | undefined @@ -14,11 +14,14 @@ export class LarkMessageEncoder extends MessageEnco async post(data?: any) { try { let resp: BaseResponse & { data?: Lark.Message } - if (this.quote) { - resp = await this.bot.internal.replyImMessage(this.quote, data) + if (this.quote?.id) { + resp = await this.bot.internal.replyImMessage(this.quote.id, { + ...data, + reply_in_thread: this.quote.replyInThread, + }) } else { data.receive_id = this.channelId - resp = await this.bot.internal?.createImMessage(data, { + resp = await this.bot.internal.createImMessage(data, { receive_id_type: extractIdType(this.channelId), }) } @@ -174,7 +177,7 @@ export class LarkMessageEncoder extends MessageEnco // platform does not support sharp } else if (type === 'quote') { await this.flush() - this.quote = attrs.id + this.quote = attrs } else if (type === 'img' || type === 'image') { const image_key = await this.createImage(attrs.src || attrs.url) this.textContent += `![${attrs.alt ?? '图片'}](${image_key})` diff --git a/adapters/lark/src/types/api.ts b/adapters/lark/src/types/api.ts index 25cbdd13..bec9a8b1 100644 --- a/adapters/lark/src/types/api.ts +++ b/adapters/lark/src/types/api.ts @@ -16681,6 +16681,8 @@ export interface ReplyImMessageRequest { content: string /** 消息类型,包括:text、post、image、file、audio、media、sticker、interactive、share_card、share_user */ msg_type: string + /** 是否以话题形式回复。取值为 true 时将以话题形式回复。注意:如果要回复的消息已经是话题形式的消息,则默认以话题形式进行回复。 */ + reply_in_thread?: boolean /** 由开发者生成的唯一字符串序列,用于回复消息请求去重;持有相同uuid的请求1小时内至多成功执行一次 */ uuid?: string } diff --git a/adapters/lark/src/types/message/index.ts b/adapters/lark/src/types/message/index.ts index 4cedc97f..0bb8f552 100644 --- a/adapters/lark/src/types/message/index.ts +++ b/adapters/lark/src/types/message/index.ts @@ -76,5 +76,21 @@ declare module '../event' { open_chat_id: string } } + /** + * 机器人自定义菜单事件 + * @see https://open.feishu.cn/document/client-docs/bot-v3/events/menu + */ + 'application.bot.menu_v6': { + operator: { + operator_name: string + operator_id: { + union_id: string + user_id: string + open_id: string + } + } + event_key: string + timestamp: number + } } } diff --git a/adapters/lark/src/utils.ts b/adapters/lark/src/utils.ts index 2f4f9d9e..688d4bcb 100644 --- a/adapters/lark/src/utils.ts +++ b/adapters/lark/src/utils.ts @@ -84,6 +84,15 @@ export async function adaptSession(bot: LarkBot, body: Eve adaptSender(body.event.sender, session) await adaptMessage(bot, body.event, session) break + case 'application.bot.menu_v6': + if (body.event.event_key.startsWith('command:')) { + session.type = 'interaction/command' + session.content = body.event.event_key.slice(8) + session.channelId = body.event.operator.operator_id.open_id + session.userId = body.event.operator.operator_id.open_id + session.isDirect = true + } + break case 'card.action.trigger': if (body.event.action.value?._satori_type === 'command') { session.type = 'interaction/command' @@ -114,6 +123,9 @@ export async function adaptSession(bot: LarkBot, body: Eve session.channelId = body.event.context.open_chat_id session.guildId = body.event.context.open_chat_id session.userId = body.event.operator.open_id + const { data } = await bot.internal.getImChat(session.channelId) + // TODO: add channel data + session.isDirect = data.chat_mode === 'p2p' } break }