Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notification): discord integration (#82)
Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
- Loading branch information
Showing
10 changed files
with
75 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
})(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
interface Link { | ||
export interface Link { | ||
cartUrl?: string; | ||
brand: string; | ||
model: string; | ||
|