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

Code, Tutorials and Hacks

  • By Daizen Ikehara
    Event Streamsを用いてTwilioのログをNode.jsとExpressサーバーアプリケーションで処理する方法 event-streams-nodejs-express-jp

    Event Streamsは執筆時点でPublic Betaとなるため、今後設定方法や仕様が変更される可能性があります。


    例 - Programmable SMS API(statusCallbackで検索)


    Event Streamsは各サービスのログをCloudEventsの仕様に沿って正規化、集約し、指定した宛先に配信します。そのためサービスごとに複数のコールバックを指定する必要がなく、またログの処理やエラーハンドリングをより簡単に実装できます。今回はこのEvent StreamsをNode.js/Expressサーバーアプリケーションで利用する方法を紹介します。また、Event Streamsの特長についてはこちらの記事で取り上げられていますのでぜひご覧ください。

    FAQにも記載されていますが、Event Streamsは既存のステータスコールバックを置き換えるものではありません。今後も引き続き利用できます。


    このチュート …

    Read More
  • By Ismael Hernández Muñoz
    How to Run a Canary Analysis with Kayenta header - How to Run a Canary Analysis with Kayenta

    A Canary Deployment is a deployment technique to reduce the risk of deploying a new version of an application or service into production. The new version, referred to as the canary, is first rolled out to a small subset of users.

    The application is monitored for errors or other anomalies that may have been introduced by the new software version. If none are detected, then the new version can be rolled out to the entire infrastructure and made available to everybody. This process is explained with the diagram below:

    diagram demonstrating the differences between software versions for two test groups

    However, the monitoring required to determine whether a new release can be rolled out to everybody can be difficult. To make sure the new changes do not introduce any issues, developers must analyze metrics such as system resource usage, latency, or application errors.

    Metrics produced by the canary version are compared to the previous version to find any significant differences between …

    Read More
  • By Mia Adjei
    Build a Free 1:1 Video Chat Application with Twilio WebRTC Go and Ruby Build a Free 1:1 Video Chat Application with Twilio WebRTC Go and Ruby

    Have you ever wished you could build a video chat application to talk to a friend, family member, or colleague one-on-one? With Twilio WebRTC Go, you can build your own video application where two participants can video chat for free.

    In this tutorial, you will learn how to build a 1:1 video chat application with Ruby and JavaScript, and set it up to run on ngrok so you can chat with a friend. The application will consist of two parts: a vanilla JavaScript client-side application that will allow you to connect to a video room, and a Ruby/Sinatra server that will grant Access Tokens for the participants in the video chat.

    If you would like to skip ahead and take a look at the code, check out the project repository on GitHub here.

    Let's get started!


    • A free Twilio account. (If you register here, you'll receive …
    Read More
  • By Kelley Robinson
    Build a carrier block list with Twilio Lookup Build a carrier block list with Twilio Lookup

    Bad actors can target phone verification or two-factor authentication flows to artificially inflate SMS traffic. Certain carriers, knowingly or not, allow this to happen and the fraudsters make money off of this inflated traffic. This could lead to higher than expected Twilio traffic for you.

    Our Verify API for sending one-time passcodes includes comprehensive fraud mitigation mechanisms. However, no provider-side solution can guarantee 100% effectiveness against sophisticated attackers, which is why we encourage customer participation in preventing attacks.

    Fortunately, Twilio's Lookup API can detect carriers and we can use this to filter out known bad actors before sending an SMS verification.

    Here's a quick snippet of an example block list:

    const accountSid = process.env.TWILIO_ACCOUNT_SID;
    const authToken = process.env.TWILIO_AUTH_TOKEN;
    const client = require("twilio")(accountSid, authToken);
    // hard coded for demo purposes only
    const block = ["12301", "12302"];
     .fetch({type: ["carrier"]})
     .then((resp) => {
       const mccmnc = resp.carrier.mobile_country_code + resp.carrier.mobile_network_code
       if (block.includes(mccmnc)) …
    Read More
  • By Matthew Gilliard
    Transcription live avec Twilio Media Streams, Azure cognitive Services et Java Transcription en direct avec Twilio Media Streams, Azure cognitive Services et Java

    Twilio Media Streams peut être utilisé pour diffuser des données audio en temps réel d'un appel téléphonique vers votre serveur à l'aide de WebSockets. Associé à un système de synthèse vocale, il peut être utilisé pour générer une transcription en temps réel d'un appel téléphonique. Dans ce post, je vais vous montrer comment configurer un serveur Java WebSocket pour gérer les données audio de Twilio Media Streams et utiliser Azure cognitive Services Speech pour la transcription.


    Pour suivre ce tutoriel, vous devez disposer des éléments suivants :

    Si vous souhaitez passer à l'étape suivante, vous pouvez trouver le code complété dans mon répertoire sur GitHub.

    Mise en route

    Pour qu'un projet Web Java soit rapidement opérationnel, je vous recommande d'utiliser …

    Read More
  • By Diane Phan
    Utiliser la reconnaissance d'images avec l'API Twilio WhatsApp Comment utiliser la reconnaissance d'images avec l'API Twilio WhatsApp

    Le concept de reconnaissance des images peut sembler être un défi, mais avec l'aide de API de reconnaissance d'images de Clarifai, le code peut prédire le contenu d'une image donnée et déterminer les concepts pour décrire l'image, ainsi que la valeur de prédiction de la précision de la classification de l'image.

    Dans cet article, nous allons vous expliquer comment développer un programme Python fonctionnel pour identifier le contenu multimédia à l'aide de l'API Twilio WhatsApp API, API Clarifai, et Flask.

    Configuration requise pour le tutoriel

    Pour créer ce projet, vous devez disposer des éléments suivants :

    • Python 3.6 ou version ultérieure. Si votre système d'exploitation ne fournit pas d'interpréteur Python, vous pouvez vous rendre sur python.org pour télécharger un programme d'installation.
    • ngrok est un utilitaire pratique pour connecter la version de développement de notre application Python exécutée sur votre système à une URL publique …
    Read More
  • By Diane Phan
    How to Start an HTTP Servlet helper - How to Start an HTTP Servlet

    With so many Java technologies available, it can be difficult to figure out which one to use to power a Java-based web application.

    Beginner Java programmers can benefit from using servlets because they provide an opportunity to understand low-level concepts in Java. Servlets are also great for building interactive web applications and dynamic web pages as they are used to extend apps hosted by web servers. They handle HTTP requests between a browser and any client, database, or application on the HTTP server.

    In this article, you will learn how to build and run your first servlet to host your Java application.

    Tutorial requirements

    Start a new Java project with Gradle

    Gradle is a handy tool that will allow you to build any software on different platforms with high performance. If you use Homebrew, enter the following command to install Gradle: …

    Read More
  • By Ashley Boucher
    Verify a User via Phone with Twilio Functions and Twilio Verify verifyvoice.png

    Many applications verify and authorize their users by sending a numeric code, called a One-Time Passcode (OTP), to the user’s phone number via either a voice call or a text message.

    In this article you’ll learn how to perform user verification via a phone call through Twilio Verify. You’ll build a pared down frontend using JavaScript and HTML and you’ll build a Node.js backend, all hosted with Twilio Functions, which will be scaffolded using the Twilio Serverless Toolkit, a plugin for the Twilio CLI.


    To get started with this tutorial, you’ll need the following:

    Read More
  • By Sam Agnew
    Fichiers et Asynchrone dans Python avec iofiles et asyncio Fichiers et Asynchrone dans Python avec iofiles et asyncio

    Le code asynchrone est devenu un pilier du développement Python. Comme asyncio fait partie de la librairie standard et que de nombreux packages tiers fournissent des fonctionnalités compatibles avec lui, ce paradigme n'est pas prêt de disparaître.

    Si vous écrivez du code asynchrone, il est important de vous assurer que toutes les parties de votre code fonctionnent ensemble afin que l'un des aspects du code ne ralentisse pas tout le reste. Les E/S de fichiers peuvent être un blocage courant sur ce front. Voyons comment utiliser la librairie aiofiles pour travailler de manière asynchrone avec des fichiers.

    En commençant par les bases, il s'agit de tout le code dont vous avez besoin pour lire le contenu d'un fichier de manière asynchrone (dans une fonction async) :

    async with aiofiles.open('filename', mode='r') as f:
        contents = await f.read()

    Voyons cela plus en détail.

    Qu'est-ce qu'un code non bloquant ?

    Vous pouvez …

    Read More
  • By Joseph Udonsak
    A Beginner's Guide to Test Driven Development With Symfony and Codeception A Beginner's Guide to Test Driven Development With Symfony and Codeception

    Have you ever been afraid of your own code? Afraid to review it? Afraid to present it to clients or management? Afraid to explain it because, unwittingly, you have created a digital Jekyll and Hyde?

    That used to be me once upon a time until I took testing more seriously.

    Let's be honest, testing doesn't quite have the allure of writing production code, and it isn't as glamorous as writing complex data structures and algorithms. Are you excited to write a test case for code that you “know” works?

    While this doesn't make testing any less important, it has resulted in testing often being seen as an afterthought by so many; including managers, other developers-even me!

    In addition, testing didn't help me allay my fears because, somehow, all the nasty bugs were never exposed by my test cases. Okay, it didn't help that I never went back and updated …

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