mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-03-07 12:00:01 +03:00
Added ability to set a webhook proxy for telegram requests
Fixed issue where config changes were broadcast before they were written
This commit is contained in:
@@ -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": ""
|
||||
|
||||
@@ -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": "",
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -426,6 +426,13 @@
|
||||
<mat-hint><a target="_blank" href="https://stackoverflow.com/a/37396871/8088021"><ng-container i18n="Telegram chat ID help">How do I get the chat ID?</ng-container></a></mat-hint>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div class="col-12 mb-2">
|
||||
<mat-form-field class="text-field" color="accent">
|
||||
<mat-label i18n="Telegram webhook proxy">Telegram webhook proxy</mat-label>
|
||||
<input placeholder="https://smee.io/XXXXX" [disabled]="!new_config['Extra']['enable_notifications'] || !new_config['API']['use_telegram_API']" [(ngModel)]="new_config['API']['telegram_webhook_proxy']" matInput>
|
||||
<mat-hint><a target="_blank" href="https://smee.io/"><ng-container i18n="Telegram webhook proxy help">Example service</ng-container></a></mat-hint>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
Reference in New Issue
Block a user