messaging slack from phantomJS
posted on March 7, 2015, 8:44 pm in
With all testing frameworks, its useful to get a message when your tests are completed instead of constantly looking at log files. And many companies are now using Slack for communication.
Here's how to get a message from PhantomJS to Slack without any plugins.
var slackPage = require('webpage').create();
var message = "Send this message to Slack!";
var postData = encodeURI('token=YOUR-SLACK-API-TOKEN&channel=#YOUR-CHANNEL&username=YOUR-USERNAME&text=' + message);
var headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postData.length
};
slackPage.open('https://slack.com/api/chat.postMessage', 'post', postData, headers, function( status ) {
console.log("status=", status);
console.log("content=", slack.content);
});
Replace the token, channel, username and message with your details and what you'd like to send.