1.13.2 • Published 8 years ago

slackbot-api v1.13.2

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

slackbot-api

Travis CI Codecov GitHub

Simple, understandable Slack Bot API.

Documentation.

#Quick overview ##initialize

import Bot from 'slackbot-api';
let bot = new Bot({
  token: process.env.SLACK_BOT_TOKEN // YOUR TOKEN HERE
});

##hear Listen on all incoming messages matching a pattern.

bot.hear(/hi (.*)/, message => {
  let name = message.match[1]; // message.match = message.text.exec(regex);

  message.reply('Hello!');
})

##listen Listen on all incoming messages mentioning the bot (with or without @)

bot.listen(/help/, message => {
  message.reply('You\'ve come to the right person!');
});

##sendMessage

bot.sendMessage('general', 'Hello guys! wassup?');
bot.sendMessage('general', 'Hello', {
  unfurl_links: false,
  // extra parameters, see https://api.slack.com/methods/chat.postMessage
});

##deleteMessage

let msg = await bot.sendMessage('general', 'Hello guys! wassup?');
msg.delete();
// or
bot.deleteMessage('general', msg.ts);

##updateMessage

let msg = await bot.sendMessage('general', 'i can haz cakez');
msg.update('Yarrrrr!');
// or
bot.updateMessage('general', msg.ts, 'Yarrrrr!');

##react Add reactions to messages.

bot.listen(/rocket/, message => {
  message.react('rocket');
})

bot.react('general', msg.ts, 'rocket');

##icon Set bot's profile icon.

bot.icon('warning');

##random Choose an argument randomly. Arguments may also be arrays.

bot.listen(/hey/, message => {
  message.reply(bot.random('Hi', 'Hello', 'Wassup'));
})

##on Listen on events.

bot.on('channel_joined', event => {
  bot.sendMessage(event.channel.id, 'Hello guys! Thanks for inviting me.');
});

##message events You can also listen on individual messages' events

bot.listen(/list/, message => {
  message.on('update', msg => {
    msg.reply(`Updated from ${message.text} to ${msg.text}`);
  })
  message.on('delete', msg => {
    msg.reply('Are you hiding something?');
  });

  message.on('reaction_added', ...);
  message.on('reaction_removed', ...);
});

##find Find a channel, user, IM, whatever by it's id or name.

let user = bot.find('mdibaiee');
let channel = bot.find('general');
let group = bot.find('my-secret-group');
let byId = bot.find('U0123456');

##Modifiers In order to create advanced plugins/tasks, you might need to modify behaviour of a function, in order to do that, bolt provides you modifiers.

There are three types of modifiers:

###preprocess Used to modify arguments of a function:

// Allow string patterns
bot.modifiers.preprocess('listen', (pattern, fn) => {
  if (typeof pattern === 'string') {
    let regex = new RegExp(pattern);
    return [regex, fn];
  }

  return [pattern, fn];
});

###postprocess Used to modify return value of a function:

bot.modifiers.postproess('listen', (bot) => {
  return 'Hey, I\'m listen and I\'m returning this!');
})

###middleware Used to decide whether a function's main action should be called or not:

bot.modifiers.middleware('hear', context => {
  // Our bot must be polite!
  if (context.message.indexOf(BAD_WORD) > -1)
    return Promise.reject();

  return Promise.resolve();
});
1.13.2

8 years ago

1.13.1

8 years ago

1.13.0

8 years ago

1.12.3

8 years ago

1.12.2

8 years ago

1.12.1

8 years ago

1.12.0

8 years ago

1.11.4

8 years ago

1.11.3

8 years ago

1.11.2

8 years ago

1.11.1

8 years ago

1.11.0

8 years ago

1.10.1

8 years ago

1.10.0

8 years ago

1.9.6

8 years ago

1.9.5

8 years ago

1.9.4

8 years ago

1.9.3

8 years ago

1.9.2

8 years ago

1.9.1

8 years ago

1.9.0

8 years ago

1.8.2

8 years ago

1.8.1

8 years ago

1.8.0

8 years ago

1.7.7

8 years ago

1.7.6

8 years ago

1.7.5

8 years ago

1.7.4

8 years ago

1.7.3

8 years ago

1.7.2

8 years ago

1.7.1

8 years ago

1.7.0

8 years ago

1.6.5

8 years ago

1.6.4

8 years ago

1.6.3

8 years ago

1.6.2

8 years ago

1.6.0

8 years ago

1.5.13

8 years ago

1.5.12

8 years ago

1.5.11

8 years ago

1.5.9

8 years ago

1.5.8

8 years ago

1.5.7

8 years ago

1.5.6

8 years ago

1.5.5

8 years ago

1.5.3

8 years ago

1.5.2

8 years ago

1.5.1

8 years ago

1.5.0

8 years ago

1.4.8

8 years ago

1.4.7

8 years ago

1.4.6

8 years ago

1.4.5

8 years ago

1.4.4

8 years ago

1.4.3

8 years ago

1.4.2

8 years ago

1.4.1

8 years ago

1.4.0

8 years ago

1.3.3

8 years ago

1.3.2

8 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.3

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.7

8 years ago

1.0.3

9 years ago

1.0.0

9 years ago