feat: 添加通过ChatID发送CI报告的功能
This commit is contained in:
parent
6cb7a26ad5
commit
7d90bd368e
@ -96,6 +96,10 @@ const getProjDiffInfo = async () => {
|
||||
return group.slice(0, 5);
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取机器人消息
|
||||
* @returns
|
||||
*/
|
||||
const getRobotMsg = async () =>
|
||||
JSON.stringify({
|
||||
type: "template",
|
||||
@ -112,11 +116,24 @@ const getRobotMsg = async () =>
|
||||
},
|
||||
});
|
||||
|
||||
const sendRobotMsg = async () => await service.sendMessage(await getRobotMsg());
|
||||
/**
|
||||
* 通过ChatID发送CI报告
|
||||
* @param chat_id
|
||||
*/
|
||||
const sendCIReportByChatId = async (chat_id: string) => {
|
||||
await service.sendMessage.byChatId(chat_id, await getRobotMsg());
|
||||
};
|
||||
|
||||
/**
|
||||
* 通过定时任务发送CI报告
|
||||
* @returns
|
||||
*/
|
||||
const sendCIReportByCron = async () =>
|
||||
await service.sendMessage.byGroupId("52usf3w8l6z4vs1", await getRobotMsg());
|
||||
|
||||
const manageRobot = {
|
||||
getRobotMsg,
|
||||
sendRobotMsg,
|
||||
sendCIReportByChatId,
|
||||
sendCIReportByCron,
|
||||
};
|
||||
|
||||
export default manageRobot;
|
||||
|
15
index.ts
15
index.ts
@ -22,13 +22,22 @@ main();
|
||||
|
||||
scheduleJob("*/15 * * * *", main);
|
||||
|
||||
scheduleJob("0 10 * * 5", manageRobot.sendRobotMsg);
|
||||
scheduleJob("0 10 * * 5", manageRobot.sendCIReportByCron);
|
||||
|
||||
Bun.serve({
|
||||
async fetch(req) {
|
||||
const url = new URL(req.url);
|
||||
if (url.pathname === '/ci') {
|
||||
return Response.json(await manageRobot.getRobotMsg());
|
||||
if (url.pathname === "/ci") {
|
||||
const chat_id = url.searchParams.get("chat_id");
|
||||
console.log("🚀 ~ fetch ~ chat_id:", chat_id);
|
||||
if (!chat_id)
|
||||
return new Response("chat_id is required!", { status: 400 });
|
||||
manageRobot.sendCIReportByChatId(chat_id);
|
||||
return Response.json({
|
||||
code: 0,
|
||||
msg: "success",
|
||||
data: "reporting...",
|
||||
});
|
||||
}
|
||||
return new Response("OK");
|
||||
},
|
||||
|
@ -62,26 +62,41 @@ const fetchPipelineDetails = async (
|
||||
}
|
||||
};
|
||||
|
||||
const sendMessage = async (content: string) => {
|
||||
const sendMessage = async (body: string) => {
|
||||
try {
|
||||
const response = await fetch("https://egg.imoaix.cn/message", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
group_id: "52usf3w8l6z4vs1",
|
||||
msg_type: "interactive",
|
||||
content,
|
||||
}),
|
||||
body,
|
||||
});
|
||||
const body = await response.json();
|
||||
return body;
|
||||
const res = await response.json();
|
||||
return res;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
sendMessage.byGroupId = async (group_id: string, content: string) => {
|
||||
const body = JSON.stringify({
|
||||
group_id,
|
||||
msg_type: "interactive",
|
||||
content,
|
||||
});
|
||||
return sendMessage(body);
|
||||
};
|
||||
|
||||
sendMessage.byChatId = async (chat_id: string, content: string) => {
|
||||
const body = JSON.stringify({
|
||||
receive_id: chat_id,
|
||||
receive_id_type: "chat_id",
|
||||
msg_type: "interactive",
|
||||
content,
|
||||
});
|
||||
return sendMessage(body);
|
||||
};
|
||||
|
||||
const service = {
|
||||
fetchProjectDetails,
|
||||
fetchPipelines,
|
||||
|
Loading…
x
Reference in New Issue
Block a user