diff --git a/backend/config.js b/backend/config.js index 96d480e..d8de131 100644 --- a/backend/config.js +++ b/backend/config.js @@ -221,7 +221,8 @@ const DEFAULT_CONFIG = { "gotify_app_token": "", "use_telegram_API": false, "telegram_bot_token": "", - "telegram_chat_id": "" + "telegram_chat_id": "", + "webhook_URL": "" }, "Themes": { "default_theme": "default", diff --git a/backend/consts.js b/backend/consts.js index 3e681cb..714afcc 100644 --- a/backend/consts.js +++ b/backend/consts.js @@ -166,6 +166,10 @@ exports.CONFIG_ITEMS = { 'key': 'ytdl_telegram_chat_id', 'path': 'YoutubeDLMaterial.API.telegram_chat_id' }, + 'ytdl_webhook_url': { + 'key': 'ytdl_webhook_url', + 'path': 'YoutubeDLMaterial.API.webhook_URL' + }, // Themes diff --git a/backend/notifications.js b/backend/notifications.js index 12ec791..dac8700 100644 --- a/backend/notifications.js +++ b/backend/notifications.js @@ -36,20 +36,28 @@ const NOTIFICATION_TYPE_TO_THUMBNAIL = { exports.sendNotification = async (notification) => { // info necessary if we are using 3rd party APIs const type = notification['type']; - const title = NOTIFICATION_TYPE_TO_TITLE[type]; - const body = NOTIFICATION_TYPE_TO_BODY[type](notification); - const url = NOTIFICATION_TYPE_TO_URL[type](notification); - const thumbnail = NOTIFICATION_TYPE_TO_THUMBNAIL[type](notification); + + const data = { + title: NOTIFICATION_TYPE_TO_TITLE[type], + body: NOTIFICATION_TYPE_TO_BODY[type](notification), + type: type, + url: NOTIFICATION_TYPE_TO_URL[type](notification), + thumbnail: NOTIFICATION_TYPE_TO_THUMBNAIL[type](notification) + } if (config_api.getConfigItem('ytdl_use_ntfy_API') && config_api.getConfigItem('ytdl_ntfy_topic_url')) { - sendNtfyNotification(body, title, type, url, thumbnail); + sendNtfyNotification(data); } if (config_api.getConfigItem('ytdl_use_gotify_API') && config_api.getConfigItem('ytdl_gotify_server_url') && config_api.getConfigItem('ytdl_gotify_app_token')) { - sendGotifyNotification(body, title, type, url, thumbnail); + sendGotifyNotification(data); } if (config_api.getConfigItem('ytdl_use_telegram_API') && config_api.getConfigItem('ytdl_telegram_bot_token') && config_api.getConfigItem('ytdl_telegram_chat_id')) { - sendTelegramNotification(body, title, type, url, thumbnail); + sendTelegramNotification(data); } + if (config_api.getConfigItem('ytdl_webhook_url')) { + sendGenericNotification(data); + } + await db_api.insertRecordIntoTable('notifications', notification); return notification; } @@ -95,7 +103,7 @@ function notificationEnabled(type) { return config_api.getConfigItem('ytdl_enable_notifications') && (config_api.getConfigItem('ytdl_enable_all_notifications') || config_api.getConfigItem('ytdl_allowed_notification_types').includes(type)); } -function sendNtfyNotification(body, title, type, url, thumbnail) { +function sendNtfyNotification({body, title, type, url, thumbnail}) { logger.verbose('Sending notification to ntfy'); fetch(config_api.getConfigItem('ytdl_ntfy_topic_url'), { method: 'POST', @@ -109,7 +117,7 @@ function sendNtfyNotification(body, title, type, url, thumbnail) { }); } -async function sendGotifyNotification(body, title, type, url, thumbnail) { +async function sendGotifyNotification({body, title, type, url, thumbnail}) { logger.verbose('Sending notification to gotify'); await gotify({ server: config_api.getConfigItem('ytdl_gotify_server_url'), @@ -127,11 +135,23 @@ async function sendGotifyNotification(body, title, type, url, thumbnail) { }); } -async function sendTelegramNotification(body, title, type, url, thumbnail) { +async function sendTelegramNotification({body, title, type, url, thumbnail}) { logger.verbose('Sending notification to Telegram'); const bot_token = config_api.getConfigItem('ytdl_telegram_bot_token'); const chat_id = config_api.getConfigItem('ytdl_telegram_chat_id'); const bot = new TelegramBot(bot_token); if (thumbnail) await bot.sendPhoto(chat_id, thumbnail); bot.sendMessage(chat_id, `${title}\n\n${body}\n${url}`, {parse_mode: 'HTML'}); +} + +function sendGenericNotification(data) { + const webhook_url = config_api.getConfigItem('ytdl_webhook_url'); + logger.verbose(`Sending generic notification to ${webhook_url}`); + fetch(webhook_url, { + method: 'POST', + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify(data), + }); } \ No newline at end of file diff --git a/src/app/settings/settings.component.html b/src/app/settings/settings.component.html index 7077f50..aa44d98 100644 --- a/src/app/settings/settings.component.html +++ b/src/app/settings/settings.component.html @@ -393,6 +393,13 @@ +