mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 04:07:36 +00:00
feat: slack integration (#34)
Co-authored-by: Evan Gentis <evan.gentis@gmail.com>
This commit is contained in:
+10
-1
@@ -20,10 +20,19 @@ const page = {
|
||||
|
||||
const stores = process.env.STORES ?? 'nvidia';
|
||||
|
||||
const notificationMethods = process.env.NOTIFICATION_METHODS ?? 'email';
|
||||
|
||||
const slack = {
|
||||
channel: process.env.SLACK_CHANNEL,
|
||||
token: process.env.SLACK_TOKEN
|
||||
};
|
||||
|
||||
export const Config = {
|
||||
email,
|
||||
notifications,
|
||||
page,
|
||||
rateLimitTimeout: 5000,
|
||||
stores
|
||||
stores,
|
||||
slack,
|
||||
notificationMethods
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
})();
|
||||
}
|
||||
Reference in New Issue
Block a user