slate/node_common/support.js

37 lines
1006 B
JavaScript
Raw Normal View History

2020-09-17 02:26:15 +03:00
import * as Environment from "~/node_common/environment";
import * as Strings from "~/common/strings";
import { IncomingWebhook } from "@slack/webhook";
const url = `https://hooks.slack.com/services/${Environment.SUPPORT_SLACK_WEBHOOK_KEY}`;
const webhook = new IncomingWebhook(url);
export const sendSlackMessage = ({
username,
name,
email,
2020-09-17 21:37:29 +03:00
twitter,
2020-09-17 02:26:15 +03:00
message,
stored,
}) => {
if (Strings.isEmpty(Environment.SUPPORT_SLACK_WEBHOOK_KEY)) {
return false;
}
const userProfileURL = `https://slate.host/${username}`;
const userURL = `<${userProfileURL}|${username}>`;
2020-09-17 21:37:29 +03:00
let twitterURL = "";
if (twitter) {
const twitterProfileURL = `https://twitter.com/${twitter.replace("@", "")}`;
twitterURL = `<${twitterProfileURL}|${twitter}>`;
}
2020-09-17 02:26:15 +03:00
try {
webhook.send({
2020-09-17 21:37:29 +03:00
text: `\n*Username:* ${userURL} (${stored} stored)\n*Name:* ${name}\n*Email:* ${email}\n*Twitter:* ${twitterURL}\n*Message:* ${message}`,
2020-09-17 02:26:15 +03:00
});
return true;
} catch (e) {
return false;
}
};