-
Notifications
You must be signed in to change notification settings - Fork 0
/
implementation.js
40 lines (37 loc) · 1.07 KB
/
implementation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const GENERAL_ERROR_MESSAGE = "I cannot do that..."
async function send_message_to_slack_channel_with_webhook(params, userSettings) {
const { message } = params;
const { slackWebhookUrl } = userSettings;
if (!slackWebhookUrl) {
return GENERAL_ERROR_MESSAGE;
}
const payload = {
blocks: [
{
type: 'section',
text: {
type: 'plain_text',
text: message,
emoji: true,
},
},
],
};
try {
const response = await fetch(slackWebhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: JSON.stringify(payload),
});
if (response.ok) {
return "Message has been sent to Slack.";
} else {
return GENERAL_ERROR_MESSAGE;
}
} catch (error) {
console.error("Error sending message to Slack:", error);
return GENERAL_ERROR_MESSAGE;
}
}