feat: 支持插件化功能
This commit is contained in:
parent
3b97b1def5
commit
3c36f59a1d
@ -1,20 +1,24 @@
|
||||
import { sleep } from "bun";
|
||||
import { fetchCIMonitor } from "../../service";
|
||||
import { getActionType, getIsActionMsg } from "../../utils/msgTools";
|
||||
import { updateCard } from "../../utils/sendMsg";
|
||||
|
||||
const makeChatIdCard = (body: LarkUserAction) => {
|
||||
return JSON.stringify({ text: `chatId: ${body.open_chat_id}` });
|
||||
};
|
||||
|
||||
const makeCICard = async () => {
|
||||
const card = await fetchCIMonitor();
|
||||
if (!card) return "";
|
||||
return JSON.stringify(card);
|
||||
const makeChatIdCard = async (body: LarkUserAction) => {
|
||||
await sleep(500);
|
||||
return JSON.stringify({
|
||||
type: "template",
|
||||
data: {
|
||||
template_id: "ctp_AAi3NnHb6zgK",
|
||||
template_variable: {
|
||||
chat_id: body.open_chat_id,
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const ACTION_MAP = {
|
||||
chat_id: makeChatIdCard,
|
||||
ci: makeCICard,
|
||||
ci: fetchCIMonitor,
|
||||
};
|
||||
|
||||
/**
|
||||
@ -26,7 +30,9 @@ const manageBtnClick = async (body: LarkUserAction) => {
|
||||
action: keyof typeof ACTION_MAP;
|
||||
};
|
||||
if (!action) return;
|
||||
const card = await ACTION_MAP[action](body);
|
||||
const func = ACTION_MAP[action];
|
||||
if (!func) return;
|
||||
const card = await func(body);
|
||||
if (!card) return;
|
||||
// 更新飞书的卡片
|
||||
await updateCard(body.open_message_id, card);
|
||||
@ -36,7 +42,7 @@ const manageBtnClick = async (body: LarkUserAction) => {
|
||||
* 处理Action消息
|
||||
* @param {LarkUserAction} body
|
||||
*/
|
||||
export const manageActionMsg = async (body: LarkUserAction) => {
|
||||
export const manageActionMsg = (body: LarkUserAction) => {
|
||||
// 过滤非Action消息
|
||||
if (!getIsActionMsg(body)) {
|
||||
return false;
|
||||
|
@ -70,7 +70,7 @@ const replyNomalMsg = async (body: LarkMessageEvent) => {
|
||||
* 处理Event消息
|
||||
* @param {LarkUserAction} body
|
||||
*/
|
||||
export const manageEventMsg = async (body: LarkMessageEvent) => {
|
||||
export const manageEventMsg = (body: LarkMessageEvent) => {
|
||||
// 过滤非Event消息
|
||||
if (!getIsEventMsg(body)) {
|
||||
return false;
|
||||
|
@ -5,12 +5,11 @@ export const manageBotReq = async (req: Request) => {
|
||||
const body = (await req.json()) as any;
|
||||
// 验证机器人
|
||||
if (body?.type === "url_verification") {
|
||||
console.log("🚀 ~ manageBotReq ~ url_verification:");
|
||||
return Response.json({ challenge: body?.challenge });
|
||||
}
|
||||
// 处理Event消息
|
||||
if (await manageEventMsg(body)) return new Response("success");
|
||||
if (manageEventMsg(body)) return new Response("success");
|
||||
// 处理Action消息
|
||||
if (await manageActionMsg(body)) return new Response("success");
|
||||
if (manageActionMsg(body)) return new Response("success");
|
||||
return new Response("hello, glade to see you!");
|
||||
};
|
||||
|
@ -1,8 +1,8 @@
|
||||
export const fetchCIMonitor = async () => {
|
||||
try {
|
||||
const res = await fetch("https://ci-monitor.xiaomiwh.cn/ci");
|
||||
return (await res.json()) as any;
|
||||
return ((await res.json()) as string) || "";
|
||||
} catch {
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user