-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
discord.ts
30 lines (26 loc) · 883 Bytes
/
discord.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);
}
})();
}