mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 11:07:43 +00:00
feat(notification): add telegram (#71)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
})();
|
||||
}
|
||||
Reference in New Issue
Block a user