npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

slackbot-api

v1.13.2

Published

Simple, consistent and customizable Slack bot API

Downloads

98

Readme

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