Skip to content

Instantly share code, notes, and snippets.

@ShayCichocki
Last active April 20, 2021 22:04
Show Gist options
  • Save ShayCichocki/4a7ec63d28abcea647534bdd4ed490f1 to your computer and use it in GitHub Desktop.
Save ShayCichocki/4a7ec63d28abcea647534bdd4ed490f1 to your computer and use it in GitHub Desktop.
const https = require('https');
const yourWebHookURL = ''; // PUT YOUR WEBHOOK URL HERE
const slackMessage = {
'text': 'your message here',
};
function sendSlackMessage (webhookURL, messageBody) {
try {
messageBody = JSON.stringify(messageBody);
} catch (e) {
throw new Error('Failed to stringify messageBody', e);
}
return new Promise((resolve, reject) => {
const requestOptions = {
method: 'POST',
header: {
'Content-Type': 'application/json'
}
};
const req = https.request(webhookURL, requestOptions, (res) => {
let response = '';
res.on('data', (d) => {
response += d;
});
res.on('end', () => {
resolve(response);
})
});
req.on('error', (e) => {
reject(e);
});
req.write(messageBody);
req.end();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment