Last active
January 26, 2017 01:06
-
-
Save vampaynani/8395192d0faa4716dc2de6dafba09bbe to your computer and use it in GitHub Desktop.
Basic Slack Bot [NodeJS]
This file contains hidden or 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
var prompt = require('prompt'); | |
var fs = require('fs'); | |
var request = require('request'); | |
fs.readFile('package.json','utf8', function(err, data){ | |
var package=JSON.parse(data); | |
prompt.start(); | |
prompt.get(['username'], function(err, result){ | |
var username = result['username'] || process.env.USER || process.env.USER_PROFILE, | |
version = package.version; | |
var url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"; | |
var data = { | |
text:"Deploy to www.domain.com v"+version+" by "+username, | |
channel:"#dev-status", | |
username:"my-bot" | |
}; | |
request.post({ | |
url: url, | |
headers: {'Content-type': 'application/json'}, | |
body: JSON.stringify(data) | |
}, function(error, response, body){ | |
if(error) console.log(error); | |
}); | |
console.log("Deploy to www.domain.com v"+version+" by "+username); | |
}); | |
}); |
This file contains hidden or 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
{ | |
"name": "Slack Bot", | |
"version": "1.0.0", | |
"private": "true", | |
"scripts": { | |
"bot": "node bot.js" | |
}, | |
"devDependencies": { | |
"prompt": "^1.0.0", | |
"request": "^2.76.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment