1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00

added new custom service with slack integration helper functions; added axios package; added notifications for card create, delete, and update (move); added notifications for comment create

This commit is contained in:
Brad Bahls 2023-12-23 08:52:07 -07:00
parent fbd1b28312
commit b8ce112dc3
6 changed files with 110 additions and 0 deletions

View file

@ -0,0 +1,73 @@
const axios = require('axios');
const slackPostUrl = 'https://slack.com/api/chat.postMessage';
const channelId = 'C06B6F4R9RT';
const plankaProdUrl = 'https://kanban.glitchsecure.com';
const plankaTestUrl = 'http://localhost:3000';
const plankaTestWebhookUrl = 'https://hooks.slack.com/services/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';
const slackAPIToken = process.env.SLACK_BOT_TOKEN;
async function sendSlackMessage(messageText) {
if (!slackAPIToken) {
throw new Error('No Slack BOT token found');
}
console.log('Sending to Slack');
const postData = {
blocks: [ {
type: 'section',
text: {
type: 'mrkdwn',
text: messageText,
},
}]
};
try {
// Prod path
const config = {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${slackAPIToken}`,
},
};
axios.post(slackPostUrl, { ...postData, channel: channelId }, config)
.then(response => {
console.log('Slack response:', response.data);
})
.catch(error => {
console.error('Error sending to Slack:', error.message);
});
// Testing in dev environment (Brad)
/*
const response = await axios.post(plankaTestWebhookUrl, postData, {
headers: {
'Content-Type': 'application/json'
}
});
*/
console.log('Slack response:', response.data);
return response.data;
} catch (error) {
console.error('Error sending to Slack:', error.message);
throw error;
}
}
function buildCardUrl(card) {
const url = plankaProdUrl + '/cards/' + card.id;
const cardUrl = '<' + url + '|' + card.name + '>';
console.log(cardUrl);
return cardUrl;
}
module.exports = {
sendSlackMessage,
buildCardUrl
};