59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import { sleep } from "bun";
|
|
import { fetchCIMonitor } from "../../service";
|
|
import { getActionType, getIsActionMsg } from "../../utils/msgTools";
|
|
import { updateCard } from "../../utils/sendMsg";
|
|
|
|
const makeChatIdCard = async (body: LarkUserAction) => {
|
|
await sleep(500);
|
|
return JSON.stringify({
|
|
type: "template",
|
|
data: {
|
|
config: {
|
|
update_multi: true,
|
|
},
|
|
template_id: "ctp_AAi3NnHb6zgK",
|
|
template_variable: {
|
|
chat_id: body.open_chat_id,
|
|
},
|
|
},
|
|
});
|
|
};
|
|
|
|
const ACTION_MAP = {
|
|
chat_id: makeChatIdCard,
|
|
ci: fetchCIMonitor,
|
|
};
|
|
|
|
/**
|
|
* 处理按钮点击事件
|
|
* @param {LarkUserAction} body
|
|
*/
|
|
const manageBtnClick = async (body: LarkUserAction) => {
|
|
const { action } = body?.action?.value as {
|
|
action: keyof typeof ACTION_MAP;
|
|
};
|
|
if (!action) return;
|
|
const func = ACTION_MAP[action];
|
|
if (!func) return;
|
|
const card = await func(body);
|
|
if (!card) return;
|
|
// 更新飞书的卡片
|
|
await updateCard(body.open_message_id, card);
|
|
};
|
|
|
|
/**
|
|
* 处理Action消息
|
|
* @param {LarkUserAction} body
|
|
*/
|
|
export const manageActionMsg = (body: LarkUserAction) => {
|
|
// 过滤非Action消息
|
|
if (!getIsActionMsg(body)) {
|
|
return false;
|
|
}
|
|
const actionType = getActionType(body);
|
|
if (actionType === "button") {
|
|
manageBtnClick(body);
|
|
}
|
|
return true;
|
|
};
|