feat: 添加CI监控命令处理
This commit is contained in:
parent
eb7a821549
commit
a280ae9f70
@ -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;
|
||||
};
|
||||
|
@ -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!");
|
||||
|
Loading…
x
Reference in New Issue
Block a user