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 测试通知发送成功')