code everywhere

messaging slack from phantomJS

posted on March 7, 2015, 8:44 pm in js

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'postDataheaders, 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.

recent posts

< back
find something helpful? send us some coin BTC 19u6CWTxH4cH9V2yTfAemA7gmmh7rANgiv

(ad) Need Hosting? Try Linode, VPS Starting from $5

privacy policy