Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 7d6fe34

Browse files
committed
feat: add apprise support
1 parent 04c521d commit 7d6fe34

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

src/server/utils/notification.ts

+30-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
11
import TelegramBot from 'node-telegram-bot-api';
2-
3-
const token = process.env.TELEGRAM_TOKEN || '';
4-
const chatId = process.env.TELEGRAM_CHAT_ID || '';
5-
const disableNotification = !!parseInt(process.env.TELEGRAM_SEND_SILENTLY || '0', 10);
6-
const bot = new TelegramBot(token);
2+
import { prisma } from '../db/client';
73

84
export const sendNotification = async (title: string, body: string, url?: string) => {
9-
if (!token || !chatId) {
10-
return;
11-
}
5+
const settings = await prisma.settings.findFirstOrThrow();
126

13-
const message = `
7+
if (settings.telegramEnabled && settings.telegramChatId && settings.telegramToken) {
8+
const bot = new TelegramBot(settings.telegramToken);
9+
const message = `
1410
<b>${title}</b>
1511
1612
${body}
1713
1814
${url || ''}
19-
`;
20-
await bot.sendMessage(chatId, message, { parse_mode: 'HTML', disable_notification: disableNotification });
15+
`;
16+
await bot.sendMessage(settings.telegramChatId, message, {
17+
parse_mode: 'HTML',
18+
disable_notification: settings.telegramSendSilently,
19+
});
20+
}
21+
22+
if (settings.appriseEnabled && settings.appriseHost && settings.appriseUrls.length !== 0) {
23+
const appriseServiceUrl = new URL(
24+
'/notify',
25+
settings.appriseHost.toLowerCase().startsWith('http') ? settings.appriseHost : `http://${settings.appriseHost}`,
26+
).href;
27+
await fetch(appriseServiceUrl, {
28+
body: JSON.stringify({
29+
urls: settings.appriseUrls,
30+
title,
31+
body: `${body} ${url}`,
32+
format: 'html',
33+
}),
34+
headers: {
35+
'Content-Type': 'application/json',
36+
},
37+
method: 'POST',
38+
});
39+
}
2140
};

0 commit comments

Comments
 (0)