2020-09-11 06:28:23 +03:00
|
|
|
import * as Environment from "~/node_common/environment";
|
|
|
|
import * as Strings from "~/common/strings";
|
2021-06-11 22:25:58 +03:00
|
|
|
import * as Logging from "~/common/logging";
|
2020-09-11 06:28:23 +03:00
|
|
|
|
|
|
|
import { IncomingWebhook } from "@slack/webhook";
|
|
|
|
|
2020-09-22 03:36:45 +03:00
|
|
|
// NOTE(jim): #fil-slate-social
|
2020-11-16 11:07:11 +03:00
|
|
|
const url = `https://hooks.slack.com/services/${Environment.SOCIAL_SLACK_WEBHOOK_KEY}`;
|
2020-09-11 06:28:23 +03:00
|
|
|
const webhook = new IncomingWebhook(url);
|
|
|
|
|
2020-09-22 03:36:45 +03:00
|
|
|
// NOTE(jim): #fil-slate-textile-api
|
2020-11-16 11:07:11 +03:00
|
|
|
const textileURL = `https://hooks.slack.com/services/${Environment.TEXTILE_SLACK_WEBHOOK_KEY}`;
|
2020-09-22 03:36:45 +03:00
|
|
|
const textileWebhook = new IncomingWebhook(textileURL);
|
|
|
|
|
2020-09-11 06:28:23 +03:00
|
|
|
export const sendSlackMessage = (message) => {
|
|
|
|
if (Strings.isEmpty(Environment.SOCIAL_SLACK_WEBHOOK_KEY)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
webhook.send({ text: message });
|
|
|
|
} catch (e) {
|
2021-06-11 22:25:58 +03:00
|
|
|
Logging.error("SLACK_MESSAGE_FAILURE", message);
|
2020-09-11 06:28:23 +03:00
|
|
|
}
|
|
|
|
};
|
2020-09-22 03:36:45 +03:00
|
|
|
|
|
|
|
export const sendTextileSlackMessage = ({
|
|
|
|
user = { username: "UNDEFINED" },
|
|
|
|
message,
|
|
|
|
functionName,
|
|
|
|
code,
|
|
|
|
file,
|
|
|
|
}) => {
|
|
|
|
if (Strings.isEmpty(Environment.TEXTILE_SLACK_WEBHOOK_KEY)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const userProfileURL = `https://slate.host/${user.username}`;
|
|
|
|
const userURL = `<${userProfileURL}|${user.username}>`;
|
|
|
|
const source = `${Environment.SOURCE}`;
|
|
|
|
const fileURL = `https://github.com/filecoin-project/slate/blob/main/${file}`;
|
|
|
|
const slackFileURL = `<${fileURL}|${file}>`;
|
|
|
|
|
|
|
|
try {
|
|
|
|
textileWebhook.send({
|
2020-09-22 04:06:26 +03:00
|
|
|
text: `*Source code —* ${slackFileURL} \n*Source client —* ${source} \n*Callsite —* \`${functionName}\`\n*User —* ${userURL}\n\n> ${message}\n\n*Textile error code —* ${code}`,
|
2020-09-22 03:36:45 +03:00
|
|
|
});
|
|
|
|
} catch (e) {
|
2021-06-11 22:25:58 +03:00
|
|
|
Logging.error("SLACK_MESSAGE_FAILURE", message);
|
2020-09-22 03:36:45 +03:00
|
|
|
}
|
|
|
|
};
|