From 617ff977dc0917fde4717222e1ec9733bda5cdd0 Mon Sep 17 00:00:00 2001 From: zhaoyingbo Date: Wed, 4 Dec 2024 09:50:17 +0000 Subject: [PATCH] =?UTF-8?q?feat(lark-msg-tool):=20=E5=A2=9E=E5=8A=A0=20Lar?= =?UTF-8?q?kBody=20=E7=B1=BB=E5=B1=9E=E6=80=A7=E5=92=8C=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A4=9A=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=92=8C=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/lark-msg-tool/src/larkBody/index.ts | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/packages/lark-msg-tool/src/larkBody/index.ts b/packages/lark-msg-tool/src/larkBody/index.ts index 5c575ea..b1ce456 100644 --- a/packages/lark-msg-tool/src/larkBody/index.ts +++ b/packages/lark-msg-tool/src/larkBody/index.ts @@ -2,25 +2,83 @@ import { LarkAction, LarkEvent } from "../types" class LarkBody { protected body: LarkEvent.Data | LarkAction.Data + /** + * 是否为事件消息 + */ public isEvent: boolean = false + /** + * 是否为Action消息 + */ public isAction: boolean = false + /** + * 事件类型 + */ public eventType?: LarkEvent.Data["header"]["event_type"] + /** + * 是否为消息事件 + */ public isMessageEvent?: boolean + /** + * 消息类型 + */ public msgType?: LarkEvent.Message["message_type"] + /** + * 用户Id + */ public userId?: LarkEvent.UserIdInfo["user_id"] + /** + * 用户OpenId + */ public openId?: LarkEvent.UserIdInfo["open_id"] + /** + * 文本内容 + */ public msgText: string = "" + /** + * 原始文本内容 + */ public rawMsgText: string = "" + /** + * 聊天类型 + */ public chatType?: LarkEvent.Message["chat_type"] + /** + * 是否为P2P聊天 + */ public isP2P?: boolean + /** + * 是否在群聊中 + */ public isInGroup?: boolean + /** + * 艾特信息 + */ public mentions?: LarkEvent.Mention[] + /** + * 艾特的机器人 + */ + public mentionedRobot?: LarkEvent.Mention + /** + * Action类型 + */ public actionType?: LarkAction.Data["action"]["tag"] + /** + * Action参数 + */ public actionValue?: LarkAction.Data["action"]["value"] + /** + * Action选项 + */ public actionOption?: LarkAction.Data["action"]["option"] + /** + * 对话流Id + */ public chatId: | LarkEvent.Message["chat_id"] | LarkAction.Data["open_chat_id"] = "" + /** + * 消息Id + */ public messageId: | LarkEvent.Message["message_id"] | LarkAction.Data["open_message_id"] = "" @@ -47,6 +105,7 @@ class LarkBody { this.isP2P = this.chatType === "p2p" this.isInGroup = this.chatType === "group" this.mentions = this.getMentions(eventBody) + this.mentionedRobot = this.getMentionedRobot(eventBody) } if (this.isAction) { @@ -175,6 +234,17 @@ class LarkBody { return body?.event?.message?.mentions } + /** + * 获取艾特的机器人 + * @param body 事件消息体 + * @returns 艾特的机器人 + */ + private getMentionedRobot(body: LarkEvent.Data) { + const mentions = this.getMentions(body) + // 返回第一个没有user_id的mention + return mentions?.find((mention) => !mention.id?.user_id) + } + /** * 获取Action类型 * @param body Action消息体