mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 05:17:35 +00:00
chore: move notification test, other refactoring (#111)
This commit is contained in:
+2
-3
@@ -1,8 +1,9 @@
|
|||||||
|
DISCORD_NOTIFY_GROUP="@here"
|
||||||
|
DISCORD_WEB_HOOK="https://discordapp.com/api/webhooks/23123123123/5dfsdfh3h2j5hdfhsdfsdhj55jf"
|
||||||
EMAIL_USERNAME="youremail@gmail.com"
|
EMAIL_USERNAME="youremail@gmail.com"
|
||||||
EMAIL_PASSWORD="secretpassword"
|
EMAIL_PASSWORD="secretpassword"
|
||||||
HEADLESS="true"
|
HEADLESS="true"
|
||||||
LOG_LEVEL="info"
|
LOG_LEVEL="info"
|
||||||
NOTIFICATION_TEST="false"
|
|
||||||
OPEN_BROWSER="true"
|
OPEN_BROWSER="true"
|
||||||
PAGE_TIMEOUT="30000"
|
PAGE_TIMEOUT="30000"
|
||||||
PHONE_NUMBER="1234567890"
|
PHONE_NUMBER="1234567890"
|
||||||
@@ -18,5 +19,3 @@ STORES="bestbuy,bandh,nvidia"
|
|||||||
SCREENSHOT="true"
|
SCREENSHOT="true"
|
||||||
TELEGRAM_ACCESS_TOKEN=""
|
TELEGRAM_ACCESS_TOKEN=""
|
||||||
TELEGRAM_CHAT_ID="1234"
|
TELEGRAM_CHAT_ID="1234"
|
||||||
DISCORD_WEB_HOOK="https://discordapp.com/api/webhooks/23123123123/5dfsdfh3h2j5hdfhsdfsdhj55jf"
|
|
||||||
DISCORD_NOTIFY_GROUP="@here"
|
|
||||||
|
|||||||
@@ -60,16 +60,14 @@ To customize `nvidia-snatcher`, make a copy of `.env-example` as `.env` and make
|
|||||||
|
|
||||||
Here is a list of variables that you can use to customize your newly copied `.env` file:
|
Here is a list of variables that you can use to customize your newly copied `.env` file:
|
||||||
|
|
||||||
|
|
||||||
| **Environment variable** | **Description** | **Notes** |
|
| **Environment variable** | **Description** | **Notes** |
|
||||||
|:---:|---|---|
|
|:---:|---|---|
|
||||||
| `DISCORD_WEB_HOOK` | Discord Web Hook URL |
|
|
||||||
| `DISCORD_NOTIFY_GROUP` | Discord group you would like to notify; optional | E.g.: @here |
|
| `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.: `jensen.robbed.us@gmail.com` |
|
| `EMAIL_USERNAME` | Gmail address | E.g.: `jensen.robbed.us@gmail.com` |
|
||||||
| `EMAIL_PASSWORD` | Gmail password | See below if you have MFA |
|
| `EMAIL_PASSWORD` | Gmail password | See below if you have MFA |
|
||||||
| `HEADLESS` | Puppeteer to run headless or not | Debugging related, default: `true` |
|
| `HEADLESS` | Puppeteer to run headless or not | Debugging related, default: `true` |
|
||||||
| `LOG_LEVEL` | [Logging levels](https://github.com/winstonjs/winston#logging-levels) | Debugging related, default: `info` |
|
| `LOG_LEVEL` | [Logging levels](https://github.com/winstonjs/winston#logging-levels) | Debugging related, default: `info` |
|
||||||
| `NOTIFICATION_TEST` | Test all the notifications configured | Default: `false` |
|
|
||||||
| `OPEN_BROWSER` | Toggle for whether or not the browser should open when item is found | Default: `true` |
|
| `OPEN_BROWSER` | Toggle for whether or not the browser should open when item is found | Default: `true` |
|
||||||
| `PAGE_TIMEOUT` | Navigation Timeout in milliseconds | `0` for infinite, default: `30000` |
|
| `PAGE_TIMEOUT` | Navigation Timeout in milliseconds | `0` for infinite, default: `30000` |
|
||||||
| `PHONE_NUMBER` | 10 digit phone number | E.g.: `1234567890`, email configuration required |
|
| `PHONE_NUMBER` | 10 digit phone number | E.g.: `1234567890`, email configuration required |
|
||||||
@@ -88,6 +86,8 @@ Here is a list of variables that you can use to customize your newly copied `.en
|
|||||||
|
|
||||||
> :point_right: If you have multi-factor authentication (MFA), you will need to create an [app password](https://myaccount.google.com/apppasswords) and use this instead of your Gmail password.
|
> :point_right: If you have multi-factor authentication (MFA), you will need to create an [app password](https://myaccount.google.com/apppasswords) and use this instead of your Gmail password.
|
||||||
|
|
||||||
|
> :point_right: You can test your notification configuration by running `npm run test:notification`.
|
||||||
|
|
||||||
#### Supported stores
|
#### Supported stores
|
||||||
|
|
||||||
| **Stores** | **Environment variable** |
|
| **Stores** | **Environment variable** |
|
||||||
|
|||||||
+2
-1
@@ -7,7 +7,8 @@
|
|||||||
"build": "rimraf ./build && tsc",
|
"build": "rimraf ./build && tsc",
|
||||||
"lint": "xo",
|
"lint": "xo",
|
||||||
"lint:fix": "xo --fix",
|
"lint:fix": "xo --fix",
|
||||||
"start": "npm run build && node build/index.js"
|
"start": "npm run build && node build/index.js",
|
||||||
|
"test:notification": "npm run build && node build/__test__/*.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import {Link} from '../store/model';
|
||||||
|
import {sendNotification} from '../notification';
|
||||||
|
|
||||||
|
const link: Link = {
|
||||||
|
brand: 'brand',
|
||||||
|
cartUrl: 'http://example.com/',
|
||||||
|
captchaLabels: ['captcha'],
|
||||||
|
model: 'model',
|
||||||
|
oosLabels: ['out of stock'],
|
||||||
|
url: 'http://example.com/'
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send test email.
|
||||||
|
*/
|
||||||
|
sendNotification(link.cartUrl ?? link.url, link);
|
||||||
+4
-4
@@ -12,6 +12,10 @@ const browser = {
|
|||||||
const logLevel = process.env.LOG_LEVEL ?? 'info';
|
const logLevel = process.env.LOG_LEVEL ?? 'info';
|
||||||
|
|
||||||
const notifications = {
|
const notifications = {
|
||||||
|
discord: {
|
||||||
|
notifyGroup: process.env.DISCORD_NOTIFY_GROUP ?? '',
|
||||||
|
webHookUrl: process.env.DISCORD_WEB_HOOK ?? ''
|
||||||
|
},
|
||||||
email: {
|
email: {
|
||||||
username: process.env.EMAIL_USERNAME ?? '',
|
username: process.env.EMAIL_USERNAME ?? '',
|
||||||
password: process.env.EMAIL_PASSWORD ?? ''
|
password: process.env.EMAIL_PASSWORD ?? ''
|
||||||
@@ -42,10 +46,6 @@ const notifications = {
|
|||||||
accessToken: process.env.TELEGRAM_ACCESS_TOKEN ?? '',
|
accessToken: process.env.TELEGRAM_ACCESS_TOKEN ?? '',
|
||||||
chatId: process.env.TELEGRAM_CHAT_ID ?? ''
|
chatId: process.env.TELEGRAM_CHAT_ID ?? ''
|
||||||
},
|
},
|
||||||
discord: {
|
|
||||||
webHookUrl: process.env.DISCORD_WEB_HOOK ?? '',
|
|
||||||
notifyGroup: process.env.DISCORD_NOTIFY_GROUP ?? ''
|
|
||||||
},
|
|
||||||
test: process.env.NOTIFICATION_TEST === 'true'
|
test: process.env.NOTIFICATION_TEST === 'true'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import adblockerPlugin from 'puppeteer-extra-plugin-adblocker';
|
|||||||
import {Config} from './config';
|
import {Config} from './config';
|
||||||
import {Store, Stores} from './store/model';
|
import {Store, Stores} from './store/model';
|
||||||
import {Logger} from './logger';
|
import {Logger} from './logger';
|
||||||
import {sendNotification} from './notification';
|
|
||||||
import {lookup} from './store';
|
import {lookup} from './store';
|
||||||
import async from 'async';
|
import async from 'async';
|
||||||
|
|
||||||
@@ -51,13 +50,6 @@ async function main() {
|
|||||||
await browser.close();
|
await browser.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Send test email.
|
|
||||||
*/
|
|
||||||
if (Config.notifications.test) {
|
|
||||||
sendNotification('http://test.com/', {brand: 'THE BEST BRAND', model: 'VENTUS', oosLabels: [], url: '', cartUrl: ''});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will continually run until user interferes.
|
* Will continually run until user interferes.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export function sendDiscordMessage(cartUrl: string, link: Link) {
|
|||||||
embed.setColor(0x76B900);
|
embed.setColor(0x76B900);
|
||||||
embed.setTimestamp();
|
embed.setTimestamp();
|
||||||
await hook.send(embed);
|
await hook.send(embed);
|
||||||
Logger.info(`✔ discord message sent: ${cartUrl}`);
|
Logger.info(`↗ discord message sent: ${cartUrl}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(error);
|
Logger.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,15 +20,15 @@ const mailOptions: Mail.Options = {
|
|||||||
subject
|
subject
|
||||||
};
|
};
|
||||||
|
|
||||||
export function sendEmail(text: string) {
|
export function sendEmail(cartUrl: string) {
|
||||||
mailOptions.text = text;
|
mailOptions.text = cartUrl;
|
||||||
|
|
||||||
transporter.sendMail(mailOptions, (error, info) => {
|
transporter.sendMail(mailOptions, (error, info) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
Logger.error(error);
|
Logger.error(error);
|
||||||
} else {
|
} else {
|
||||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||||
Logger.info(`✔ email sent: ${info.response}`);
|
Logger.info(`↗ email sent: ${info.response}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,16 +8,16 @@ const push = new Push({
|
|||||||
token: pushover.token
|
token: pushover.token
|
||||||
});
|
});
|
||||||
|
|
||||||
export function sendPushoverNotification(text: string) {
|
export function sendPushoverNotification(cartUrl: string) {
|
||||||
const message = {
|
const message = {
|
||||||
message: text
|
message: cartUrl
|
||||||
};
|
};
|
||||||
|
|
||||||
push.send(message, (err: Error, result: string) => {
|
push.send(message, (err: Error, result: string) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
Logger.error(err);
|
Logger.error(err);
|
||||||
} else {
|
} else {
|
||||||
Logger.info(`✔ Pushover notification sent: ${result}`);
|
Logger.info(`↗ pushover notification sent: ${result}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ const channel = Config.notifications.slack.channel;
|
|||||||
const token = Config.notifications.slack.token;
|
const token = Config.notifications.slack.token;
|
||||||
const web = new WebClient(token);
|
const web = new WebClient(token);
|
||||||
|
|
||||||
export function sendSlackMessage(text: string) {
|
export function sendSlackMessage(cartUrl: string) {
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const result = await web.chat.postMessage({text, channel});
|
const result = await web.chat.postMessage({text: cartUrl, channel});
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
Logger.error(result.error);
|
Logger.error(result.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.info(`✔ slack message sent to '${channel}': ${text}`);
|
Logger.info(`↗ slack message sent to '${channel}': ${cartUrl}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(error);
|
Logger.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export function sendSMS(text: string) {
|
|||||||
Logger.error(error);
|
Logger.error(error);
|
||||||
} else {
|
} else {
|
||||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||||
Logger.info(`✔ sms sent: ${info.response}`);
|
Logger.info(`↗ sms sent: ${info.response}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export function playSound() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
player.play(notificationSound, (err: string) => {
|
player.play(notificationSound, (err: string) => {
|
||||||
Logger.info('✔ playing sound');
|
Logger.info('↗ playing sound');
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
Logger.error(`error playing sound: ${err}`);
|
Logger.error(`error playing sound: ${err}`);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export function sendTelegramMessage(text: string) {
|
|||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
await client.sendMessage(telegram.chatId, text);
|
await client.sendMessage(telegram.chatId, text);
|
||||||
Logger.info(`✔ telegram message sent to '${telegram.chatId}': ${text}`);
|
Logger.info(`↗ telegram message sent to '${telegram.chatId}': ${text}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(error);
|
Logger.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user