From fc3f2a1579b5c3355c6100e1296313aed2e5f71d Mon Sep 17 00:00:00 2001 From: chaos-zhu Date: Wed, 4 Feb 2026 20:47:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81tg=E5=8F=8D=E4=BB=A3?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 2 ++ .gitignore | 3 ++- server/utils/notification.js | 19 ++++++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..b77c918 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +# tg发送消息的反代地址 +TELEGRAM_API_URL=https://xxx.com \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5120225..ab4f32b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ node_modules db uploads .output -dist \ No newline at end of file +dist +.env \ No newline at end of file diff --git a/server/utils/notification.js b/server/utils/notification.js index 0d5f4ad..466d2d4 100644 --- a/server/utils/notification.js +++ b/server/utils/notification.js @@ -293,7 +293,14 @@ async function sendTelegramNotification(config, payload) { try { console.log('[Notification] Telegram 通知预发送:', payload.title) - const bot = new TelegramBot(telegram.token) + // 创建 Bot 实例,从环境变量读取 API 地址(用于反代) + const botOptions = {} + const apiUrl = process.env.TELEGRAM_API_URL + if (apiUrl) { + botOptions.baseApiUrl = apiUrl + console.log('[Notification] 使用自定义 Telegram API 地址:', apiUrl) + } + const bot = new TelegramBot(telegram.token, botOptions) const chatId = Number(telegram.chatId) // 检查是否有有效的图片URL需要发送 @@ -777,8 +784,14 @@ export async function testTelegram(telegramConfig) { const message = `*测试通知*\n这是一条测试通知,用于验证 Telegram 配置是否正确。\n\n_发送时间: ${new Date().toISOString()}_` - // 使用 node-telegram-bot-api 发送消息 - const bot = new TelegramBot(telegramConfig.token) + // 创建 Bot 实例,从环境变量读取 API 地址(用于反代) + const botOptions = {} + const apiUrl = process.env.TELEGRAM_API_URL + if (apiUrl) { + botOptions.baseApiUrl = apiUrl + console.log('[Notification] 使用自定义 Telegram API 地址:', apiUrl) + } + const bot = new TelegramBot(telegramConfig.token, botOptions) await bot.sendMessage(Number(telegramConfig.chatId), message, { parse_mode: 'Markdown' }) console.log('[Notification] Telegram 测试通知发送成功')