Skip to content

Commit

Permalink
feat(notification): add pushover (#55)
Browse files Browse the repository at this point in the history
Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
  • Loading branch information
therrell and jef committed Sep 19, 2020
1 parent 8aba7ec commit c85658b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.example
Expand Up @@ -8,6 +8,8 @@ SLACK_TOKEN="slack-token"
STORES="bestbuy,bandh,nvidia"
PHONE_NUMBER="1234567890"
PHONE_CARRIER="tmobile"
PUSHOVER_TOKEN="123pushover-token456"
PUSHOVER_USER="123pushover-user-key"
OPEN_BROWSER="true"
PLAY_SOUND="false"
SCREENSHOT="true"
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -25,6 +25,7 @@
"nodemailer": "^6.4.11",
"open": "^7.2.1",
"puppeteer": "^5.3.0",
"pushover-notifications": "^1.2.2",
"winston": "^3.3.3"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions src/config.ts
Expand Up @@ -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'
};
Expand Down
5 changes: 5 additions & 0 deletions src/notification/notification.ts
Expand Up @@ -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) {
Expand All @@ -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();
}
Expand Down
22 changes: 22 additions & 0 deletions src/notification/pushover.ts
@@ -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 change: 1 addition & 0 deletions src/types/pushover-notifications.d.ts
@@ -0,0 +1 @@
declare module 'pushover-notifications';

0 comments on commit c85658b

Please sign in to comment.