mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 09:57:38 +00:00
feat(notification): add pushover (#55)
Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
@@ -25,6 +25,10 @@ const notifications = {
|
||||
channel: process.env.SLACK_CHANNEL ?? '',
|
||||
token: process.env.SLACK_TOKEN ?? ''
|
||||
},
|
||||
pushover: {
|
||||
token: process.env.PUSHOVER_TOKEN,
|
||||
user: process.env.PUSHOVER_USER
|
||||
},
|
||||
test: process.env.NOTIFICATION_TEST ?? 'false',
|
||||
playSound: process.env.PLAY_SOUND ?? 'false'
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@ import {sendEmail} from './email';
|
||||
import {sendSMS} from './sms';
|
||||
import {playSound} from './sound';
|
||||
import {sendSlackMessage} from './slack';
|
||||
import sendPushoverNotification from './pushover';
|
||||
|
||||
export function sendNotification(cartUrl: string) {
|
||||
if (Config.notifications.email.username && Config.notifications.email.password) {
|
||||
@@ -20,6 +21,10 @@ export function sendNotification(cartUrl: string) {
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.notifications.pushover.token && Config.notifications.pushover.user) {
|
||||
sendPushoverNotification(cartUrl);
|
||||
}
|
||||
|
||||
if (Config.notifications.playSound) {
|
||||
playSound();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import {Config} from '../config';
|
||||
import {Logger} from '../logger';
|
||||
import Push = require('pushover-notifications');
|
||||
|
||||
const p = new Push({
|
||||
user: Config.notifications.pushover.user,
|
||||
token: Config.notifications.pushover.token
|
||||
});
|
||||
|
||||
export default function sendPushoverNotification(text: string) {
|
||||
const message = {
|
||||
message: text
|
||||
};
|
||||
|
||||
p.send(message, (err: Error, result: string) => {
|
||||
if (err) {
|
||||
Logger.error(err);
|
||||
} else {
|
||||
Logger.info(`✔ Pushover notification sent: ${result}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
declare module 'pushover-notifications';
|
||||
Reference in New Issue
Block a user