Skip to content

Commit

Permalink
feat: add apprise support
Browse files Browse the repository at this point in the history
  • Loading branch information
oae committed Nov 4, 2022
1 parent 04c521d commit 7d6fe34
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions src/server/utils/notification.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
import TelegramBot from 'node-telegram-bot-api';

const token = process.env.TELEGRAM_TOKEN || '';
const chatId = process.env.TELEGRAM_CHAT_ID || '';
const disableNotification = !!parseInt(process.env.TELEGRAM_SEND_SILENTLY || '0', 10);
const bot = new TelegramBot(token);
import { prisma } from '../db/client';

export const sendNotification = async (title: string, body: string, url?: string) => {
if (!token || !chatId) {
return;
}
const settings = await prisma.settings.findFirstOrThrow();

const message = `
if (settings.telegramEnabled && settings.telegramChatId && settings.telegramToken) {
const bot = new TelegramBot(settings.telegramToken);
const message = `
<b>${title}</b>
${body}
${url || ''}
`;
await bot.sendMessage(chatId, message, { parse_mode: 'HTML', disable_notification: disableNotification });
`;
await bot.sendMessage(settings.telegramChatId, message, {
parse_mode: 'HTML',
disable_notification: settings.telegramSendSilently,
});
}

if (settings.appriseEnabled && settings.appriseHost && settings.appriseUrls.length !== 0) {
const appriseServiceUrl = new URL(
'/notify',
settings.appriseHost.toLowerCase().startsWith('http') ? settings.appriseHost : `http://${settings.appriseHost}`,
).href;
await fetch(appriseServiceUrl, {
body: JSON.stringify({
urls: settings.appriseUrls,
title,
body: `${body} ${url}`,
format: 'html',
}),
headers: {
'Content-Type': 'application/json',
},
method: 'POST',
});
}
};

0 comments on commit 7d6fe34

Please sign in to comment.