Merge branch 'GlitchSecure-slack-bot-integration'
commit
bcacfa8fe2
@ -0,0 +1,58 @@
|
|||||||
|
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 {
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
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…
Reference in New Issue