feat(notification): add telegram (#71)

This commit is contained in:
Mark Dietzer
2020-09-19 14:02:00 -07:00
committed by GitHub
parent d4de1a4638
commit 393d5f6898
13 changed files with 252 additions and 32 deletions
+6 -1
View File
@@ -4,6 +4,7 @@ import {sendSMS} from './sms';
import {playSound} from './sound';
import {sendSlackMessage} from './slack';
import sendPushoverNotification from './pushover';
import {sendTelegramMessage} from './telegram';
export function sendNotification(cartUrl: string) {
if (Config.notifications.email.username && Config.notifications.email.password) {
@@ -14,6 +15,10 @@ export function sendNotification(cartUrl: string) {
sendSlackMessage(cartUrl);
}
if (Config.notifications.telegram.botToken && Config.notifications.telegram.chatId) {
sendTelegramMessage(cartUrl);
}
if (Config.notifications.phone.number) {
const carrier = Config.notifications.phone.carrier.toLowerCase();
if (carrier && Config.notifications.phone.availableCarriers.has(carrier)) {
@@ -25,7 +30,7 @@ export function sendNotification(cartUrl: string) {
sendPushoverNotification(cartUrl);
}
if (Config.notifications.playSound) {
if (Config.notifications.playSound !== 'false') {
playSound();
}
}
+21
View File
@@ -0,0 +1,21 @@
import {Config} from '../config';
import {Logger} from '../logger';
import {TelegramClient} from 'messaging-api-telegram';
const chatId = Config.notifications.telegram.chatId;
const accessToken = Config.notifications.telegram.botToken;
const client = new TelegramClient({
accessToken
});
export function sendTelegramMessage(text: string) {
(async () => {
try {
await client.sendMessage(chatId, text);
Logger.info(`✔ telegram message sent to '${chatId}': ${text}`);
} catch (error) {
Logger.error(error);
}
})();
}