mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 05:09:43 +02:00
feat: Slack bot notifications (#676)
This commit is contained in:
parent
90435da0ab
commit
2eff8b80f1
9 changed files with 128 additions and 26 deletions
|
@ -25,7 +25,7 @@ module.exports = {
|
|||
|
||||
sails.log.info('Email sent: %s', info.messageId);
|
||||
} catch (error) {
|
||||
sails.log.error(error);
|
||||
sails.log.error(error); // TODO: provide description text?
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
53
server/api/helpers/utils/send-slack-message.js
Normal file
53
server/api/helpers/utils/send-slack-message.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
const POST_MESSAGE_API_URL = 'https://slack.com/api/chat.postMessage';
|
||||
|
||||
module.exports = {
|
||||
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); // TODO: provide description text?
|
||||
return;
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
sails.log.error('Error sending to Slack: %s', response.error);
|
||||
return;
|
||||
}
|
||||
|
||||
const responseJson = await response.json();
|
||||
|
||||
if (!responseJson.ok) {
|
||||
sails.log.error('Error sending to Slack: %s', responseJson.error);
|
||||
}
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue