Level up your Twilio API skills in TwilioQuest, an educational game for Mac, Windows, and Linux. Download Now
Build the future of communications.
Start building for free

Python posts

  • By Miguel Grinberg
    Play Chess with a Friend on WhatsApp using Python and Twilio Play Chess with a Friend on WhatsApp using Python and Twilio

    While most of the world is under some form of stay-at-home orders to prevent the spread of COVID-19, we are constantly looking for new ways to entertain ourselves and remain connected with family and friends.

    When I was little I used to play chess a lot, so now that I have additional time on my hands I decided to start playing again. The thing is, nobody in my immediate family plays chess, so I had this idea of using WhatsApp to play a game of chess against a remote friend.

    Chess game demo

    By the end of this tutorial you will know how to use the Twilio API for WhatsApp to implement a turn-based game that requires sending messages and images between multiple participants. You will also learn about how to manage a game of chess in Python, but even if chess isn’t your thing, you will be able to replace the chess …

    Read More
  • By Imran Khan
    Build a Live Traffic WhatsApp Chatbot with Python, Flask, Folium and Twilio Build a Live Traffic WhatsApp Chatbot with Python, Flask, Folium and Twilio

    Like most people I am endlessly frustrated by sitting in slow-moving traffic and I often wonder if I just got unlucky or is it always like this?  In this tutorial I’m going to show you how to answer that question by building a basic chatbot for WhatsApp using the Twilio API for WhatsApp and the Flask framework for Python.

    The chatbot will allow users to share their current location and get back a live traffic report and a link to an interactive map.  Here’s an example showing how it works:

    traffic chatbot demo

    Tutorial requirements

    To follow this tutorial you will need the following:

    • Python 3.6 or newer.  You can download an installer from python.org.
    • ngrok. We will use this free utility to connect our Flask application running on our local system to a public URL that Twilio can connect to from the Internet.  Installation instructions for your operating system can …
    Read More
  • By Liz Moy
    Build a Survey App With Python, Twilio, and Airtable Build a Survey App With Python, Twilio and Airtable

    "Scandia 010" by How I See Life is licensed under CC BY-ND 2.0

    Airtable is like a cool big-budget superhero crossover between a spreadsheet and a database.

    It’s easy to write to an Airtable from your Twilio app, so we’re going to take that idea and build off of it to make a SMS-driven survey app using Python and the Flask framework.

    The survey app we are going to build will gather NPS, which stands for Net Promoter Score, a metric used to measure customer experience. However, you can customize the survey for purposes specific to your needs. Try it out by texting your favorite emoji to the number below.

    Airtable NPS survey testing number with Twilio

    We’ll go through this step-by-step, and we will do it all in a single file. If you would like to download the complete project you can find it in this GitHub repository: https://github.com/Eclairemoy/nps-survey

    Building the Project

    Prerequisites

    To …

    Read More
  • By Dotun Jolaoso
    Voice and SMS One-Time Passwords with Python and Twilio Voice and SMS One-Time Passwords with Python and Twilio

    One-time passwords (OTPs) contain numeric or alphanumeric codes that are used to provide an extra layer of security for your applications, by ensuring that a user is authenticated for a particular transaction or a login session. In this tutorial, we’ll be building a simple Flask application that generates and validates OTPs that are delivered to users via Voice or SMS channels using Twilio.

    Technical requirements

    To follow along, you’ll need the following:

    • A free Twilio Account. If you use this link to register, you will receive $10 credit when you upgrade to a paid account.
    • Python 3.6 or newer.
    • A phone line that can receive voice calls and/or SMS.

    Creating a Python environment

    Let’s create a directory where our project will reside. From the terminal, run the following command:

    $ mkdir twilio_otp
    

    Next, cd into the project directory and run the following command to create a virtual environment.

    $ …
    Read More
  • By James Putterman
    Send Dynamic Emails with Python and Twilio SendGrid Send Dynamic Emails with Python and Twilio SendGrid

    Email is a critical part of any business communication strategy, both internally and externally. Today the need to have dynamic, content-driven, responsive email campaigns is critical. Twilio SendGrid allows organizations to deliver on this need with a highly performant and customizable CRM that works well in both the GUI and programmatically via API.

    In this tutorial, we’ll set up a free SendGrid account and, using Python, send ourselves both simple text/html emails as well as high-res, dynamic content. We’ll also retrieve sending data like the number of emails sent, how many were opened or clicked, if any bounced, etc.

    By the end of the tutorial you’ll be able to:

    • Set up a free SendGrid account and API key for interacting with the service
    • Set up a Python application that calls the SendGrid Web API v3, sends emails to different lists, and retrieves statistics about those sends
    • Start working with …
    Read More
  • By Gabriela Cavalcante
    Construindo um Twilio Webhook seguro com Python e FastAPI Construindo um webhook Twilio seguro utilizando Python e FastAPI

    Alguns dias atrás, eu estava procurando por um Framework Web Python para construir uma aplicação de chat que fosse assíncrona e que tivesse alta performance. Como eu sou bem familiarizada com Flask, não quis gastar tempo aprendendo algo muito diferente.

    Foi então que eu encontrei o FastAPI: um framework web moderno para construir APIs com Python 3.6+, baseado no Starlette e inspirado no Flask. Este framework utiliza o padrão das type hints, já traz validações e serialização, além de usar o padrão aberto para APIs, OpenAPI. Foi uma escolha perfeita porque este framework não somente suporta   requisições assíncronas como também geração automática de documentação. Você pode encontrar outros recursos incríveis do FastAPI aqui.

    Nesse tutorial, nós vamos construir um webhook Twilio usando esse framework fantástico. Para entender na prática como o FastAPI funciona e como podemos construir aplicações com ele, vamos implementar um webhook seguro …

    Read More
  • By Miguel Grinberg
    Build a COVID-19 Bot with Python and Twilio Autopilot Build a COVID-19 Bot with Python and Twilio Autopilot.png

    Twilio Autopilot makes it easy to build conversational bots that provide information to users in a highly engaging and intuitive format. A single Autopilot bot can be deployed on several channels including SMS, Voice, WhatsApp, Slack, Alexa and more.

    In this tutorial we are going to build a bot that provides COVID-19 stats for all countries using a purely conversational style. We will train the bot with example sentences to help it extract meaning from the freeform text entered by the user. Once you learn how this specific bot works, you will be able to adapt it to other data sources.

    Autobot conversation

    The aspects that make this bot interesting that I’d like you to notice are:

    • The user makes requests in an informal and conversational tone. Autopilot makes it very easy to “teach” the bot how people ask questions using freeform language, and how to extract the actual information embedded in …
    Read More
  • By Kelley Robinson
    Secure your video conference with one-time passcodes How to protect your video conference with one-time passcodes

    As we dutifully practice social distancing, live video conferencing is increasingly popular. From company meetings to yoga classes and magic shows, traditional in person events are going virtual. But while technology connects us, it also comes with privacy and security risks.

    This post will show you how to add one-time passcode authentication on top of your Twilio Video application to ensure that only registered users are able to access the conference.

    While passwords may help protect against war dialing, they don't guarantee that the people joining the video conference should be allowed to participate. A lot of people are still widely sharing Zoom meeting IDs and passwords.

    One-time passcode authentication is useful for gating:

    • Paid content like workout classes, political fundraisers, or live dating shows.
    • Sensitive content with an access control list (ACL)

    This tutorial will walk you through adding Twilio Verify SMS verification to …

    Read More
  • By Nahuel Sznajderhaus
    Handle Twilio Debugger Events with Python and Flask Handle Twilio Debugger Events with Python and Flask

    Twilio offers a wide range of APIs. One Twilio account can run many applications, and perhaps your team develops and maintains a specific range of them. To best debug your applications when (and not if) there are errors, it would be nice to filter through debugger events and only get the notifications that you need to see.

    In this post, I’ll show you how to leverage Twilio’s Debugger Alert Triggers to receive, process and store the error events from your selected Twilio application. That is, you’ll be able to write an application that listens to events from the Twilio Debugger and writes relevant content about them into a comma separated values (CSV) file that you maintain on your machine. In a more advanced project, you could write this into a cloud database instead. The idea is the same.

    Tutorial requirements

    We will be using Python, so I’ll assume …

    Read More
  • By Haki Benita
    Testing a Twilio Interactive Voice Response (IVR) System With Python and pytest Testing a Twilio IVR System with Python and pytest

    In a previous tutorial you learned how to build an IVR system with Python, Django and Twilio. In that project you created an IVR system that provides users with information about movie show times over the phone.

    In this article you are going to add automated tests for the IVR system using Pytest.

    Why You Should Test Your System

    Maintaining good and comprehensive tests is crucial for your project's success. First, as a developer, writing tests gives you an opportunity to experience what it's like to be a customer of your own system. Whether you are developing an API, a website, a dashboard or an IVR system, writing tests is like using your own system. If there is something wrong, or something that can be improved, you are going to notice it when you try to test it.

    Good tests are tests you can trust. If once all the …

    Read More
  • Newer
    Older
    Sign up and start building
    Not ready yet? Talk to an expert.