Created
September 14, 2018 16:22
-
-
Save deckerego/9ecf31d3e5b1049a740fc3dbff5185c7 to your computer and use it in GitHub Desktop.
Send a Message to Slack
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
'use strict'; | |
const https = require('https'); | |
class Slack { | |
constructor(slackPath) { | |
this._options = { | |
hostname: "hooks.slack.com", | |
method: "POST", | |
path: slackPath, | |
}; | |
} | |
sendSlack(message) { | |
const payload = JSON.stringify({ | |
text: message, | |
}); | |
const req = https.request(this._options); | |
req.on("error", (error) => console.log("Error in sending Slack message: ", JSON.stringify(error))); | |
req.write(payload); | |
req.end(); | |
} | |
} | |
module.exports = Slack; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment