mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 05:09:43 +02:00
Rename custom.js -> slack.js
This commit is contained in:
parent
ddbf2c528d
commit
719ba9fc9c
5 changed files with 4 additions and 4 deletions
70
server/api/services/slack.js
Normal file
70
server/api/services/slack.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
const axios = require('axios');
|
||||
const slackPostUrl = 'https://slack.com/api/chat.postMessage';
|
||||
const channelId = process.env.SLACK_CHANNEL_ID;
|
||||
const slackAPIToken = process.env.SLACK_BOT_TOKEN;
|
||||
const plankaProdUrl = process.env.BASE_URL;
|
||||
|
||||
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
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue