egg_server/routes/bot/actionMsg.ts
zhaoyingbo 1c6c3cef89
All checks were successful
Egg Server CI/CD / build-image (push) Successful in 51s
Egg Server CI/CD / refresh-image (push) Successful in 15s
Egg Server CI/CD / fast-deploy (push) Successful in 2s
fix: action类型消息处理错误
2024-10-12 10:30:10 +00:00

40 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Context } from "../../types"
import groupAgent from "./groupAgent"
const ACTION_MAP = {
sendFunctionSelector: groupAgent.sendFunctionSelector,
sendTimeScopeSelector: groupAgent.sendTimeScopeSelector,
manageGroupMsg: groupAgent.manageGroupMsg,
}
/**
* 处理点击事件
* @param {Context.Data} ctx - 上下文数据包含body, larkService和logger
*/
const manageAction = async (ctx: Context.Data) => {
const { body, logger } = ctx
const { action } = body?.action?.value as {
action: keyof typeof ACTION_MAP
}
logger.info(`Got lark action: ${action}`)
if (!action) return
const func = ACTION_MAP[action]
if (!func) return
return func(ctx)
}
/**
* 处理Action消息
* @param {Context.Data} ctx - 上下文数据
*/
export const manageActionMsg = async (ctx: Context.Data) => {
const {
larkBody: { actionType },
} = ctx
if (!["button", "select_static"].includes(actionType!))
return ctx.genResp.ok()
const card = await manageAction(ctx)
if (card) return ctx.genResp.custom(card)
return ctx.genResp.ok()
}