chore(lark-msg): 优化getChatId函数实现
All checks were successful
/ release (push) Successful in 24s

This commit is contained in:
zhaoyingbo 2024-09-26 01:41:45 +00:00
parent 0ab68df37b
commit 2c11ce4841

View File

@ -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 }