Skip to content

Instantly share code, notes, and snippets.

@deckerego
Created September 14, 2018 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deckerego/9ecf31d3e5b1049a740fc3dbff5185c7 to your computer and use it in GitHub Desktop.
Save deckerego/9ecf31d3e5b1049a740fc3dbff5185c7 to your computer and use it in GitHub Desktop.
Send a Message to Slack
'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