diff --git a/backend/config.js b/backend/config.js index 2bfdec9..a5ee5df 100644 --- a/backend/config.js +++ b/backend/config.js @@ -220,7 +220,8 @@ const DEFAULT_CONFIG = { "telegram_bot_token": "", "telegram_chat_id": "", "webhook_URL": "", - "discord_webhook_URL": "" + "discord_webhook_URL": "", + "slack_webhook_URL": "", }, "Themes": { "default_theme": "default", diff --git a/backend/consts.js b/backend/consts.js index 49f7634..4461819 100644 --- a/backend/consts.js +++ b/backend/consts.js @@ -162,6 +162,10 @@ exports.CONFIG_ITEMS = { 'key': 'ytdl_discord_webhook_url', 'path': 'YoutubeDLMaterial.API.discord_webhook_URL' }, + 'ytdl_slack_webhook_url': { + 'key': 'ytdl_slack_webhook_url', + 'path': 'YoutubeDLMaterial.API.slack_webhook_URL' + }, // Themes diff --git a/backend/notifications.js b/backend/notifications.js index 5e64283..0cb51d1 100644 --- a/backend/notifications.js +++ b/backend/notifications.js @@ -64,6 +64,9 @@ exports.sendNotification = async (notification) => { if (config_api.getConfigItem('ytdl_discord_webhook_url')) { sendDiscordNotification(data); } + if (config_api.getConfigItem('ytdl_slack_webhook_url')) { + sendSlackNotification(data); + } await db_api.insertRecordIntoTable('notifications', notification); return notification; @@ -174,6 +177,65 @@ async function sendDiscordNotification({body, title, type, url, thumbnail}) { return result; } +function sendSlackNotification({body, title, type, url, thumbnail}) { + const slack_webhook_url = config_api.getConfigItem('ytdl_slack_webhook_url'); + logger.verbose(`Sending slack notification to ${slack_webhook_url}`); + const data = { + blocks: [ + { + type: "section", + text: { + type: "mrkdwn", + text: `*${title}*` + } + }, + { + type: "section", + text: { + type: "plain_text", + text: body + } + } + ] + } + + // add thumbnail if exists + if (thumbnail) { + data['blocks'].push({ + type: "image", + image_url: thumbnail, + alt_text: "notification_thumbnail" + }); + } + + data['blocks'].push( + { + type: "section", + text: { + type: "mrkdwn", + text: `<${url}|${url}>` + } + }, + { + type: "context", + elements: [ + { + type: "mrkdwn", + text: `*ID:* ${type}` + } + ] + } + ); + + fetch(slack_webhook_url, { + method: 'POST', + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify(data), + }); +} + function sendGenericNotification(data) { const webhook_url = config_api.getConfigItem('ytdl_webhook_url'); logger.verbose(`Sending generic notification to ${webhook_url}`); diff --git a/src/app/settings/settings.component.html b/src/app/settings/settings.component.html index 78ba4cd..59b12d8 100644 --- a/src/app/settings/settings.component.html +++ b/src/app/settings/settings.component.html @@ -387,9 +387,16 @@