feat: slack integration (#34)

Co-authored-by: Evan Gentis <evan.gentis@gmail.com>
This commit is contained in:
Esg450
2020-09-18 17:55:26 -04:00
committed by GitHub
parent c2a210cc81
commit c0a881a16e
6 changed files with 216 additions and 2 deletions
+6 -1
View File
@@ -1,8 +1,13 @@
import {Config} from '../config';
import sendEmail from './email';
import sendSlaskMessage from './slack';
export default function sendNotification(cartUrl: string) {
if (Config.notifications.email) {
if (Config.notificationMethods.toLocaleLowerCase().includes('email')) {
sendEmail(cartUrl);
}
if (Config.notificationMethods.toLocaleLowerCase().includes('slack')) {
sendSlaskMessage(cartUrl);
}
}
+23
View File
@@ -0,0 +1,23 @@
import {WebClient} from '@slack/web-api';
import {Config} from '../config';
import {Logger} from '../logger';
const channel = Config.slack.channel ?? '';
const token = Config.slack.token ?? '';
const web = new WebClient(token);
export default function sendSlackMessage(text: string) {
(async () => {
try {
const result = await web.chat.postMessage({text, channel});
if (!result.ok) {
Logger.error(result.error);
return;
}
Logger.info(`✔ slack message sent to '${channel}': ${text}`);
} catch (error) {
Logger.error(error);
}
})();
}