mirror of
https://github.com/zhigang1992/telert.git
synced 2026-01-12 08:24:41 +08:00
feat: implement GET endpoint for webhook chat retrieval and message sending
This commit is contained in:
27
src/index.ts
27
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}`
|
||||
|
||||
Reference in New Issue
Block a user