Giter Site home page Giter Site logo

queue-bot's Introduction

Queue Bot

Queue Bot was designed to manage Slack-based help queues. Built with Python 2.7 and Slack's Real Time Messaging API.

The bot tracks which users are currently enqueued with a queue data structure built on top of a linked list. Each node in the linked list represents a user in the queue, and it contains that user's handle, formatted according to Slack's rules for @username posting.

Setup

You can get Queue Bot running in two stages: Slack setup and environment setup.

Creating a Custom Slack Bot Integration

First, integrate a bot with Slack so that you can get an API token for it. To integrate a custom bot with your Slack team, do the following:

  1. Log into the Slack team where you want to integrate a Queue Bot, and go to "Manage Apps" from the left-hand menu. This should bring you to the browser admin interface for your channel.

    https://github.com/jgriffith23/queue-bot/blob/master/images/manage_apps.png?raw=true
  2. Click the "Browse" button.

    https://github.com/jgriffith23/queue-bot/blob/master/images/browse_apps.png?raw=true
  3. Use the search bar to find the Bots app. Select it.

    https://github.com/jgriffith23/queue-bot/blob/master/images/find_bots_app.png?raw=true
  4. Click the "Add Configuration" button and follow the setup's only prompt: pick a username for your bot.

    https://github.com/jgriffith23/queue-bot/blob/master/images/on_bots_page.png?raw=true
  5. You should be sent to a page where you can customize your bot settings and view your API token. Yours should be something other than a blurry blob.

    https://github.com/jgriffith23/queue-bot/blob/master/images/bots_config_page.png?raw=true
  6. Make any customizations you want to make, save your integration, and head back to Slack. Keep the bot integration page open.

  7. Go to the channel where you want your bot to be able to post. In my code, the channel is called "help," but you can call it whatever you want.

  8. Invite your bot to that channel with the username you gave it in the admin interface.

Finally, copy your API token from the bot integration page of your Slack admin interface, and open your terminal.

Running the Code

I assume you already have your preferred version of Python installed. As I said before, this project was built with Python 2.7, but the setup for Python 3 should be similar.

  1. Download the files from this repo to a new directory (Clone it if you like. Heck, fork it and modify it.) and navigate into that directory.

  2. Put your API key into your shell environment. I suggest adding it to a file called secrets.sh and adding this bit of bash code:

    export BOT_API_TOKEN="a-really-long-thing-that-is-your-bot-token"

    Now, you can export your variable into the environment like this:

    source secrets.sh

    Just be sure to add secrets.sh to your .gitignore file to keep your secrets off the Internet!

    Fun fact: If you do accidentally push your Slack API token to GitHub, you'll receive a lovely email from Slack alerting you that your token was posted on the Internet and that they've disabled it. The email includes where the token was found and a link to how to issue a new one. Way to go, Slack!

  3. Create a virtual environment:

    virtualenv env
    
  4. Activate your virtual environment:

    source env/bin/activate
    
  5. Install all requirements:

    pip install -r requirements.txt
    
  6. With your secrets sourced and your environment activated, run queue_bot.py

The terminal should appear to hang. But if you start typing messages in the channel you invited your bot to, you should see a dictionary print to stdout for each message you send.

Available Commands

If you're seeing message data appear in your terminal, you're ready to start up a user queue. I've currently implemented four commands.

The following list shows the text you'd type in your Slack channel for each command, followed by a brief description.

  • queue.open(): Tell folks that your user queue is ready to be used. Set it to empty to start.
  • queue.close(): Empty all users from the queue and ask them to enqueue when it's open again.
  • queue = [] (or several other variations; see queue_bot.py): Empty the queue and show an emoji in their place to celebrate.
  • queue.enqueue(@username): Add the given user to the queue and display the queue's current contents.
  • queue.dequeue(): Remove the next user from the queue and display the queue's current contents.
  • queue.remove(@username): Remove the given user from the queue, wherever they are positioned, and display the queue's current contents.
  • queue.freeze(): Don't allow other users to be added to the queue.
  • queue.unfreeze(): What's on the tin. Unfreeze the queue.
  • queue.status(): Get the current status of the queue.

Future features that I'd like to implement include:

  • [X] A queue.freeze() command to keep users in the queue but not allow more to be added.

  • [ ] The ability for the queue to automatically close itself or freeze at a certain time, if it's known the queue needs to close then.

  • [ ] "Staff only" users: Get the user ids of particular users so that only they can use queue commands.

    (Note to self: try using sc.server.users.find('foo').id to get particular users' ids for the staff list.)

  • [ ] Allow users to be dequeued when the queue is frozen.

That's it! Hope you enjoy your new Slack-based user queue assistant.

Helpful Resources

I found these links helpful in building Queue Bot:

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.