From 4b770ad07ccd160ffc85d6e1b67bd31eec3ffcc6 Mon Sep 17 00:00:00 2001 From: oiov Date: Sat, 21 Jun 2025 16:52:19 +0800 Subject: [PATCH] feats(email): add telegram pusher --- README-zh.md | 2 + README.md | 2 + app/(protected)/admin/system/app-configs.tsx | 383 +++++++++++++----- app/api/admin/configs/route.ts | 5 + app/api/v1/email-catcher/route.ts | 176 +++++++- app/manifest.json | 2 +- content/docs/developer/telegram-bot.mdx | 4 + locales/en.json | 14 +- locales/zh.json | 16 +- package.json | 2 +- .../migrations/20250621130829/migration.sql | 95 +++++ public/manifest.json | 2 +- public/site.webmanifest | 2 +- public/sw.js.map | 2 +- 14 files changed, 594 insertions(+), 113 deletions(-) create mode 100644 content/docs/developer/telegram-bot.mdx create mode 100644 prisma/migrations/20250621130829/migration.sql diff --git a/README-zh.md b/README-zh.md index 7dce8c3..b1041eb 100644 --- a/README-zh.md +++ b/README-zh.md @@ -28,6 +28,8 @@ WR.DO 是一个一站式网络工具平台,集成短链服务、临时邮箱 - 可创建无限数量邮箱 - 支持接收无限制邮件 (依赖 Cloudflare Email Worker) - 支持发送邮件(依赖 Resend) + - 支持 Catch-All 配置 + - 支持 Telegram 推送(多频道/群组) - 支持调用 API 创建邮箱 - 支持调用 API 获取收件箱邮件 - diff --git a/README.md b/README.md index cae830d..c983c30 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ WR.DO is a all-in-one web utility platform featuring short links with analytics, - Unlimited mailbox creation - Receive unlimited emails (powered by Cloudflare Email Worker) - Send emails (powered by Resend) + - Support catch-all emails + - Support push to telegram groups - API endpoints for mailbox creation - API endpoints for inbox retrieval diff --git a/app/(protected)/admin/system/app-configs.tsx b/app/(protected)/admin/system/app-configs.tsx index 747b6da..e47fe39 100644 --- a/app/(protected)/admin/system/app-configs.tsx +++ b/app/(protected)/admin/system/app-configs.tsx @@ -1,6 +1,7 @@ "use client"; import { useEffect, useState, useTransition } from "react"; +import Link from "next/link"; import { useTranslations } from "next-intl"; import { toast } from "sonner"; import useSWR from "swr"; @@ -14,6 +15,7 @@ import { CollapsibleContent, CollapsibleTrigger, } from "@/components/ui/collapsible"; +import { Input } from "@/components/ui/input"; import { Skeleton } from "@/components/ui/skeleton"; import { Switch } from "@/components/ui/switch"; import { Textarea } from "@/components/ui/textarea"; @@ -31,15 +33,21 @@ export default function AppConfigs({}: {}) { } = useSWR>("/api/admin/configs", fetcher); const [notification, setNotification] = useState(""); const [catchAllEmails, setCatchAllEmails] = useState(""); + const [tgBotToken, setTgBotToken] = useState(""); + const [tgChatId, setTgChatId] = useState(""); + const [tgTemplate, setTgTemplate] = useState(""); + const [tgWhiteList, setTgWhiteList] = useState(""); const t = useTranslations("Setting"); useEffect(() => { - if (!isLoading && configs?.system_notification) { - setNotification(configs.system_notification); - } - if (!isLoading && configs?.catch_all_emails) { - setCatchAllEmails(configs.catch_all_emails); + if (!isLoading && configs) { + setNotification(configs?.system_notification); + setCatchAllEmails(configs?.catch_all_emails); + setTgBotToken(configs?.tg_email_bot_token); + setTgChatId(configs?.tg_email_chat_id); + setTgTemplate(configs?.tg_email_template); + setTgWhiteList(configs?.tg_email_target_white_list); } // 计算登录方式数量 if (!isLoading) { @@ -60,10 +68,10 @@ export default function AppConfigs({}: {}) { body: JSON.stringify({ key, value, type }), }); if (res.ok) { - toast.success("Updated!"); + toast.success("Saved"); mutate(); } else { - toast.error("Failed!", { + toast.error("Failed to save", { description: await res.text(), }); } @@ -71,11 +79,7 @@ export default function AppConfigs({}: {}) { }; if (isLoading) { - return ( - <> - - - ); + return ; } return ( @@ -86,7 +90,7 @@ export default function AppConfigs({}: {}) { - +
@@ -229,9 +233,6 @@ export default function AppConfigs({}: {}) { ) } > - {isPending && ( - - )} {t("Save")}
@@ -249,90 +250,279 @@ export default function AppConfigs({}: {}) { - +
{/* Catch-All */} -
-
-

- Catch-All Beta -

-

- {t( - "Enable email catch-all, all user's email address which created on this platform will be redirected to the catch-all email address", - )} -

-
- {configs && ( - - handleChange(v, "enable_email_catch_all", "BOOLEAN") - } - /> - )} -
-
-
-

{t("Catch-All Email Address")}

-

- {t( - "Set catch-all email address, split by comma if more than one, such as: 1@a-com,2@b-com, Only works when email catch all is enabled", - )} -

-
- {configs && ( -
-