Giter Site home page Giter Site logo

slack-bot-commands's Introduction

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 token.

  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.

slack-bot-commands's People

Contributors

noviny avatar

Stargazers

Mike James avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.