egg_server/routes/bot/actionMsg.ts
zhaoyingbo d64d6211c0
All checks were successful
Egg Server CI/CD / build-image (push) Successful in 50s
Egg Server CI/CD / refresh-image (push) Successful in 12s
Egg Server CI/CD / fast-deploy (push) Successful in 3s
feat(group-agent): 支持大模型语义化理解用户输入
2024-10-16 12:20:25 +00:00

43 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 GROUP_MAP = {
groupAgent,
}
/**
* 处理点击事件
* @param {Context.Data} ctx - 上下文数据包含body, larkService和logger
*/
const manageAction = async (ctx: Context.Data) => {
const {
larkBody: { actionValue },
logger,
} = ctx
const { cardGroup } = actionValue as {
cardGroup: keyof typeof GROUP_MAP
}
logger.info(`Got lark action cardGroup: ${cardGroup}`)
if (!cardGroup) return
const func = GROUP_MAP[cardGroup]
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.json(card)
return ctx.genResp.ok()
}