All checks were successful
Egg Server MIflow / build-image (push) Successful in 46s
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { getActionType } from "@egg/lark-msg-tool"
|
||
|
||
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
|
||
* @returns {Promise<void>} 无返回值
|
||
*/
|
||
const manageBtnClick = async (ctx: Context.Data): Promise<void> => {
|
||
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
|
||
func(ctx)
|
||
}
|
||
|
||
/**
|
||
* 处理Action消息
|
||
* @param {Context.Data} ctx - 上下文数据
|
||
*/
|
||
export const manageActionMsg = async (ctx: Context.Data) => {
|
||
const actionType = getActionType(ctx.body)
|
||
if (actionType === "button") manageBtnClick(ctx)
|
||
if (actionType === "select_static") manageBtnClick(ctx)
|
||
return ctx.genResp.json()
|
||
}
|