feat(lark-msg-tool): 增加 LarkBody 类属性和方法以支持更多消息类型和用户信息
All checks were successful
/ release (push) Successful in 25s

This commit is contained in:
zhaoyingbo 2024-12-04 09:50:17 +00:00
parent cda8de9913
commit 617ff977dc

View File

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