43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import groupAgent from "../../controller/groupAgent"
|
||
import { Context } from "../../types"
|
||
|
||
const GROUP_MAP = {
|
||
groupAgent: groupAgent.manual,
|
||
}
|
||
|
||
/**
|
||
* 处理点击事件
|
||
* @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()
|
||
}
|