diff --git a/.env.example b/.env.example index b74c718..46e30f7 100644 --- a/.env.example +++ b/.env.example @@ -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" diff --git a/package-lock.json b/package-lock.json index 09c3621..3de8c95 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4798,6 +4798,11 @@ "ws": "^7.2.3" } }, + "pushover-notifications": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/pushover-notifications/-/pushover-notifications-1.2.2.tgz", + "integrity": "sha512-+3Xcj+kiMiouZK1Ws8yGBTyl8WMPZZdELgl/iVxYqNwDdlaObBHMhEGPRC6Zb9t0BE27ikOoOqSIO1cKZOtsDA==" + }, "querystring": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz", diff --git a/package.json b/package.json index f7f829a..9fe5404 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/config.ts b/src/config.ts index 41db416..e844e26 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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' }; diff --git a/src/notification/notification.ts b/src/notification/notification.ts index 1eee804..d7eb4c7 100644 --- a/src/notification/notification.ts +++ b/src/notification/notification.ts @@ -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(); } diff --git a/src/notification/pushover.ts b/src/notification/pushover.ts new file mode 100644 index 0000000..f0d6138 --- /dev/null +++ b/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}`); + } + }); +} diff --git a/src/types/pushover-notifications.d.ts b/src/types/pushover-notifications.d.ts new file mode 100644 index 0000000..93f67cf --- /dev/null +++ b/src/types/pushover-notifications.d.ts @@ -0,0 +1 @@ +declare module 'pushover-notifications';