import { Context } from "../../types" import { manageActionMsg } from "./actionMsg" import { manageEventMsg } from "./eventMsg" /** * 处理机器人请求 * @param {Context.Data} ctx - 上下文数据,包含请求体、日志记录器和响应生成器 * @returns {Promise} 返回响应对象 */ export const manageBotReq = async (ctx: Context.Data): Promise => { const { body } = ctx // 检查请求体是否为空 if (!body) { return ctx.genResp.badRequest("bot req body is empty") } // 验证机器人 if (body.type === "url_verification") { ctx.logger.info(`bot challenge: ${body.challenge}`) return Response.json({ challenge: body.challenge }) } // 处理Event消息 if (manageEventMsg(ctx)) return ctx.genResp.ok() // 处理Action消息 if (manageActionMsg(ctx)) return ctx.genResp.ok() // 其他情况,返回成功响应 return ctx.genResp.ok() }