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

slacktrigger

v1.0.3

Published

A tiny node module which facilitates the construction of trigger based slack bots.

Downloads

2

Readme

#Description

A tiny module which simplifies the creation of trigger based slackbots by allowing one to define handlers that behave in a command-argument style fashion.

#Usage

The module consumes the following positional arguments and returns an express app suitable for use as the target of an outgoing webhook.

  • handlers: An object whose keys correspond to commands and whose values correspond to handlers of those commands.

  • name: The default user name used by the bot, this can be overwritten by a handler that returns a response object containing the user_name property.

  • slack token: The token provided by the outgoing webhook used to verify requests. Any request whose token does not match the one provided is dropped.

  • api token: Your slack API token used for user name resolution.

A handler is a function which consumes a single object with the following properties and returns a promise that resolves to the message payload. This can either be a simple string or a response object of the kind expected by the webhook.

  • trigger: The bot trigger (i.e the first character of the posted message)
  • req: The original request made by the webhook
  • args: An array containing the tokenized argument list. Anything within single quotes is considered a single argument.
  • ulist: An object mapping slack uids to nicks

The corresponding outgoing webhook must have the 'trigger word(s)' field set to a single character, this is the character which precedes each command intended for the bot.

E.G

if trigger word(s) is ~ then ~command arg1 arg2 'this is arg3' will result in the 'command' handler being called with an object containing args: ['arg1', 'arg2', 'this is arg 3']

##Example

var slack = require('slacktrigger');
var q = require('q');

var handlers = {};

handlers.argdump = function(opts) {
  return q(JSON.stringify(opts.args));
};

handlers.greetme = function(opts) {
  return q('hello ' + opts.req.user_name );
};

handlers.ping = function() {
  return q('pong');
};

var app = slack(handlers, //handlers
    'testbot', //default bot name (can be overwritten in a handler by returning a request object containing 'username')
    '<slack token>', //slack token (provided by the outgoing webhook)
    '<api token>'); //api token

// Sample input/output (assumes % is the trigger specified in the outgoing webhook):
//
// user: %argdump one two 'arg three' => ['one', 'two', 'arg three' ]
// user: %greetme => user
// user: %ping => pong