mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 09:57:38 +00:00
9675c5b8d6
Co-authored-by: Jef LeCompte <jeffreylec@gmail.com> Co-authored-by: bmalaski <5288648+bmalaski@users.noreply.github.com>
31 lines
856 B
TypeScript
31 lines
856 B
TypeScript
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.setText(notifyGroup);
|
|
}
|
|
|
|
embed.setColor(0x76B900);
|
|
embed.setTimestamp();
|
|
await hook.send(embed);
|
|
Logger.info(`↗ discord message sent: ${cartUrl}`);
|
|
} catch (error) {
|
|
Logger.error(error);
|
|
}
|
|
})();
|
|
}
|