This commit is contained in:
parent
0ab68df37b
commit
2c11ce4841
@ -5,7 +5,7 @@ import { LarkAction, LarkEvent } from "./types"
|
||||
* @param body 事件消息体
|
||||
* @returns 是否为事件消息
|
||||
*/
|
||||
export const getIsEventMsg = (body: LarkEvent.Data) => {
|
||||
export const getIsEventMsg = (body: any): body is LarkEvent.Data => {
|
||||
return body?.header?.event_type === "im.message.receive_v1"
|
||||
}
|
||||
|
||||
@ -18,15 +18,6 @@ export const getMsgType = (body: LarkEvent.Data) => {
|
||||
return body?.event?.message?.message_type
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对话流Id
|
||||
* @param body 事件消息体
|
||||
* @returns 对话流Id
|
||||
*/
|
||||
export const getChatId = (body: LarkEvent.Data & LarkAction.Data) => {
|
||||
return body?.event?.message?.chat_id || body?.open_chat_id
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户Id
|
||||
* @param body 事件消息体
|
||||
@ -75,7 +66,7 @@ export const getMentions = (body: LarkEvent.Data) => {
|
||||
* @param body Action消息体
|
||||
* @returns 是否为Action消息
|
||||
*/
|
||||
export const getIsActionMsg = (body: LarkAction.Data) => {
|
||||
export const getIsActionMsg = (body: any): body is LarkAction.Data => {
|
||||
return !!body?.action
|
||||
}
|
||||
|
||||
@ -106,4 +97,15 @@ export const getActionOption = (body: LarkAction.Data) => {
|
||||
return body?.action?.option
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对话流Id
|
||||
* @param body 事件消息体
|
||||
* @returns 对话流Id
|
||||
*/
|
||||
export const getChatId = (body: LarkEvent.Data | LarkAction.Data) => {
|
||||
if (getIsEventMsg(body)) return body?.event?.message?.chat_id
|
||||
if (getIsActionMsg(body)) return body?.open_chat_id
|
||||
return ""
|
||||
}
|
||||
|
||||
export { LarkAction, LarkEvent }
|
||||
|
Loading…
x
Reference in New Issue
Block a user