slacky

2.1.0 • Public • Published

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

Param Type Description
fn function Middleware function

Example

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

middleware.run(done) ⇒ this

Execute middleware

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

Param Type Description
... Any Arguments to be passed to middleware
done function Function 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

Param Type Description
plugins Array | Object | function One or more plugins to register.
plugins.register function Options to pass to the plugin
plugins.options Object Options to pass to the plugin
callback function

router

router.listen(pattern, callback)

Listen

Kind: static method of router

Param Type Description
pattern RegExp | String Pattern to match incoming messages to.
callback function

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

Param Type Description
path String Message to match.

Readme

Keywords

none

Package Sidebar

Install

npm i slacky

Weekly Downloads

0

Version

2.1.0

License

MIT

Last publish

Collaborators

  • michaeljacobdavis