base-bot
v0.1.0
Published
Simple bot that knows how to handle events when told too. Use base bot to build more complex bots with plugins.
Downloads
1
Readme
base-bot
Simple bot that knows how to handle events when told too. Use base bot to build more complex bots with plugins.
Install
Install with npm
$ npm i base-bot --save
Usage
var bot = require('base-bot');
API
BaseBot
Create a new instance of a BaseBot with provided options.
Params
options
{Object}: Options to configure the github bot.
Example
var bot = new BaseBot();
.handle
Handle a payload object. The payload
will be passed to all registered handlers. Handlers may modify the payload
and return it in their callback
. The aggregated results will be returned in the handle
callback
.
Params
event
{String}: Event type to handle. Only listeners registered for this type will be notified.payload
{Object}: Payload object to handle.cb
{Function}: Callback to notify call when finished handling payload.
Example
bot.handle('issue', payload, function(err, results) {
if (err) return console.error(err);
console.log(results);
});
.handler
Add a specific on
and handle
methods for an event.
Params
method
{String}: Name of the methods to add.returns
{Object}this
: for chaining.
Example
bot.handler('issue');
bot.onIssue(function(payload, cb) { cb(null, payload); });
bot.handleIssue(payload, function(err, results) {
if (err) return console.error(err);
console.log(results);
});
.handlers
Add a specific on
and handle
methods for an array of events.
Params
methods
{String|Array}: Array of method names to add.returns
{Object}this
: for chaining.
Example
bot.handlers(['issue', 'commit']);
bot.onIssue(function(payload, cb) { cb(null, payload); });
bot.onCommit(function(payload, cb) { cb(null, payload); });
bot.handleIssue(payload, function(err, results) {
if (err) return console.error(err);
console.log(results);
});
bot.handleCommit(payload, function(err, results) {
if (err) return console.error(err);
console.log(results);
});
Related projects
- base-methods: base-methods is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… more | homepage
- use: Easily add plugin support to your node.js application. | homepage
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Author
Brian Woodward
License
Copyright © 2015 Brian Woodward Released under the MIT license.
This file was generated by verb on December 21, 2015.