1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +02:00
planka/server/api/helpers/utils/send-slack-message.js

56 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-04-08 00:33:29 +02:00
const POST_MESSAGE_API_URL = 'https://slack.com/api/chat.postMessage';
module.exports = {
// TODO: make sync?
2024-04-08 00:33:29 +02:00
inputs: {
markdown: {
type: 'string',
required: true,
},
},
async fn(inputs) {
const headers = {
Authorization: `Bearer ${sails.config.custom.slackBotToken}`,
'Content-Type': 'application/json; charset=utf-8',
};
const body = {
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: inputs.markdown,
},
},
],
channel: sails.config.custom.slackChannelId,
};
let response;
try {
response = await fetch(POST_MESSAGE_API_URL, {
headers,
method: 'POST',
body: JSON.stringify(body),
});
} catch (error) {
sails.log.error(`Error sending to Slack: ${error}`);
2024-04-08 00:33:29 +02:00
return;
}
if (!response.ok) {
sails.log.error(`Error sending to Slack: ${response.error}`);
2024-04-08 00:33:29 +02:00
return;
}
const responseJson = await response.json();
if (!responseJson.ok) {
sails.log.error(`Error sending to Slack: ${responseJson.error}`);
2024-04-08 00:33:29 +02:00
}
},
};