Twilio: the Ultimate Communication Tool

By  on  

My favorite part of the mobile revolution was the explosion of communication tools.  I grew up chatting on AOL Instant Messenger, MSN Messenger, and other desktop messaging tools, so when mobile phones took on text messaging, I was hyped for a new generation of mobile communication possibilities.  Today we get push notifications and have dedicated communication apps like WhatsApp, Facebook Messenger, etc -- wow, life has changed!  If I wanted to optimize my reach to users, I'd want a service that could accommodate as many communication avenues as possible.  That's why Twilio is such a success: a progressive, flexible, all-encompassing service that allows you to reach your users in a variety of formats!

Quick Hits

  • Twilio provides world class APIs and infrastructure for communicating over SMS, WhatsApp, Facebook messenger, and more
  • Provides an easy XML-like language, TwiML, to respond to received SMS messages
  • Twilio provides an API and helper libraries for numerous languages: PHP, Node.js, and more
  • Twilio provides dozens of easy to understand tutorials
  • Create SMS chat bots and interactive voice responders with their visual builder or with easy to use APIs
  • Use Twilio to manage two factor authentication
  • Create programmable video:  build in-app voice and video with cloud infrastructure and powerful SDKs;  everything you need to build with WebRTC.
  • Used by Twitch, Zendesk, eBay, Trulia, Lyft, and more

Basic Setup

You can sign up for a free account at Twilio so you can get a feel for the service.  Once you sign up, Twilio provides you a console which acts as a starting block for all of the "project" types you can create with Twilio.  In most cases, you'll need a Twilio phone number, which Twilio provides to you readily.  With each project, you'll generate an auth token that you'll use within your API.

Sending SMS Messages with Twilio

Sending a text message to your user or customer, whether it be an appointment reminder, a sales receipt, or authentication, is incredibly useful; what's awesome from a developer perspective is that Twilio makes it so easy to do:

const accountSid = 'XXXXXX';
const authToken = 'XXXXXX';
const client = require('twilio')(accountSid, authToken);

client.messages
  .create({
     body: 'David Walsh Blog rules!',
     from: '+16088889069',
     to: '+16088675309'
   })
  .done();

The result is just as you'd hope for:

A clean text message just as you'd directed Twilio to send!

Making a Phone Call with Twilio

If you want to go a step further and have Twilio act as a dialer, the API is just as easy for making a simple phone call:

const accountSid = 'XXXXXX';
const authToken = 'XXXXXX';
const client = require('twilio')(accountSid, authToken);

client.calls
  .create({
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: '+16088675309',
    from: '+16088889069'
  });

Within three seconds my phone was ringing as expected!  Twilio makes the developer experience so easy.

Recording Phone Calls

Using Twilio as an answering machine is another simple task you can code Twilio with:

const express = require('express');
const VoiceResponse = require('twilio').twiml.VoiceResponse;

const app = express();

// Returns TwiML which prompts the caller to record a message
app.post('/record', (request, response) => {
  // Use the Twilio Node.js SDK to build an XML response
  const twiml = new VoiceResponse();
  twiml.say('Hello. Please leave a message after the beep.');

  // Use  to record the caller's message
  twiml.record();

  // End the call with 
  twiml.hangup();

  // Render the response as XML in reply to the webhook request
  response.type('text/xml');
  response.send(twiml.toString());
});

// Create an HTTP server and listen for requests on port 3000
app.listen(3000);

Twilio's Voice API is remarkable and, what's even better, is incredibly easy to use as a developer and the eventual recipient of the message.

Twilio's reputation as an industry leader in communications, from fax to SMS to voice onto video, is well earned.  Their communication capabilities make life easy for the developer, the end user, and the intermediaries managing the communications!

Recent Features

Incredible Demos

  • By
    Redacted Font

    Back when I created client websites, one of the many things that frustrated me was the initial design handoff.  It would always go like this: Work hard to incorporate client's ideas, dream up awesome design. Create said design, using Lorem Ipsum text Send initial design concept to the client...

  • By
    MooTools FontChecker Plugin

    There's a very interesting piece of code on Google Code called FontAvailable which does a jQuery-based JavaScript check on a string to check whether or not your system has a specific font based upon its output width. I've ported this functionality to MooTools. The MooTools...

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!