Skip to content

Instantly share code, notes, and snippets.

@tkambler
Last active October 7, 2015 10:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkambler/9104446 to your computer and use it in GitHub Desktop.
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)
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