Last active
October 7, 2015 10:49
-
-
Save tkambler/9104446 to your computer and use it in GitHub Desktop.
A simple script that demonstrates how you can create a Hubot plugin with raw JavaScript (i.e. without CoffeeScript)
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
var util = require('util'); | |
/** | |
* A simple script that demonstrates how you can create a Hubot plugin with raw | |
* JavaScript (i.e. without CoffeeScript) | |
*/ | |
var Plugin = function(robot) { | |
/** | |
* Instruct Hubot to respond when a message is directed at him, like so: | |
* hubot ... | |
*/ | |
robot.respond(/test/, function(msg) { | |
msg.send("OK."); | |
}); | |
/** | |
* Instruct Hubot to respond when he hears a message within a room. Doesn't | |
* have to be directed at him. | |
*/ | |
robot.hear(/herp/, function(msg) { | |
msg.send('Derp.'); | |
}); | |
/** | |
* Instruct Hubot to listen for POST requests to the specified URL. | |
*/ | |
robot.router.post('/something/test', function(req, res) { | |
console.log('body', req.body); | |
res.send('ok'); | |
robot.messageRoom('#test', '123'); | |
}); | |
/* | |
You can also make outbound HTTP requests using robot's `http` method: | |
robot.http('http://www.theverge.com').get()(function(err, resp, body) { | |
console.log(arguments); | |
}); | |
*/ | |
}; | |
module.exports = function(robot) { | |
return new Plugin(robot); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment