mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 13:27:38 +00:00
feat: slack integration (#34)
Co-authored-by: Evan Gentis <evan.gentis@gmail.com>
This commit is contained in:
@@ -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