mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 14:37:41 +00:00
chore: move notification test, other refactoring (#111)
This commit is contained in:
@@ -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