Code Monkey home page Code Monkey logo

slackbot-api's Introduction

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();
});

slackbot-api's People

Contributors

mamal72 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

williamsbg03

slackbot-api's Issues

Send an image?

So I am using this api: https://picsum.photos/

And I want it to send an image from that api.

I am using axios and slackbot-api. I am new to this slackbot stuff, so if someone could anwser it would really help thanks!

I tried looking at issue #2, but I must have must have skipped it or something.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.