feat(lark-msg-tool): 增加 LarkBody 类属性和方法以支持更多消息类型和用户信息
All checks were successful
/ release (push) Successful in 25s
All checks were successful
/ release (push) Successful in 25s
This commit is contained in:
parent
cda8de9913
commit
617ff977dc
@ -2,25 +2,83 @@ import { LarkAction, LarkEvent } from "../types"
|
|||||||
|
|
||||||
class LarkBody {
|
class LarkBody {
|
||||||
protected body: LarkEvent.Data | LarkAction.Data
|
protected body: LarkEvent.Data | LarkAction.Data
|
||||||
|
/**
|
||||||
|
* 是否为事件消息
|
||||||
|
*/
|
||||||
public isEvent: boolean = false
|
public isEvent: boolean = false
|
||||||
|
/**
|
||||||
|
* 是否为Action消息
|
||||||
|
*/
|
||||||
public isAction: boolean = false
|
public isAction: boolean = false
|
||||||
|
/**
|
||||||
|
* 事件类型
|
||||||
|
*/
|
||||||
public eventType?: LarkEvent.Data["header"]["event_type"]
|
public eventType?: LarkEvent.Data["header"]["event_type"]
|
||||||
|
/**
|
||||||
|
* 是否为消息事件
|
||||||
|
*/
|
||||||
public isMessageEvent?: boolean
|
public isMessageEvent?: boolean
|
||||||
|
/**
|
||||||
|
* 消息类型
|
||||||
|
*/
|
||||||
public msgType?: LarkEvent.Message["message_type"]
|
public msgType?: LarkEvent.Message["message_type"]
|
||||||
|
/**
|
||||||
|
* 用户Id
|
||||||
|
*/
|
||||||
public userId?: LarkEvent.UserIdInfo["user_id"]
|
public userId?: LarkEvent.UserIdInfo["user_id"]
|
||||||
|
/**
|
||||||
|
* 用户OpenId
|
||||||
|
*/
|
||||||
public openId?: LarkEvent.UserIdInfo["open_id"]
|
public openId?: LarkEvent.UserIdInfo["open_id"]
|
||||||
|
/**
|
||||||
|
* 文本内容
|
||||||
|
*/
|
||||||
public msgText: string = ""
|
public msgText: string = ""
|
||||||
|
/**
|
||||||
|
* 原始文本内容
|
||||||
|
*/
|
||||||
public rawMsgText: string = ""
|
public rawMsgText: string = ""
|
||||||
|
/**
|
||||||
|
* 聊天类型
|
||||||
|
*/
|
||||||
public chatType?: LarkEvent.Message["chat_type"]
|
public chatType?: LarkEvent.Message["chat_type"]
|
||||||
|
/**
|
||||||
|
* 是否为P2P聊天
|
||||||
|
*/
|
||||||
public isP2P?: boolean
|
public isP2P?: boolean
|
||||||
|
/**
|
||||||
|
* 是否在群聊中
|
||||||
|
*/
|
||||||
public isInGroup?: boolean
|
public isInGroup?: boolean
|
||||||
|
/**
|
||||||
|
* 艾特信息
|
||||||
|
*/
|
||||||
public mentions?: LarkEvent.Mention[]
|
public mentions?: LarkEvent.Mention[]
|
||||||
|
/**
|
||||||
|
* 艾特的机器人
|
||||||
|
*/
|
||||||
|
public mentionedRobot?: LarkEvent.Mention
|
||||||
|
/**
|
||||||
|
* Action类型
|
||||||
|
*/
|
||||||
public actionType?: LarkAction.Data["action"]["tag"]
|
public actionType?: LarkAction.Data["action"]["tag"]
|
||||||
|
/**
|
||||||
|
* Action参数
|
||||||
|
*/
|
||||||
public actionValue?: LarkAction.Data["action"]["value"]
|
public actionValue?: LarkAction.Data["action"]["value"]
|
||||||
|
/**
|
||||||
|
* Action选项
|
||||||
|
*/
|
||||||
public actionOption?: LarkAction.Data["action"]["option"]
|
public actionOption?: LarkAction.Data["action"]["option"]
|
||||||
|
/**
|
||||||
|
* 对话流Id
|
||||||
|
*/
|
||||||
public chatId:
|
public chatId:
|
||||||
| LarkEvent.Message["chat_id"]
|
| LarkEvent.Message["chat_id"]
|
||||||
| LarkAction.Data["open_chat_id"] = ""
|
| LarkAction.Data["open_chat_id"] = ""
|
||||||
|
/**
|
||||||
|
* 消息Id
|
||||||
|
*/
|
||||||
public messageId:
|
public messageId:
|
||||||
| LarkEvent.Message["message_id"]
|
| LarkEvent.Message["message_id"]
|
||||||
| LarkAction.Data["open_message_id"] = ""
|
| LarkAction.Data["open_message_id"] = ""
|
||||||
@ -47,6 +105,7 @@ class LarkBody {
|
|||||||
this.isP2P = this.chatType === "p2p"
|
this.isP2P = this.chatType === "p2p"
|
||||||
this.isInGroup = this.chatType === "group"
|
this.isInGroup = this.chatType === "group"
|
||||||
this.mentions = this.getMentions(eventBody)
|
this.mentions = this.getMentions(eventBody)
|
||||||
|
this.mentionedRobot = this.getMentionedRobot(eventBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isAction) {
|
if (this.isAction) {
|
||||||
@ -175,6 +234,17 @@ class LarkBody {
|
|||||||
return body?.event?.message?.mentions
|
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类型
|
* 获取Action类型
|
||||||
* @param body Action消息体
|
* @param body Action消息体
|
||||||
|
Loading…
x
Reference in New Issue
Block a user