2
0
Fork 0
mirror of https://github.com/elementor/hello-theme.git synced 2026-03-03 12:56:14 +08:00
hello-theme/.github/scripts/send-slack-message.js
Hein van Vlastuin 2a43d8c792
Some checks failed
Build / Build theme (push) Has been cancelled
Lint / ESLint (push) Has been cancelled
Lint / PHPCS (push) Has been cancelled
PHPUnit / File Diff (push) Has been cancelled
PHPUnit / PHPUnit - WordPress 6.5 - PHP version 7.4 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress 6.6 - PHP version 7.4 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress latest - PHP version 7.4 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress nightly - PHP version 7.4 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress 6.5 - PHP version 8.0 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress 6.6 - PHP version 8.0 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress latest - PHP version 8.0 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.0 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress 6.5 - PHP version 8.1 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress 6.6 - PHP version 8.1 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress latest - PHP version 8.1 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.1 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress 6.5 - PHP version 8.2 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress 6.6 - PHP version 8.2 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress latest - PHP version 8.2 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.2 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress 6.5 - PHP version 8.3 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress 6.6 - PHP version 8.3 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress latest - PHP version 8.3 (push) Has been cancelled
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.3 (push) Has been cancelled
PHPUnit / PHPUnit - Test Results (push) Has been cancelled
Add Slack Notifications - GA (#577)
2025-11-26 13:54:54 +02:00

55 lines
1.3 KiB
JavaScript

const https = require('https');
const slackToken = process.env.CLOUD_SLACK_BOT_TOKEN || '';
const slackChannel = process.env.SLACK_CHANNEL || '#tmz-alerts';
const payloadJson = process.env.SLACK_PAYLOAD || '{}';
if (!slackToken) {
console.log('⚠️ Slack token not provided, skipping notification');
process.exit(0);
}
let payload;
try {
payload = JSON.parse(payloadJson);
payload.channel = slackChannel;
} catch (error) {
console.error('Failed to parse payload:', error.message);
process.exit(1);
}
const payloadStr = JSON.stringify(payload);
const data = Buffer.from(payloadStr, 'utf8');
const options = {
hostname: 'slack.com',
port: 443,
path: '/api/chat.postMessage',
method: 'POST',
headers: {
'Authorization': `Bearer ${slackToken}`,
'Content-Type': 'application/json',
'Content-Length': data.length
}
};
const req = https.request(options, (res) => {
let responseData = '';
res.on('data', (chunk) => {
responseData += chunk;
});
res.on('end', () => {
const response = JSON.parse(responseData);
if (res.statusCode === 200 && response.ok) console.log('✅ Slack notification sent');
process.exit(0);
});
});
req.on('error', (error) => {
console.error('Failed to send Slack notification');
process.exit(0);
});
req.write(data);
req.end();