diff --git a/backend/appdata/default.json b/backend/appdata/default.json index 1bd7305..ea1b448 100644 --- a/backend/appdata/default.json +++ b/backend/appdata/default.json @@ -49,6 +49,7 @@ "use_telegram_API": false, "telegram_bot_token": "", "telegram_chat_id": "", + "telegram_webhook_proxy": "", "webhook_URL": "", "discord_webhook_URL": "", "slack_webhook_URL": "" diff --git a/backend/config.js b/backend/config.js index afb02fd..43f7d17 100644 --- a/backend/config.js +++ b/backend/config.js @@ -85,11 +85,11 @@ exports.getConfigFile = () => { exports.setConfigFile = (config) => { try { const old_config = exports.getConfigFile(); + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); const changes = exports.findChangedConfigItems(old_config, config); if (changes.length > 0) { for (const change of changes) exports.config_updated.next(change); } - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); return true; } catch(e) { return false; @@ -239,6 +239,7 @@ const DEFAULT_CONFIG = { "use_telegram_API": false, "telegram_bot_token": "", "telegram_chat_id": "", + "telegram_webhook_proxy": "", "webhook_URL": "", "discord_webhook_URL": "", "slack_webhook_URL": "", diff --git a/backend/consts.js b/backend/consts.js index b092ca5..86cbb8c 100644 --- a/backend/consts.js +++ b/backend/consts.js @@ -154,6 +154,10 @@ exports.CONFIG_ITEMS = { 'key': 'ytdl_telegram_chat_id', 'path': 'YoutubeDLMaterial.API.telegram_chat_id' }, + 'ytdl_telegram_webhook_proxy': { + 'key': 'ytdl_telegram_webhook_proxy', + 'path': 'YoutubeDLMaterial.API.telegram_webhook_proxy' + }, 'ytdl_webhook_url': { 'key': 'ytdl_webhook_url', 'path': 'YoutubeDLMaterial.API.webhook_URL' diff --git a/backend/notifications.js b/backend/notifications.js index af5be13..5000029 100644 --- a/backend/notifications.js +++ b/backend/notifications.js @@ -14,8 +14,6 @@ const REST = require('@discordjs/rest').REST; const API = require('@discordjs/core').API; const EmbedBuilder = require('@discordjs/builders').EmbedBuilder; -const debugMode = process.env.YTDL_MODE === 'debug'; - const NOTIFICATION_TYPE_TO_TITLE = { task_finished: 'Task finished', download_complete: 'Download complete', @@ -160,7 +158,7 @@ config_api.config_updated.subscribe(change => { const bot_token = config_api.getConfigItem('ytdl_telegram_bot_token'); if (!use_telegram_api || !bot_token) return; if (!change) return; - if (change['key'] === 'ytdl_use_telegram_API' || change['key'] === 'ytdl_telegram_bot_token') { + if (change['key'] === 'ytdl_use_telegram_API' || change['key'] === 'ytdl_telegram_bot_token' || change['key'] === 'ytdl_telegram_webhook_proxy') { logger.debug('Telegram bot setting up'); setupTelegramBot(); } @@ -170,9 +168,10 @@ async function setupTelegramBot() { const use_telegram_api = config_api.getConfigItem('ytdl_use_telegram_API'); const bot_token = config_api.getConfigItem('ytdl_telegram_bot_token'); if (!use_telegram_api || !bot_token) return; - + telegram_bot = new TelegramBotAPI(bot_token); - const webhook_url = `${utils.getBaseURL()}/api/telegramRequest`; + const webhook_proxy = config_api.getConfigItem('ytdl_telegram_webhook_proxy'); + const webhook_url = webhook_proxy ? webhook_proxy : `${utils.getBaseURL()}/api/telegramRequest`; telegram_bot.setWebHook(webhook_url); } diff --git a/src/app/settings/settings.component.html b/src/app/settings/settings.component.html index 6d4ae4d..950820f 100644 --- a/src/app/settings/settings.component.html +++ b/src/app/settings/settings.component.html @@ -426,6 +426,13 @@ How do I get the chat ID? +
+ + Telegram webhook proxy + + Example service + +