lbry.tech/app/helpers/slack.js

42 lines
836 B
JavaScript
Raw Normal View History

2018-11-30 21:46:22 +01:00
"use strict";
2018-07-12 17:21:42 +02:00
2018-11-30 21:46:22 +01:00
// I M P O R T
import { IncomingWebhook } from "@slack/client";
// U T I L S
2018-07-12 17:21:42 +02:00
2018-11-30 21:46:22 +01:00
require("dotenv").config();
2018-07-12 17:21:42 +02:00
2018-11-30 21:46:22 +01:00
const environmentMessage = process.env.NODE_ENV === "development" ?
"\n_— in DEVELOPMENT_" :
"\n_— in PRODUCTION_";
2018-07-12 17:21:42 +02:00
2018-11-30 21:46:22 +01:00
const slackUrl = process.env.SLACK_WEBHOOK_URL || "";
const slackWebhook = new IncomingWebhook(slackUrl);
2018-07-12 17:21:42 +02:00
2018-11-30 21:46:22 +01:00
// P R O G R A M
2018-07-12 17:21:42 +02:00
2018-11-30 21:46:22 +01:00
export default ({ message, pretext, title }) => {
if (!slackUrl) return;
pretext = pretext + environmentMessage;
slackWebhook.send({
attachments: [{
mrkdwn_in: [
"text",
"pretext"
],
pretext: pretext || "",
text: message || "",
title: title || ""
}]
}, (error, response) => { // eslint-disable-line no-unused-vars
if (error) console.log(error); // eslint-disable-line no-console
2018-07-12 17:21:42 +02:00
});
};