From f38780692429a17b5e3c1f0860a1e71ead429f53 Mon Sep 17 00:00:00 2001
From: zhaoyingbo <zhaoyingbo@xiaomi.com>
Date: Fri, 8 Mar 2024 19:15:14 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=A5=E5=8F=A3=E6=94=B9=E4=B8=BA?=
 =?UTF-8?q?=E8=BF=94=E5=9B=9EJSON?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 controllers/manageRobot/index.ts | 26 ++++++++++++--------------
 index.ts                         |  2 +-
 2 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/controllers/manageRobot/index.ts b/controllers/manageRobot/index.ts
index c913db1..149bfd3 100644
--- a/controllers/manageRobot/index.ts
+++ b/controllers/manageRobot/index.ts
@@ -97,24 +97,22 @@ const getProjDiffInfo = async () => {
   return group.slice(0, 5);
 };
 
-const sendRobotMsg = async () => {
-  const msgContent = {
-    type: "template",
-    data: {
-      template_id: "ctp_AAyVLS6Q37cL",
-      template_variable: {
-        ...(await getNewCicdStatus()),
-        ...(await getStatisticsInfo()),
-        group_table: await getProjDiffInfo(),
-      },
+const getRobotMsg = async () => JSON.stringify({
+  type: "template",
+  data: {
+    template_id: "ctp_AAyVLS6Q37cL",
+    template_variable: {
+      ...(await getNewCicdStatus()),
+      ...(await getStatisticsInfo()),
+      group_table: await getProjDiffInfo(),
     },
-  };
+  },
+})
 
-  const res = await service.sendMessage(JSON.stringify(msgContent));
-  console.log(res);
-};
+const sendRobotMsg = async () => await service.sendMessage(await getRobotMsg())
 
 const manageRobot = {
+  getRobotMsg,
   sendRobotMsg,
 };
 
diff --git a/index.ts b/index.ts
index 246eea3..e9a42d5 100644
--- a/index.ts
+++ b/index.ts
@@ -28,7 +28,7 @@ Bun.serve({
   async fetch(req) {
     const url = new URL(req.url);
     if (url.pathname === '/ci') {
-      await manageRobot.sendRobotMsg();
+      return Response.json(await manageRobot.getRobotMsg());
     }
     return new Response("OK");
   },