This commit is contained in:
parent
6d47652aa3
commit
ee271ed4cc
@ -2,64 +2,64 @@ import { LarkAction, LarkEvent } from "./types"
|
||||
|
||||
/**
|
||||
* 是否为事件消息
|
||||
* @param {LarkEvent.Data} body - 事件消息体
|
||||
* @returns {boolean} 是否为事件消息
|
||||
* @param body 事件消息体
|
||||
* @returns 是否为事件消息
|
||||
*/
|
||||
export const getIsEventMsg = (body: LarkEvent.Data): boolean => {
|
||||
export const getIsEventMsg = (body: LarkEvent.Data) => {
|
||||
return body?.header?.event_type === "im.message.receive_v1"
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取事件文本类型
|
||||
* @param {LarkEvent.Data} body - 事件消息体
|
||||
* @returns {string | undefined} 事件文本类型
|
||||
* @param body 事件消息体
|
||||
* @returns 事件文本类型
|
||||
*/
|
||||
export const getMsgType = (body: LarkEvent.Data): string | undefined => {
|
||||
export const getMsgType = (body: LarkEvent.Data) => {
|
||||
return body?.event?.message?.message_type
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对话流Id
|
||||
* @param {LarkEvent.Data} body - 事件消息体
|
||||
* @returns {string | undefined} 对话流Id
|
||||
* @param body 事件消息体
|
||||
* @returns 对话流Id
|
||||
*/
|
||||
export const getChatId = (body: LarkEvent.Data): string | undefined => {
|
||||
export const getChatId = (body: LarkEvent.Data) => {
|
||||
return body?.event?.message?.chat_id
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户Id
|
||||
* @param {LarkEvent.Data} body - 事件消息体
|
||||
* @returns {string | undefined} 用户Id
|
||||
* @param body 事件消息体
|
||||
* @returns 用户Id
|
||||
*/
|
||||
export const getUserId = (body: LarkEvent.Data): string | undefined => {
|
||||
export const getUserId = (body: LarkEvent.Data) => {
|
||||
return body?.event?.sender?.sender_id?.user_id
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为Action消息
|
||||
* @param {LarkAction.Data} body - Action消息体
|
||||
* @returns {boolean} 是否为Action消息
|
||||
* @param body Action消息体
|
||||
* @returns 是否为Action消息
|
||||
*/
|
||||
export const getIsActionMsg = (body: LarkAction.Data): boolean => {
|
||||
export const getIsActionMsg = (body: LarkAction.Data) => {
|
||||
return !!body?.action
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Action类型
|
||||
* @param {LarkAction.Data} body - Action消息体
|
||||
* @returns {string | undefined} Action类型
|
||||
* @param body Action消息体
|
||||
* @returns Action类型
|
||||
*/
|
||||
export const getActionType = (body: LarkAction.Data): string | undefined => {
|
||||
export const getActionType = (body: LarkAction.Data) => {
|
||||
return body?.action?.tag
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文本内容并剔除艾特信息
|
||||
* @param {LarkEvent.Data} body - 事件消息体
|
||||
* @returns {string} 文本内容
|
||||
* @param body 事件消息体
|
||||
* @returns 文本内容
|
||||
*/
|
||||
export const getMsgText = (body: LarkEvent.Data): string => {
|
||||
export const getMsgText = (body: LarkEvent.Data) => {
|
||||
try {
|
||||
const { text }: { text: string } = JSON.parse(body?.event?.message?.content)
|
||||
// 去掉@_user_1相关的内容,例如 '@_user_1 测试' -> '测试'
|
||||
@ -72,19 +72,19 @@ export const getMsgText = (body: LarkEvent.Data): string => {
|
||||
|
||||
/**
|
||||
* 获取聊天类型
|
||||
* @param {LarkEvent.Data} body - 事件消息体
|
||||
* @returns {string | undefined} 聊天类型
|
||||
* @param body 事件消息体
|
||||
* @returns 聊天类型
|
||||
*/
|
||||
export const getChatType = (body: LarkEvent.Data): string | undefined => {
|
||||
export const getChatType = (body: LarkEvent.Data) => {
|
||||
return body?.event?.message?.chat_type
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取艾特信息
|
||||
* @param {LarkEvent.Data} body - 事件消息体
|
||||
* @returns {Array | undefined} 艾特信息
|
||||
* @param body 事件消息体
|
||||
* @returns 艾特信息
|
||||
*/
|
||||
export const getMentions = (body: LarkEvent.Data): Array<any> | undefined => {
|
||||
export const getMentions = (body: LarkEvent.Data) => {
|
||||
return body?.event?.message?.mentions
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,17 @@ export namespace LarkEvent {
|
||||
* 消息类型
|
||||
* @example text、post、image、file、audio、media、sticker、interactive、share_chat、share_user
|
||||
*/
|
||||
message_type: string
|
||||
message_type:
|
||||
| "text"
|
||||
| "post"
|
||||
| "image"
|
||||
| "file"
|
||||
| "audio"
|
||||
| "media"
|
||||
| "sticker"
|
||||
| "interactive"
|
||||
| "share_chat"
|
||||
| "share_user"
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user