Added support for custom webhook URLs for notifications

pull/860/head
Tzahi12345 2 years ago
parent 7593a23c2e
commit fb27264d33

@ -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",

@ -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

@ -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, `<b>${title}</b>\n\n${body}\n<a href="${url}">${url}</a>`, {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),
});
}

@ -393,6 +393,13 @@
</mat-select>
</mat-form-field>
</div>
<div class="col-12 mb-2 mt-2">
<mat-form-field class="text-field" color="accent">
<mat-label i18n="webhook URL">Webhook URL</mat-label>
<input placeholder="https://example.com/endpoint/12345" [(ngModel)]="new_config['API']['webhook_URL']" matInput>
<mat-hint>Place endpoint URL here to integrate with services like Zapier and Automatisch.</mat-hint>
</mat-form-field>
</div>
<div class="col-12 mt-3">
<mat-checkbox color="accent" [disabled]="!new_config['Extra']['enable_notifications']" [(ngModel)]="new_config['API']['use_ntfy_API']"><ng-container i18n="Use ntfy API setting">Use ntfy API</ng-container></mat-checkbox>
</div>

Loading…
Cancel
Save