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消息体