feat: 添加CI监控命令处理
All checks were successful
Egg CI/CD / build-image (push) Successful in 1m17s
Egg CI/CD / deploy (push) Successful in 26s

This commit is contained in:
zhaoyingbo 2024-05-17 11:38:23 +00:00
parent eb7a821549
commit a280ae9f70
2 changed files with 39 additions and 6 deletions

View File

@ -1,3 +1,4 @@
import { fetchCIMonitor } from "../../service";
import lark from "../../service/lark";
import { LarkMessageEvent } from "../../types";
import { getChatId, getIsEventMsg, getMsgType } from "../../utils/msgTools";
@ -61,11 +62,39 @@ const filterIllegalMsg = (body: LarkMessageEvent) => {
return false;
};
const manageCMDMsg = async (body: LarkMessageEvent) => {
const text = getMsgText(body);
const chatId = getChatId(body);
let msgContent = "";
if (text === "/id") {
msgContent = JSON.stringify({
type: "template",
data: {
config: {
update_multi: true,
},
template_id: "ctp_AAi3NnHb6zgK",
template_variable: {
chat_id: chatId,
},
},
});
}
if (text === "/ci") {
msgContent = await fetchCIMonitor();
}
if (msgContent) {
await lark.sendMsg("chat_id", chatId, "interactive", msgContent);
return true;
}
return false;
};
/**
*
*
* @param {LarkMessageEvent} body
*/
const replyNomalMsg = async (body: LarkMessageEvent) => {
const replyGuideMsg = async (body: LarkMessageEvent) => {
const chatId = getChatId(body);
const content = JSON.stringify({
type: "template",
@ -84,7 +113,7 @@ const replyNomalMsg = async (body: LarkMessageEvent) => {
* Event消息
* @param {LarkUserAction} body
*/
export const manageEventMsg = (body: LarkMessageEvent) => {
export const manageEventMsg = async (body: LarkMessageEvent) => {
// 过滤非Event消息
if (!getIsEventMsg(body)) {
return false;
@ -93,7 +122,11 @@ export const manageEventMsg = (body: LarkMessageEvent) => {
if (filterIllegalMsg(body)) {
return true;
}
// 临时返回消息
replyNomalMsg(body);
// 处理命令消息
if (await manageCMDMsg(body)) {
return true;
}
// 返回引导消息
replyGuideMsg(body);
return true;
};

View File

@ -8,7 +8,7 @@ export const manageBotReq = async (req: Request) => {
return Response.json({ challenge: body?.challenge });
}
// 处理Event消息
if (manageEventMsg(body)) return new Response("success");
if (await manageEventMsg(body)) return new Response("success");
// 处理Action消息
if (manageActionMsg(body)) return new Response("success");
return new Response("hello, glade to see you!");