From 96d5463c4583f9568552d9a0652101bafe416755 Mon Sep 17 00:00:00 2001 From: Phil Skentelbery Date: Tue, 14 Nov 2017 20:05:20 -0600 Subject: [PATCH] Added push notification support to app --- index.js | 22 ++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8a0c666..74dc61e 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const fetch = require('node-fetch'); const commandLineArgs = require('command-line-args'); const getUsage = require('command-line-usage'); +const push = require( 'pushover-notifications' ); // Get partNumbers from json file. const partNumbers = require('./partNumbers.json'); @@ -101,6 +102,13 @@ const endpoint = `https://www.apple.com/shop/retail/pickup-message?pl=true&cppar // Keep track of the last request time. let lastRequestTimestamp = null; +// Construct push endpoint + +const p = new push ( { + user: process.env.PUSHOVER_USER, + token: process.env.PUSHOVER_TOKEN +}); + /** * Update program status display * @@ -175,6 +183,15 @@ function displayStoresAvailable(storesAvailable) { console.log(storesAvailableStr); } +// Build the message +const msg = { + message: 'iPhone X stock available nearby!', + title: 'Important News!', + priority: 2, + retry: 60, + expire: 1800 +}; + /** * The main program loop * @@ -193,6 +210,11 @@ async function requestLoop() { } else { // The device is available. Show that information to the user and exit the program. displayStoresAvailable(storesAvailable); + p.send (msg, function (err, result){ + if (err) { + throw err; + } + }) process.exit(); } } diff --git a/package.json b/package.json index e38c285..ff7b489 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "dependencies": { "command-line-args": "^4.0.7", "command-line-usage": "^4.0.1", - "node-fetch": "^1.7.3" + "node-fetch": "^1.7.3", + "pushover-notifications": "^0.2.4" }, "devDependencies": { "eslint": "^4.10.0",