• Stars
    star
    759
  • Rank 59,846 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created about 7 years ago
  • Updated 16 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple, yet powerful and extendable Slack bot

Slack Machine

Join the chat at Slack image image image CI Status image

Slack Machine is a simple, yet powerful and extendable Slack bot framework. More than just a bot, Slack Machine is a framework that helps you develop your Slack workspace into a ChatOps powerhouse. Slack Machine is built with an intuitive plugin system that lets you build bots quickly, but also allows for easy code organization. A plugin can look as simple as this:

from machine.plugins.base import MachineBasePlugin
from machine.plugins.message import Message
from machine.plugins.decorators import respond_to


class DeploymentPlugin(MachineBasePlugin):
    """Deployments"""

    @respond_to(r"deploy (?P<application>\w+) to (?P<environment>\w+)")
    async def deploy(self, msg: Message, application, environment):
        """deploy <application> <environment>: deploy application to target environment"""
        await msg.say(f"Deploying {application} to {environment}")

Note

As of v0.30.0 Slack Machine dropped support for the old backend based on the RTM API. As such, Slack Machine is now fully based on AsyncIO. This means plugins written before the rewrite to asyncio aren't supported anymore. See here for a migration guide to get your old plugins working with the new version of Slack Machine.

It's really easy!

Features

  • Get started with mininal configuration
  • Built on top of the Slack Events API for smoothly responding to events in semi real-time. Uses Socket Mode so your bot doesn't need to be exposed to the internet!
  • Support for rich interactions using the Slack Web API
  • High-level API for maximum convenience when building plugins
  • Low-level API for maximum flexibility
  • Built on top of AsyncIO to ensure good performance by handling communication with Slack concurrently

Plugin API features:

  • Listen and respond to any regular expression
  • Respond to Slash Commands
  • Capture parts of messages to use as variables in your functions
  • Respond to messages in channels, groups and direct message conversations
  • Respond with reactions
  • Respond in threads
  • Respond with ephemeral messages
  • Send DMs to any user
  • Support for blocks
  • Support for message attachments [Legacy 🏚]
  • Listen and respond to any Slack event supported by the Events API
  • Store and retrieve any kind of data in persistent storage (currently Redis, DynamoDB and in-memory storage are supported)
  • Schedule actions and messages
  • Emit and listen for events
  • Help texts for Plugins

Coming Soon

  • Support for Interactive Buttons
  • ... and much more

Installation

You can install Slack Machine using pip:

$ pip install slack-machine

or add it to your Poetry project:

poetry add slack-machine

It is strongly recommended that you install slack-machine inside a virtual environment!

Usage

  1. Create a directory for your Slack Machine bot: mkdir my-slack-bot && cd my-slack-bot

  2. Add a local_settings.py file to your bot directory: touch local_settings.py

  3. Create a new app in Slack: https://api.slack.com/apps

  4. Choose to create an app from an App manifest

  5. Copy/paste the following manifest: manifest.yaml

  6. Add the Slack App and Bot tokens to your local_settings.py like this:

    SLACK_APP_TOKEN = "xapp-my-app-token"
    SLACK_BOT_TOKEN = "xoxb-my-bot-token"
    
  7. Start the bot with slack-machine

  8. ...

  9. Profit!

Documentation

You can find the documentation for Slack Machine here: https://dondebonair.github.io/slack-machine/

Go read it to learn how to properly configure Slack Machine, write plugins, and more!

More Repositories

1

pelican-bootstrap3

Bootstrap 3 theme for Pelican
331
star
2

virtual-hadoop-cluster

A virtual Hadoop cluster running CDH5
104
star
3

graphite-stack-ansible-vagrant

Provision a complete Graphite, StatsD & Grafana install using Ansible and (optionally) Vagrant
Shell
63
star
4

statserver

This is a complete statistics & monitoring solution provisioned by Ansible
53
star
5

sentry-ansible-vagrant

Provision a complete Sentry install using Ansible and (optionally) Vagrant
Shell
47
star
6

gapi-php

Updated Gapi class for Google Analytics
PHP
21
star
7

flume-plugins

Some extensions to Flume to help with collecting logs and storing as Avro.
Java
17
star
8

flood

Python search APIs to various Torrent trackers
Python
11
star
9

dandydev.net

My personal site
HTML
10
star
10

dotfiles

My personal dotfiles
Shell
10
star
11

sentry-vagrant

Vagrant/Puppet provisioning for Sentry
Ruby
9
star
12

daan.fyi

MDX
8
star
13

secure-dev-proxy

Setting Up a Secure Development Proxy
Shell
7
star
14

fabdocker

Docker deployments with Fabric
Python
5
star
15

ploy

Go
3
star
16

pythonserver-ansible

Ansible Playbook to setup a Python server
1
star
17

sgannotate

JavaScript
1
star
18

gitsentry

Watch git repositories for changes to specific paths and get notified on Slack
Python
1
star
19

autoplaylistpoetry

Generate Spotify playlists from a piece of text
Python
1
star
20

JackAMovie

JackAMovie
CSS
1
star
21

pyalgorithms

Basic algorithms in Python
Python
1
star
22

RegDomain

Extract domain/hostname from URL in PHP
PHP
1
star
23

flybot

The MakeItFly Slack bot
CoffeeScript
1
star
24

docker-presentation

JavaScript
1
star
25

makeitfly_hubot

CoffeeScript
1
star
26

excel2note

Excel2Note creates Evernote notes from an Excel sheet
Python
1
star