From ca00a877ad36c7ae11e0bb7fbe2210d7b7a2806f Mon Sep 17 00:00:00 2001 From: Dream Hunter Date: Sat, 18 May 2024 14:02:18 +0800 Subject: [PATCH] feat: telegram bot TelegramSettings && webhook (#244) * feat: telegram bot TelegramSettings * feat: webhook --- CHANGELOG.md | 6 + README.md | 1 + frontend/package.json | 2 +- frontend/src/api/index.js | 1 + frontend/src/views/Admin.vue | 58 +++++--- frontend/src/views/Index.vue | 4 + frontend/src/views/admin/Account.vue | 2 +- frontend/src/views/admin/Mails.vue | 2 +- frontend/src/views/admin/MailsUnknow.vue | 2 +- frontend/src/views/admin/Telegram.vue | 77 ++++++++++- frontend/src/views/admin/UserManagement.vue | 2 +- frontend/src/views/admin/Webhook.vue | 87 ++++++++++++ frontend/src/views/index/Webhook.vue | 130 ++++++++++++++++++ frontend/tsconfig.json | 13 ++ vitepress-docs/docs/en/cli.md | 2 + vitepress-docs/docs/zh/guide/cli/worker.md | 2 + worker/package.json | 2 +- worker/src/admin_api/index.js | 19 +-- worker/src/admin_api/webhook_settings.ts | 22 +++ worker/src/{commom_api.js => commom_api.ts} | 5 +- worker/src/constants.ts | 7 +- worker/src/{email.js => email/auto_reply.ts} | 42 ++---- worker/src/email/index.ts | 51 +++++++ worker/src/mails_api/index.js | 4 + worker/src/mails_api/webhook_settings.ts | 135 +++++++++++++++++++ worker/src/models/models.ts | 16 +++ worker/src/telegram_api/index.ts | 42 ++++-- worker/src/telegram_api/settings.ts | 30 +++++ worker/src/telegram_api/telegram.ts | 53 +++++--- worker/src/types.d.ts | 42 ++++++ worker/src/{worker.js => worker.ts} | 24 +++- worker/wrangler.toml.template | 2 + 32 files changed, 776 insertions(+), 111 deletions(-) create mode 100644 frontend/src/views/admin/Webhook.vue create mode 100644 frontend/src/views/index/Webhook.vue create mode 100644 frontend/tsconfig.json create mode 100644 worker/src/admin_api/webhook_settings.ts rename worker/src/{commom_api.js => commom_api.ts} (87%) rename worker/src/{email.js => email/auto_reply.ts} (50%) create mode 100644 worker/src/email/index.ts create mode 100644 worker/src/mails_api/webhook_settings.ts create mode 100644 worker/src/models/models.ts create mode 100644 worker/src/telegram_api/settings.ts create mode 100644 worker/src/types.d.ts rename worker/src/{worker.js => worker.ts} (86%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7592a428..1f32776d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGE LOG +## main branch + +- `telegram bot` 白名单配置 +- `ENABLE_WEBHOOK` 添加 webhook +- admin 页面使用双层 tab + ## v0.4.2 - 修复 smtp imap proxy sever 的一些 bug diff --git a/README.md b/README.md index 2e1cef21..fe8182bf 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ - [x] `admin` 后台创建无前缀邮箱 - [x] 添加 `SMTP proxy server`,支持 `SMTP` 发送邮件, `IMAP` 查看邮件 - [x] 添加完整的用户注册登录功能,可绑定邮箱地址,绑定后可自动获取邮箱JWT凭证切换不同邮箱 +- [x] `Telegram Bot` 使用,以及 `Telegram` 推送 ## Reference diff --git a/frontend/package.json b/frontend/package.json index 331063e5..8372b14a 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "cloudflare_temp_email", - "version": "0.4.2", + "version": "0.4.3", "private": true, "type": "module", "scripts": { diff --git a/frontend/src/api/index.js b/frontend/src/api/index.js index 2e1ce7d0..bb199d8d 100644 --- a/frontend/src/api/index.js +++ b/frontend/src/api/index.js @@ -69,6 +69,7 @@ const getOpenSettings = async (message) => { enableIndexAbout: res["enableIndexAbout"] || false, copyright: res["copyright"] || openSettings.value.copyright, cfTurnstileSiteKey: res["cfTurnstileSiteKey"] || "", + enableWebhook: res["enableWebhook"] || false, }); if (openSettings.value.needAuth) { showAuth.value = true; diff --git a/frontend/src/views/Admin.vue b/frontend/src/views/Admin.vue index f783d0c5..94d2a5a6 100644 --- a/frontend/src/views/Admin.vue +++ b/frontend/src/views/Admin.vue @@ -18,6 +18,7 @@ import About from './common/About.vue'; import Maintenance from './admin/Maintenance.vue'; import Appearance from './common/Appearance.vue'; import Telegram from './admin/Telegram.vue'; +import Webhook from './admin/Webhook.vue'; const { localeCache, adminAuth, showAdminAuth, adminTab, loading, globalTabplacement @@ -42,12 +43,14 @@ const { t } = useI18n({ account: 'Account', account_create: 'Create Account', account_settings: 'Account Settings', + user: 'User', user_management: 'User Management', user_settings: 'User Settings', unknow: 'Mails with unknow receiver', senderAccess: 'Sender Access Control', sendBox: 'Send Box', telegram: 'Telegram Bot', + webhook: 'Webhook', statistics: 'Statistics', maintenance: 'Maintenance', appearance: 'Appearance', @@ -61,12 +64,14 @@ const { t } = useI18n({ account: '账号', account_create: '创建账号', account_settings: '账号设置', + user: '用户', user_management: '用户管理', user_settings: '用户设置', unknow: '无收件人邮件', senderAccess: '发件权限控制', sendBox: '发件箱', telegram: '电报机器人', + webhook: 'Webhook', statistics: '统计', maintenance: '维护', appearance: '外观', @@ -98,28 +103,43 @@ onMounted(async () => { - + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + - - - - - - - + + + + + + + + diff --git a/frontend/src/views/Index.vue b/frontend/src/views/Index.vue index 553e13d4..8d7d5662 100644 --- a/frontend/src/views/Index.vue +++ b/frontend/src/views/Index.vue @@ -10,6 +10,7 @@ import AutoReply from './index/AutoReply.vue'; import SendBox from './index/SendBox.vue'; import SendMail from './index/SendMail.vue'; import AccountSettings from './index/AccountSettings.vue'; +import WenHook from './index/Webhook.vue'; import About from './common/About.vue'; const { localeCache, settings, openSettings, indexTab, globalTabplacement } = useGlobalState() @@ -65,6 +66,9 @@ const deleteMail = async (curMailId) => { + + + diff --git a/frontend/src/views/admin/Account.vue b/frontend/src/views/admin/Account.vue index c1689542..7ebb8d25 100644 --- a/frontend/src/views/admin/Account.vue +++ b/frontend/src/views/admin/Account.vue @@ -261,7 +261,7 @@ onMounted(async () => {