From dd58a30b7ac0bd5d5b16c735d5d72e046aa7fba0 Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Fri, 16 May 2025 06:52:59 +0000 Subject: [PATCH] feat: implement GET endpoint for webhook chat retrieval and message sending --- src/index.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/index.ts b/src/index.ts index 466bd56..fe06711 100644 --- a/src/index.ts +++ b/src/index.ts @@ -83,6 +83,33 @@ router.post("/t/:webhookId", async (context) => { context.res.body = { ok: true }; }); +router.get("/t/:webhookId", async (context) => { + const chat = await TG_GROUPS.get( + `webhook-chat:${context.req.params.webhookId}` + ); + if (chat == null) { + context.res.body = { ok: false, error: "chatId not found" }; + context.res.status = 404; + return; + } + + const search = context.req.url.searchParams; + const result: RichMessage = { + event: search.get("event") || "Unknown Event", + text: search.get("text") || undefined, + channel: search.get("channel") || undefined, + emoji: search.get("emoji") || undefined, + notify: search.get("notify") !== "false", + metadata: search.get("metadata") ? JSON.parse(search.get("metadata") || "{}") : undefined, + }; + + await sendToChat(JSON.parse(chat), formatRichMessage(result), { + parseMode: "HTML", + disableNotification: result.notify === false, + }); + context.res.body = { ok: true }; +}); + router.post("/t/:webhookId/map", async (context) => { const chat = await TG_GROUPS.get( `webhook-chat:${context.req.params.webhookId}`