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

slack-bot-commands

v1.0.4

Published

Tool to help quickly construct a slack bot that responds to commands.

Downloads

3

Readme

Slack Bot commands

A quick and easy way to get set up with a slack bot, by having an extensible class that listens to messages to run commands.

Getting Set Up

  1. Create yourself a slack app, (see instructions on slack), and get a slack team ID to pass to your bot.

  2. Create an index:

const token = process.env.SLACK_TOKEN;
const commands = require('./commands');
const slackBot = require('slack-bot-commands')

let res =  slackBot(commands, token);

module.exports = res;

The res will be a function that when called, will set up a service worker listening for messages on the app. All messages that are not bot messages, will be passed to your commands.

  1. Building your commands.

We have a class that can be exported and extended to create your commands, and then the base classes can be returned in an array as the commands to the SlackBot function.

const { Command } = require('slack-bot-commands');

class ourCommand extends Command {
	constructor(message) {
		super(message);
		this.testRegex = /^some action/i;
		this.name = 'Our New Action';
	}

	action() {
		return 'This message will be printed when the message matches the regex';
	}
}
  1. Behind the scenes

The Command class has a 'test' method, which will be called. If it returns true, the action will be called, and the result will be passed back to slack. All commands are tested for every non-bot slack message.

Other Notes

There is a 'help' command by default, which will list all the commands available, what their test regexes are, and their descriptions.

Hidden export:

const { CommandTester } = require('slack-bot-commands');
const someCommand = require('./someCommand');

CommandTester(someCommand, {
	text: 'our slack message',
	user: '1234',
	channel: '5678',
})

This will test the command, tell you if it doesn't pass the test, and if it passes, run the action, logging the result of the action. This can help you iterate your commands without clogging up a test slack channel.