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

slacktion

v2.0.1

Published

A toolkit for creating slash commands for Slack

Downloads

1

Readme

slacktion

Build a slash command for Slack without the boilerplate.

Example

const Command = require('slacktion').Command;

let repeater = Command(DATA_POSTED_BY_SLACK, VALIDATION_TOKEN);

repeater.action(/reverse (.*)/, 'reverse [text]: Repeats back the text in reverse',
    (data, matches, callback) => {
      callback({
        response_type: 'ephemeral',
        text: matches[1].split('').reverse().join('')
      });
    }
  )
  .action(/.*/, '[text]: Repeats back the text',
    (data, matches, callback) => {
      callback({
        response_type: 'ephemeral',
        text: data.text
      });
    }
  )
  .execute((err, result) => {});

Installation

$ npm install slacktion

Features

  • validate token
  • define multiple actions with regular expressions
  • automatically build a help action that explains the command's usage

Usage

Create a command

Instantiate your command by passing it the data Slack posted to your URL and the validation token you received from Slack when creating the command.

const Command = require('slacktion').Command;
let repeater = Command(DATA_POSTED_BY_SLACK, VALIDATION_TOKEN);

action(pattern, description, handler)

A simple command might have just one action:

repeater.action(/.*/, '[text]: Repeats back the text',
  (data, matches, callback) => {
    callback(null, {
      response_type: 'ephemeral',
      text: data.text
    });
  }
);

The pattern should be a regular expression that will be executed against the text a user enters. You can use capture groups to parse the text and those matches will be sent to your handler.

The description is a string that will be used to automatically build a help action. For example, the action above would respond with the following when a user types "/repeat help":

• /repeat [text]: Repeats back the text in reverse

The handler should look like (data, matches, callback) => {}. The data object includes all the data posted to your URL from Slack. The matches array includes the results of executing the pattern against the text sent from Slack (i.e., everything that the user typed after the command). The callback follows Node's standard (err, result) => {} style.

Multiple actions

A more complex command can define multiple actions, each with their own regular expression to match against whatever the user typed.

repeater.action(/reverse (.*)/, 'reverse [text]: Repeats back the text in reverse',
    (data, matches, callback) => {
      callback({
        response_type: 'ephemeral',
        text: matches[1].split('').reverse().join('')
      });
    }
  )
  .action(/.*/, '[text]: Repeats back the text',
    (data, matches, callback) => {
      callback({
        response_type: 'ephemeral',
        text: data.text
      });
    }
  )

execute(callback)

Execute the command, which will find the first action with a pattern that matches the text received from Slack run that action's handler.

repeater.execute((err, result) => {
  // handle err or result
});

If no matching action is found, the error will be null and the result will be a simple message explaining that the text could not be matched to an action.

Options

When creating your command, you can force it to respond to the URL Slack provides for delayed responses instead of the original request.

let cmd = Command(DATA_POSTED_BY_SLACK, VALIDATION_TOKEN, {
  force_delay: true
});

This can be useful if you want to respond in a channel without showing the original command and without setting up an incoming webhook. You can immediately acknowledge the response and customize that message with the delay_response option.

let cmd = Command(DATA_POSTED_BY_SLACK, VALIDATION_TOKEN, {
  force_delay: true,
  delay_response: {
    response_type: 'ephemeral',
    text: '10-4, good buddy'
  }
});