Bots can be a super useful bridge between Slack channels and external applications. Let’s code a simple Slack bot as a Python application that combines the Slack API with the Twilio SMS API so a user can send and receive Slack messages via SMS.

Tools We Need

Our bot, which we’ll call “twiliobot”, requires Python, Slack and Twilio APIs and libraries. To write and run our Python code we need:

Here’s a handy step-by-step guide to setting up Python, pip, virtualenv and Flask.

The Slack dependencies are:

Our Twilio requirements include:

Free Twilio account

One Twilio phone number with SMS capabilities

Make sure Python version 2 or 3 is installed now. We will configure everything else throughout the remainder of this tutorial.

You can follow along by writing the code in this post or skip ahead to the finished project by cloning the companion GitHub repository.

Setting Our Environment

Now that we know what tools we need to use, go to the terminal (or Command Prompt on Windows) and change into a directory where you want to store this project. Within that directory, create a new virtualenv to isolate our application dependencies from other Python projects you’re working on.