mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 16:57:34 +00:00
feat(notification): add pushbullet, add url with notifications (#226)
Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
@@ -37,6 +37,7 @@ const notifications = {
|
||||
number: process.env.PHONE_NUMBER ?? ''
|
||||
},
|
||||
playSound: process.env.PLAY_SOUND ?? '',
|
||||
pushBulletApiKey: process.env.PUSHBULLET ?? '',
|
||||
pushover: {
|
||||
token: process.env.PUSHOVER_TOKEN ?? '',
|
||||
username: process.env.PUSHOVER_USER ?? ''
|
||||
|
||||
@@ -4,6 +4,7 @@ import {playSound} from './sound';
|
||||
import {sendDesktopNotification} from './desktop';
|
||||
import {sendDiscordMessage} from './discord';
|
||||
import {sendEmail} from './email';
|
||||
import {sendPushBulletNotification} from './pushbullet';
|
||||
import {sendPushoverNotification} from './pushover';
|
||||
import {sendSMS} from './sms';
|
||||
import {sendSlackMessage} from './slack';
|
||||
@@ -36,6 +37,10 @@ export function sendNotification(cartUrl: string, link: Link) {
|
||||
}
|
||||
}
|
||||
|
||||
if (notifications.pushBulletApiKey) {
|
||||
sendPushBulletNotification(cartUrl, link);
|
||||
}
|
||||
|
||||
if (notifications.pushover.token && notifications.pushover.username) {
|
||||
sendPushoverNotification(cartUrl);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import {Config} from '../config';
|
||||
import {Link} from '../store/model';
|
||||
import {Logger} from '../logger';
|
||||
import PushBullet from 'pushbullet';
|
||||
|
||||
const pushBulletApiKey = Config.notifications.pushBulletApiKey;
|
||||
|
||||
export function sendPushBulletNotification(cartUrl: string, link: Link) {
|
||||
const pusher = new PushBullet(pushBulletApiKey);
|
||||
const title = `🚨 ${link.brand} ${link.model} ${link.series} 👀`;
|
||||
|
||||
pusher.note({}, title, cartUrl, (err: Error, result: string) => {
|
||||
if (err) {
|
||||
Logger.error(err);
|
||||
} else {
|
||||
Logger.info(`↗ pushbullet notification sent: ${result}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
+2
-2
@@ -88,13 +88,13 @@ async function lookupCard(browser: Browser, store: Store, page: Page, link: Link
|
||||
await page.screenshot({path: link.screenshot});
|
||||
}
|
||||
|
||||
const givenUrl = link.cartUrl ? link.cartUrl : link.url;
|
||||
let givenUrl = link.cartUrl ? link.cartUrl : link.url;
|
||||
|
||||
if (Config.browser.open) {
|
||||
if (link.openCartAction === undefined) {
|
||||
await open(givenUrl);
|
||||
} else {
|
||||
link.openCartAction(browser);
|
||||
givenUrl = await link.openCartAction(browser);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,8 +67,11 @@ export function generateSetupAction() {
|
||||
const accessToken = data.access_token;
|
||||
|
||||
Logger.info('[nvidia] you can log into your cart now...');
|
||||
Logger.info(checkoutUrl(drLocale, accessToken));
|
||||
await open(checkoutUrl(drLocale, accessToken));
|
||||
const cartUrl = checkoutUrl(drLocale, accessToken);
|
||||
Logger.info(cartUrl);
|
||||
if (Config.browser.open) {
|
||||
await open(cartUrl);
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.debug(error);
|
||||
Logger.error('✖ [nvidia] cannot generate cart/session token, continuing without, auto-"add to cart" may not work...');
|
||||
@@ -83,6 +86,7 @@ export function generateOpenCartAction(id: number, nvidiaLocale: string, drLocal
|
||||
const page = await browser.newPage();
|
||||
Logger.info(`🚀🚀🚀 [nvidia] ${cardName}, starting auto add to cart... 🚀🚀🚀`);
|
||||
let response: Response | null;
|
||||
let cartUrl: string;
|
||||
try {
|
||||
Logger.info(`🚀🚀🚀 [nvidia] ${cardName}, getting access token... 🚀🚀🚀`);
|
||||
response = await page.goto(nvidiaSessionUrl(nvidiaLocale), {waitUntil: 'networkidle0'});
|
||||
@@ -97,15 +101,19 @@ export function generateOpenCartAction(id: number, nvidiaLocale: string, drLocal
|
||||
response = await page.goto(addToCartUrl(id, drLocale, accessToken), {waitUntil: 'networkidle0'});
|
||||
|
||||
Logger.info(`🚀🚀🚀 [nvidia] ${cardName}, opening checkout page... 🚀🚀🚀`);
|
||||
Logger.info(checkoutUrl(drLocale, accessToken));
|
||||
await open(checkoutUrl(drLocale, accessToken));
|
||||
cartUrl = checkoutUrl(drLocale, accessToken);
|
||||
Logger.info(cartUrl);
|
||||
await open(cartUrl);
|
||||
} catch (error) {
|
||||
Logger.debug(error);
|
||||
Logger.error(`✖ [nvidia] ${cardName} could not automatically add to cart, opening page`);
|
||||
await open(fallbackCartUrl(nvidiaLocale));
|
||||
cartUrl = fallbackCartUrl(nvidiaLocale);
|
||||
await open(cartUrl);
|
||||
}
|
||||
|
||||
await page.close();
|
||||
|
||||
return cartUrl;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ export interface Link {
|
||||
model: string;
|
||||
url: string;
|
||||
cartUrl?: string;
|
||||
openCartAction?: (browser: Browser) => void;
|
||||
openCartAction?: (browser: Browser) => Promise<string>;
|
||||
screenshot?: string;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
declare module 'pushbullet';
|
||||
Reference in New Issue
Block a user