lbry.tech/app/helpers/slack.js
ポール ウェッブ 4ba5ec49dd 2.0.1
2018-11-30 14:49:51 -06:00

41 lines
842 B
JavaScript

"use strict";
// I M P O R T
import { IncomingWebhook } from "@slack/client";
// U T I L S
require("dotenv").config();
const environmentMessage = process.env.NODE_ENV === "development" ?
"\n_— in DEVELOPMENT_" :
"\n_— in PRODUCTION_";
const slackUrl = process.env.SLACK_WEBHOOK_URL || "";
const slackWebhook = new IncomingWebhook(slackUrl);
// P R O G R A M
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
});
};