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

slackr-bot

v0.0.3

Published

API for using the slack RTM interface

Downloads

5

Readme

Slackr Bot

A node module for making bots that use the slack rtm api.

Initializing

The object you require is a session, to create a session all you need is a bot token, or a user token if the bot will be acting as that user.

var Session = require('slackr-bot');

var session = new Session(token);

Unfortunately bot's currently cannot send attachments, so built in is the ability to use an incoming webhook to send then automatically. You just have to configure it:

var session = new Session({
  token: token,
  devChannel: '#bottest',
  webhookClient: {
    token: 'xxxxxxxxxxxxxxxxxxxx',
    team: 'tumblr',
    username: 'ghbot',
    icon_url: 'http://michaelsharman.com/static/images/github_metro.png'
  }
});

All the data in the webhook client can be used but the only required ones are token and team.

The other option seen in this session instantiation is the dev channel. With this the bot will ignore anything in that channel unless NODE_ENV=development is set. In which case it will only listen to that channel.

send

To send a message over rtm just call session.send(obj). If you want to send a message there's a helper that allows you to call

session.sendMessage({
  channel: '#foo',
  text: 'omg'
});

Responding

To react to messages there are some helper matchers to let you match only certain strings being passed.

session.on('exact string match', cb);
session.on('.prefix *', cb);
session.on('*wildcard*', cb);
session.on(/regex/i, cb);
session.on('/regex string/i', cb);

Exact string match

The callback receives these arguments:

  1. Message - message object see section describing
  2. string - the matched string

Prefix match

The callback receives these arguments:

  1. Message - message object see section describing
  2. prefix - the prefix it matched on
  3. rest - the string that comes after the prfix

arguments[2] + arguments[3] === message.text

Wildcard match

The callback receives these arguments:

  1. Message - message object see section describing
  2. string - the matched string

Regex match

The callback receives these arguments:

  1. Message - message object see section describing
  2. match - the match object that came back from the successufl regex match

Message

The message object is passed to message callbacks. It has all the data passed in the message, as well as some helpers.

Simple usage:

session.on('.gh help', function(msg) {
  msg.reply('.gh team( <team name>)( cnt), .gh <user> recent( cnt)');
});

The message has a reply method that can be used. It can take a string or an object like shown in the advanced object

Advanced usage

session.on(/^.gh (\w+) recent(?: (\d+))?/, function(message, match) {
  var promise = getPersonsPr(match[1]);

  message.typing();

  var num = match[2] ? parseInt(match[2]) : 3;

  promise.then(function(prs) {
    var resp = {
      text: 'Pull Requests:'
      attachments: _(prs).first(num).map('attachment').value()
    };

    message.reply(resp);
  });
});

This shows many features of the response

  1. you can call inside of another callback to reply
  2. you can reply with advanced objects that contain attachments
  3. you can signal in these async actions a typing indicator

Todo

  • [ ] Tests
  • [ ] Update channels as new ones are created
  • [ ] Implement connection checking to add ability to reconnect dynamically

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request