Skip to content

Commit

Permalink
feat(notification): add desktop notifications (#140)
Browse files Browse the repository at this point in the history
Co-authored-by: Jef LeCompte <[email protected]>
  • Loading branch information
nacgarg and jef authored Sep 21, 2020
1 parent 7191e03 commit 722eaf3
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Here is a list of variables that you can use to customize your newly copied `.en

| **Environment variable** | **Description** | **Notes** |
|:---:|---|---|
| `DESKTOP_NOTIFICATIONS` | Display desktop notifications using [node-notifier](https://www.npmjs.com/package/node-notifier); optional | Default: `false` |
| `DISCORD_NOTIFY_GROUP` | Discord group you would like to notify; optional | E.g.: @here |
| `DISCORD_WEB_HOOK` | Discord Web Hook URL |
| `EMAIL_USERNAME` | Gmail address | E.g.: `[email protected]` |
Expand Down
104 changes: 99 additions & 5 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"dependencies": {
"dotenv": "^8.2.0",
"messaging-api-telegram": "^1.0.0",
"node-notifier": "^8.0.0",
"nodemailer": "^6.4.11",
"open": "^7.2.1",
"puppeteer": "^5.3.0",
Expand All @@ -39,6 +40,7 @@
"@types/node": "^14.11.1",
"@types/nodemailer": "^6.4.0",
"@types/puppeteer": "^3.0.2",
"@types/node-notifier": "^8.0.0",
"play-sound": "^1.1.3",
"rimraf": "^3.0.2",
"typescript": "^4.0.2",
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const browser = {
const logLevel = process.env.LOG_LEVEL ?? 'info';

const notifications = {
desktop: process.env.DESKTOP_NOTIFICATIONS === 'true',
discord: {
notifyGroup: process.env.DISCORD_NOTIFY_GROUP ?? '',
webHookUrl: process.env.DISCORD_WEB_HOOK ?? ''
Expand Down
14 changes: 14 additions & 0 deletions src/notification/desktop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import notifier from 'node-notifier';
import {Link} from '../store/model';

export function sendDesktopNotification(cartUrl: string, link: Link) {
(async () => {
const title = link.brand + ' ' + link.model + ' IN STOCK';
const message = cartUrl;

notifier.notify({
title,
message
});
})();
}
6 changes: 6 additions & 0 deletions src/notification/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {sendSlackMessage} from './slack';
import {sendPushoverNotification} from './pushover';
import {sendTelegramMessage} from './telegram';
import {sendDiscordMessage} from './discord';
import {sendDesktopNotification} from './desktop';

import {Link} from '../store/model';

const notifications = Config.notifications;
Expand Down Expand Up @@ -41,4 +43,8 @@ export function sendNotification(cartUrl: string, link: Link) {
if (notifications.playSound) {
playSound();
}

if (notifications.desktop) {
sendDesktopNotification(cartUrl, link);
}
}

0 comments on commit 722eaf3

Please sign in to comment.