slate/node_common/support.js

36 lines
1.1 KiB
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);
2021-05-06 03:08:14 +03:00
export const sendSlackMessage = ({ username, name, email, twitter, message, stored }) => {
2020-09-17 02:26:15 +03:00
if (Strings.isEmpty(Environment.SUPPORT_SLACK_WEBHOOK_KEY)) {
return false;
}
2021-05-06 03:08:14 +03:00
let userURL;
if (username) {
const userProfileURL = `https://slate.host/${username}`;
userURL = `<${userProfileURL}|${username}>`;
} else {
userURL = "[Not authenticated]";
}
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;
}
};