How to Build an SMS Slack Bot in Python
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:
- Either Python 2 or 3
- pip and virtualenv to handle Python application dependencies.
- Flask web microframework, if you’re unfamiliar with Flask, many learning resources are available
The Slack dependencies are:
- Free Slack account with a team on which you have API access or sign up for the Slack Developer Hangout team
- Official Python slackclient code library built by the Slack team
- Slack API ...
Tutorials from Twilio: Live Coding on Twitch This Week
The launch celebration of Tutorials from Twilio continues as the Twilio developer evangelists take you through building their favorites live on Twitch. Join us all week long as we use these amazing new tutorials to equip you with the knowledge you need to add chat to an existing iOS mobile app, implement two-factor authentication in a Rails application, make phone calls from a browser using Python and Django and much more.
Find the schedule of the weeks streams below and we hope you join Team Twilio on Twitch.
Tuesday, March 22nd, 9:30am – 11:30am EDT
Greg Baugues – @gregbaugues
Adding Two Factor Authentication to a Laravel App with Authy
Tuesday, March 22nd, 10:30am – 12:30pm EDT (Archived video here)
Phil Nash – @phil_nash
Two Factor Authentication (2FA) in Ruby on Rails Apps
Wednesday, March 23rd, 9am-12pm EDT
Brent Schooley – @BrentSchooley
Building a chat app with Swift using Twilio IP Messaging ...
iOS and Web Browser Video Calls with Python and Swift
Tools We’ll Need
Python and Swift will serve as the two main programming languages we’ll use to get our web and mobile apps running. We’re going to set up the Python application first so let’s take a look at those resources we will need along the way:
- Twilio Python helper library to create our TwiML
- A free Twilio account, which will come with ...
City Chat with Python, Django and Twilio Programmable Chat
Looking for a new apartment in your city? Is it election day and you want to remind people to get out and vote? Want to poll residents for the best restaurant in their neighborhood?
In this blog post, we’ll build a messaging application where messages are broadcast to recipients based on the city reported by their browser location. Having everyone in your city join together in a chat application may seem crazy, but buckle up, because we’re going to give it a try. By combining Python, Django, Twilio Programmable Chat and the Google Maps API we’ll take our best shot at making it easier to find an apartment, remind your neighbors to vote or poll your fellow city residents.
Before we dive into building our neighborhood-based chat application, let’s take a look at the tools we’ll be using throughout this blog ...
Warm Phone Call Transfers with Python, Flask and Twilio Voice
Have you ever had your call disconnect while you were on hold with customer service and waiting for a transfer from one department to another? You probably felt like this when the call dropped:
A warm phone call transfer, where a caller is on the phone with an agent then the agent brings on another agent and introduces them to the customer, shouldn’t be so difficult. There are only a few steps that need to be done properly for a warm phone call transfer to work, as we can visualize in the following diagram.
As the diagram shows, a customer, who in this post we’ll refer to as Trinity, dials into a typical phone number for service. An agent, known as Agent Smith, answers the calls. However, Agent Smith discovers he can’t solve the problem and needs to connect Trinity to Agent Johnson, who’s better equipped ...
Choose Your Own Adventure Presentations: Wizard Mode Part 3 of 3 with Flask, Reveal.js and WebSockets
You’ve coded your way through the original Choose Your Own Adventure Presentations story, the Wizards Only gatekeeper and the Web Forms trials blog posts. Now it’s time to pull out our magical wands for one more trick and complete our application-building quest.
Voting with a wand (or smartphone)
In this final tutorial we’ll wrap up our Flask application with a new ability that will allow the audience to vote with a web browser on their wand…or smartphone. We will write code to keep track of audience votes from web browsers using websocket connections. The new browser-based voting can augment our existing SMS-based voting for presentations when cell signals aren’t working well.
Roll up the sleeves on your cloak and get ready to write a bit more Python code as we finish out our Choose Your Own Adventure Presentations application.
If you ...
Choose Your Own Adventure Presentations: Wizard Mode Part 2 of 3
In the first part of our Choose Your Own Adventure Presentations Wizard Mode tutorial we set up the necessary code for separating authorized wizards from non-wizards. However, logging in and out of an application isn’t very magical. It’s time to write write some new spells in Wizards Only mode to allow us to deftly manipulate our presentations.
Even Wizards Need Web Forms
The Wizards Only mode interface we’re creating throughout this post will grant us the ability to see which presentations are available as well as create and edit metadata, such as whether a presentation is visible or invisible to non-wizards.
What We’ll Need
If you followed along with part 1 of this series then you’ve already set up all of the dependencies and the database connections we’ll need for this part of ...
Choose Your Own Adventure Presentations: Wizard Mode Part 1 of 3
You’ve coded your way through the harrowing challenges of the first Choose Your Own Adventure Presentations tutorial. A sign lies in the road ahead. “PyCon has summoned you to give a Choose Your Own Adventure talk in Montreal!” it reads.
How do you proceed? If you choose to run from the PyCon challenge, close the browser window now. If you accept the challenge, prepare yourself for the dangers ahead with the new Wizard Mode functionality and continuing reading this blog post.
You’re still here, adventurer! Let’s get to work. In this series of three blog posts we’re going to expand the Choose Your Own Adventure Presentations application with new a Wizard Mode. If you haven’t yet worked through the original blog post I highly recommend doing that before working through this series. The section below named “A Clean Starting Point” will get you set up ...
Building A Multi Channel Support Desk with TaskRouter
We live in a time where there are more ways than ever for businesses and their customers to connect. As developers, we have the opportunity to build applications that help facilitate these connections. But if you’ve built a support desk before, you know that writing the code that manages agent availability and integrates multiple channels of communication can be complicated. Twilio built TaskRouter to help make building this type of functionality in your applications a bit easier.
In this post, we’ll show you specifically how to use the Twilio TaskRouter to build a support desk application that initially allows customers to contact you via phone. We’ll walk you through enhancing that application to scale to multiple agents and then add SMS as a second communication channel, routing each customer to the best agent for them.
Before we start coding, be sure to pull up the companion GitHub ...
Calculating Net Promoter Score with Python and SMS
On the Twilio Developer Evangelism team we’re constantly seeking quantitative feedback to improve how we work. In 2014, I began collecting feedback via SMS to calculate Net Promoter Score on my conference talks as one quantitative measure for how talks were received. For example, at the end of my DjangoCon 2014 talk you can see in the video how I asked the audience to text in a score based on how likely they were to recommend that talk to a friend or colleague.
In this blog post, we’ll walk through how you can also obtain quantitative data on your events by requesting scores from the audience via SMS and calculating Net Promoter Score with a Python script.
What is Net Promoter Score?
Before we get started with the code, let’s clarify what Net Promoter Score is and why it’s useful as a measurement tool. Net Promoter ...