feat(notification): discord integration (#82)

Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
bmalaski
2020-09-20 12:36:05 -04:00
committed by GitHub
parent 5b91065043
commit a3fc07daf0
10 changed files with 75 additions and 5 deletions
+30
View File
@@ -0,0 +1,30 @@
import {Webhook, MessageBuilder} from 'discord-webhook-node';
import {Config} from '../config';
import {Logger} from '../logger';
import {Link} from '../store/model';
const hook = new Webhook(Config.notifications.discord.webHookUrl);
const notifyGroup = Config.notifications.discord.notifyGroup;
export function sendDiscordMessage(cartUrl: string, link: Link) {
(async () => {
try {
const embed = new MessageBuilder();
embed.setTitle('Stock Notification');
embed.addField('URL', cartUrl, true);
embed.addField('Brand', link.brand, true);
embed.addField('Model', link.model, true);
if (notifyGroup !== '') {
embed.addField('Attention', notifyGroup, true);
}
embed.setColor(0x76B900);
embed.setTimestamp();
await hook.send(embed);
Logger.info(`✔ discord message sent: ${cartUrl}`);
} catch (error) {
Logger.error(error);
}
})();
}