From 1153183869afffe988e67320f21e1d28eeadc7dc Mon Sep 17 00:00:00 2001 From: zhaoyingbo Date: Wed, 23 Oct 2024 09:44:56 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=86=E7=A6=BB=E5=B0=8F=E7=85=8E?= =?UTF-8?q?=E8=9B=8B=E5=92=8Cmichat=E7=9A=84=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- constant/template.ts | 3 +- routes/bot/eventMsg.ts | 96 ++++++++++++++++++++-------------- test/archive/getChatHistory.ts | 54 +++++++++++++++---- 3 files changed, 103 insertions(+), 50 deletions(-) diff --git a/constant/template.ts b/constant/template.ts index f0b051a..01fb454 100644 --- a/constant/template.ts +++ b/constant/template.ts @@ -15,7 +15,8 @@ const tempMap = { successMsg: "ctp_AA0LgXOkEOPK", errorMsg: "ctp_AA0LgXOkEuqi", chatId: "ctp_AAi3NnHb6zgK", - guide: "ctp_AAyVx5R39xU9", + eggGuide: "ctp_AAyVx5R39xU9", + miChatGuide: "AAqDiiTs4kSN9", createKVSuccess: "ctp_AA00oqPWPXtG", } diff --git a/routes/bot/eventMsg.ts b/routes/bot/eventMsg.ts index f15ce32..a8b9f20 100644 --- a/routes/bot/eventMsg.ts +++ b/routes/bot/eventMsg.ts @@ -1,5 +1,6 @@ import { type LarkBody } from "@egg/lark-msg-tool" +import tempMap from "../../constant/template" import db from "../../db" import { Context } from "../../types" import createKVTemp from "../sheet/createKVTemp" @@ -93,14 +94,13 @@ const manageIdMsg = ({ * 回复引导消息 * @param {Context.Data} ctx - 上下文数据 */ -const manageHelpMsg = ({ - larkBody: { chatId }, - larkCard, - larkService, -}: Context.Data): void => { +const manageHelpMsg = ( + { larkBody: { chatId }, larkCard, larkService }: Context.Data, + tempKey: keyof typeof tempMap +): void => { larkService.message.sendCard2Chat( chatId, - larkCard.genTempCard("guide", { chat_id: chatId }) as string + larkCard.genTempCard(tempKey, { chat_id: chatId }) as string ) } @@ -110,6 +110,7 @@ const manageHelpMsg = ({ */ const manageCMDMsg = (ctx: Context.Data) => { const { + app, body, logger, larkService, @@ -123,44 +124,61 @@ const manageCMDMsg = (ctx: Context.Data) => { manageIdMsg(ctx) return } - // 帮助 - if (msgText.trim() === "/help") { - logger.info(`bot command is /help, chatId: ${chatId}`) - manageHelpMsg(ctx) - return - } - // CI监控 - if (msgText.trim() === "/ci") { - logger.info(`bot command is /ci, chatId: ${chatId}`) - attachService.ciMonitor(chatId) - return - } - // 简报 - if (msgText.includes("share") && msgText.includes("简报")) { - logger.info(`bot command is share report, chatId: ${chatId}`) - // 这个用时比较久,先发一条提醒用户收到了请求 - // TODO: 迁移到简报服务中 - larkService.message.send( - "chat_id", - chatId, - "text", - "正在为您收集简报,请稍等片刻~" - ) - attachService.reportCollector(body) - return - } - // 创建Sheet DB - if (msgText.trim() === "/gen db") { - logger.info(`bot command is /gen db, chatId: ${chatId}`) - createKVTemp.createFromEvent(ctx) - return - } + // 选择群组信息 - if (msgText.trim().startsWith("/groupchat")) { + if (msgText.trim().startsWith("/g")) { logger.info(`bot command is /groupchat, chatId: ${chatId}`) groupAgent(ctx) return } + + // michat专属功能 + if (app === "michat") { + // 帮助 + if (msgText.trim() === "/help") { + logger.info(`bot command is /help, chatId: ${chatId}`) + manageHelpMsg(ctx, "miChatGuide") + return + } + } + + // 小煎蛋专属功能 + if (app === "egg") { + // CI监控 + if (msgText.trim() === "/ci") { + logger.info(`bot command is /ci, chatId: ${chatId}`) + attachService.ciMonitor(chatId) + return + } + // 简报 + if (msgText.includes("share") && msgText.includes("简报")) { + logger.info(`bot command is share report, chatId: ${chatId}`) + // 这个用时比较久,先发一条提醒用户收到了请求 + // TODO: 迁移到简报服务中 + larkService.message.send( + "chat_id", + chatId, + "text", + "正在为您收集简报,请稍等片刻~" + ) + attachService.reportCollector(body) + return + } + // 创建Sheet DB + if (msgText.trim() === "/gen db") { + logger.info(`bot command is /gen db, chatId: ${chatId}`) + createKVTemp.createFromEvent(ctx) + return + } + + // 帮助 + if (msgText.trim() === "/help") { + logger.info(`bot command is /help, chatId: ${chatId}`) + manageHelpMsg(ctx, "eggGuide") + return + } + } + return } diff --git a/test/archive/getChatHistory.ts b/test/archive/getChatHistory.ts index de535ea..1fdee58 100644 --- a/test/archive/getChatHistory.ts +++ b/test/archive/getChatHistory.ts @@ -1,14 +1,48 @@ -import { LarkService } from "../../services" +// import logger from "@egg/logger" -const service = new LarkService("egg", "") +// import getChatHistory from "../../routes/bot/groupAgent/chatHistory" +// import { LarkService } from "../../services" -const currentTime = Math.floor(new Date().getTime() / 1000) -const yesterdayTime = currentTime - 24 * 60 * 60 +// const service = new LarkService("michat", "") -const res = await service.message.getHistory( - "oc_c83f627bde3da39b01bbbfb026a00111", - yesterdayTime.toString(), - currentTime.toString() -) +// const currentTime = Math.floor(new Date().getTime() / 1000) +// const weekAgoTime = currentTime - 7 * 24 * 60 * 60 -console.log(JSON.stringify(res, null, 2)) +// const res = await service.message.getHistory( +// "oc_bd23da1ae9948654fc04365d7d102d73", +// weekAgoTime.toString(), +// currentTime.toString() +// ) + +// // const res = await getChatHistory( +// // { larkService: service, logger: logger }, +// // { +// // chatId: "oc_bd23da1ae9948654fc04365d7d102d73", +// // timeScope: "", +// // startTime: "2024-10-16 00:00:00", +// // endTime: "2024-10-24 00:00:00", +// // mentions: [], +// // } +// // ) +// // { +// // "user": "左建光", +// // "content": "Anthropic经过一番操作已经是和openai并肩的AI双雄了[呲牙]", +// // "time": "2024/10/23 09:25:33" +// // }, +// // { +// // "user": "魏柏楠", +// // "content": "@Mi Chat /id", +// // "time": "2024/10/23 10:02:42" +// // } +// console.log(JSON.stringify(res, null, 2)) + +// // 把res内容输出到csv文件,保留user、content、time字段,使用逗号分隔 +// // 手写代码实现 +// const fileContent = res +// .filter(({ user, content, time }) => user && content && time) +// .map( +// ({ user, content, time }) => +// `${time},${user},${content.replace(/,/g, ",").replace(/\n/g, " ")}` +// ) +// .join("\n") +// await Bun.write("output.csv", fileContent)