2.1.0 • Published 8 years ago

slacky v2.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

Slacky - A minimalistic slackbot.

API

middleware

Middleware should have the function signature of next, event, data.

Example (Tip: Don't want your middleware to run on all events?)

bot.use(function (next, event, data) {
 const eventsICareAbout = ['message', 'something'];
 if(eventsICareAbout.indexOf(event) == -1) {
   next();
 }
 ... Deal with your event ...
});

middleware.use(fn) ⇒ this

Add middleware to the bot.

Kind: static method of middleware
Returns: this - Current bot

ParamTypeDescription
fnfunctionMiddleware function

Example

bot.use(function (next, event, data) {
  next();
});

middleware.run(done) ⇒ this

Execute middleware

Kind: static method of middleware
Returns: this - Current bot

ParamTypeDescription
...AnyArguments to be passed to middleware
donefunctionFunction to be called after middleware has executed

plugin

Plugins add many different pieces of functionality to a bot without having to manage everything in one repository.

Example

const plugin = function (options, next) {
  ... Add listeners or functionality ...
  next();
};
bot.register(plugin);

Example (You can also pass options to plugins by specifiying a `register` function (the plugin) and an `options` object.)

const plugin = function (options, next) {
  console.log(options.players); // 4
  next();
};
bot.register({ register: plugin, options: { players: 4 });

Example (`register` also can take an array of plugins.)

bot.register([require('plugin1'), { register: require('plugin2'), options: { players: 4 }]);

plugin.register(plugins, callback)

Register plugins to the bot.

Kind: static method of plugin

ParamTypeDescription
pluginsArray | Object | functionOne or more plugins to register.
plugins.registerfunctionOptions to pass to the plugin
plugins.optionsObjectOptions to pass to the plugin
callbackfunction

router

router.listen(pattern, callback)

Listen

Kind: static method of router

ParamTypeDescription
patternRegExp | StringPattern to match incoming messages to.
callbackfunction

Example

<caption>Listen takes either a string or regular expression and a callback. The callback is called
whenever a message matching that string/regexp is seen. The callback is called with the route,
message body, and a respond function to reply.</caption>
bot.listen('hello', function (route, message, respond) {
  respond('world');
});

Example (You can also use capture groups in a regular expression. They are returned as `route.matches`.)

bot.listen('hello (.*)', function (route, message, respond) {
  console.log(route.matches);
});

router.route(path)

Given a message, trigger the first applicable listener.

Kind: static method of router

ParamTypeDescription
pathStringMessage to match.
2.1.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago