Last active
April 20, 2021 22:04
-
-
Save ShayCichocki/4a7ec63d28abcea647534bdd4ed490f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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