mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 01:47:39 +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_PASSWORD="secretpassword"
|
||||
HEADLESS="true"
|
||||
LOG_LEVEL="info"
|
||||
NOTIFICATION_TEST="false"
|
||||
OPEN_BROWSER="true"
|
||||
PAGE_TIMEOUT="30000"
|
||||
PHONE_NUMBER="1234567890"
|
||||
@@ -18,5 +19,3 @@ STORES="bestbuy,bandh,nvidia"
|
||||
SCREENSHOT="true"
|
||||
TELEGRAM_ACCESS_TOKEN=""
|
||||
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:
|
||||
|
||||
|
||||
| **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_WEB_HOOK` | Discord Web Hook URL |
|
||||
| `EMAIL_USERNAME` | Gmail address | E.g.: `jensen.robbed.us@gmail.com` |
|
||||
| `EMAIL_PASSWORD` | Gmail password | See below if you have MFA |
|
||||
| `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` |
|
||||
| `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` |
|
||||
| `PAGE_TIMEOUT` | Navigation Timeout in milliseconds | `0` for infinite, default: `30000` |
|
||||
| `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: You can test your notification configuration by running `npm run test:notification`.
|
||||
|
||||
#### Supported stores
|
||||
|
||||
| **Stores** | **Environment variable** |
|
||||
|
||||
+2
-1
@@ -7,7 +7,8 @@
|
||||
"build": "rimraf ./build && tsc",
|
||||
"lint": "xo",
|
||||
"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": {
|
||||
"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 notifications = {
|
||||
discord: {
|
||||
notifyGroup: process.env.DISCORD_NOTIFY_GROUP ?? '',
|
||||
webHookUrl: process.env.DISCORD_WEB_HOOK ?? ''
|
||||
},
|
||||
email: {
|
||||
username: process.env.EMAIL_USERNAME ?? '',
|
||||
password: process.env.EMAIL_PASSWORD ?? ''
|
||||
@@ -42,10 +46,6 @@ const notifications = {
|
||||
accessToken: process.env.TELEGRAM_ACCESS_TOKEN ?? '',
|
||||
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'
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import adblockerPlugin from 'puppeteer-extra-plugin-adblocker';
|
||||
import {Config} from './config';
|
||||
import {Store, Stores} from './store/model';
|
||||
import {Logger} from './logger';
|
||||
import {sendNotification} from './notification';
|
||||
import {lookup} from './store';
|
||||
import async from 'async';
|
||||
|
||||
@@ -51,13 +50,6 @@ async function main() {
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -22,7 +22,7 @@ export function sendDiscordMessage(cartUrl: string, link: Link) {
|
||||
embed.setColor(0x76B900);
|
||||
embed.setTimestamp();
|
||||
await hook.send(embed);
|
||||
Logger.info(`✔ discord message sent: ${cartUrl}`);
|
||||
Logger.info(`↗ discord message sent: ${cartUrl}`);
|
||||
} catch (error) {
|
||||
Logger.error(error);
|
||||
}
|
||||
|
||||
@@ -20,15 +20,15 @@ const mailOptions: Mail.Options = {
|
||||
subject
|
||||
};
|
||||
|
||||
export function sendEmail(text: string) {
|
||||
mailOptions.text = text;
|
||||
export function sendEmail(cartUrl: string) {
|
||||
mailOptions.text = cartUrl;
|
||||
|
||||
transporter.sendMail(mailOptions, (error, info) => {
|
||||
if (error) {
|
||||
Logger.error(error);
|
||||
} else {
|
||||
// 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
|
||||
});
|
||||
|
||||
export function sendPushoverNotification(text: string) {
|
||||
export function sendPushoverNotification(cartUrl: string) {
|
||||
const message = {
|
||||
message: text
|
||||
message: cartUrl
|
||||
};
|
||||
|
||||
push.send(message, (err: Error, result: string) => {
|
||||
if (err) {
|
||||
Logger.error(err);
|
||||
} 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 web = new WebClient(token);
|
||||
|
||||
export function sendSlackMessage(text: string) {
|
||||
export function sendSlackMessage(cartUrl: string) {
|
||||
(async () => {
|
||||
try {
|
||||
const result = await web.chat.postMessage({text, channel});
|
||||
const result = await web.chat.postMessage({text: cartUrl, channel});
|
||||
if (!result.ok) {
|
||||
Logger.error(result.error);
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.info(`✔ slack message sent to '${channel}': ${text}`);
|
||||
Logger.info(`↗ slack message sent to '${channel}': ${cartUrl}`);
|
||||
} catch (error) {
|
||||
Logger.error(error);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export function sendSMS(text: string) {
|
||||
Logger.error(error);
|
||||
} else {
|
||||
// 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) => {
|
||||
Logger.info('✔ playing sound');
|
||||
Logger.info('↗ playing sound');
|
||||
|
||||
if (err) {
|
||||
Logger.error(`error playing sound: ${err}`);
|
||||
|
||||
@@ -12,7 +12,7 @@ export function sendTelegramMessage(text: string) {
|
||||
(async () => {
|
||||
try {
|
||||
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) {
|
||||
Logger.error(error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user