How to Win Friends & Influence Hackathon Judges with Twilio


Matt Makai | @mattmakai | makaimc on GitHub | Twilio Developer Evangelist

Twilio: Cloud Communications
diagram

twilio makes it easy for developers to add voice, SMS, and VoIP functionality into web and native mobile apps.

Your app probably has one of these:

http://myapp.com

twilio gives it one of these:

(612) 867-5309

With twilio you can:

  • Build a group chat app - GroupMe
  • End no-shows for doctor's appointments - Appointment Reminder
  • Make voice calls to a customer from your browser - Zendesk
  • Put everyone into a a group conference call

Talk is cheap!

(let's make some phones ring...)

HOLY BISCUITS

(told you it was easy)

Now it's your turn!

DOers

Doing is for DOers

  • At twilio, we celebrate the DOers
  • This workshop is for DOers
  • Code > Slides
  • Results > Theory

Challenge #1

Sending text messages (SMS)

  • Pair up
  • Create Twilio account
  • Choose your programming language
  • Send SMS to each other's phones
  • Send SMS to (202) 552-0409

Stuff you'll need to know:

  • Twilio REST API
  • Twilio Helper Libraries

The twilio REST API

  • Make phone calls
  • Send text messages
  • Get usage records
  • Buy phone numbers
  • Everything twilio can do (just about)
  • Full Docs

A cURL Request


$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/AC308ac9a994b1bd8b73ca0166442236c7/Calls.json \
    -d "Url=http://demo.twilio.com/docs/voice.xml" \
    -d "To=+14155551212" \
    -d "From=+14158675309" \
    -u 'AC308ac9a994b1bd8b73ca0166442236c7:{AuthToken}'
                    

Available Helper Libraries

Advanced topics

If we have time, or after workshop

  • Webhooks
  • TwiML
  • Where to look when things break

Webhooks

Webhooks are user-defined callbacks that allow event-driven interaction between two applications over HTTP.

  • Assume a Service and a Consumer of that Service.
  • The Consumer wants to be notified when Some Event happens inside the Service.
  • The Consumer defines a URL to be requested by the Service over HTTP when Some Event happens.

twilio provides webhooks for voice calls and text messages

  • You purchase a phone number from twilio
  • For each phone number, you specify webhooks for incoming voice calls and text messages
  • When twilio receives a phone call or SMS to your number, the URLs you specified are requested over HTTP

What does twilio tell you about incoming calls?

Your URL is sent POST or GET parameters that contain information like:

  • The number calling/texting
  • a unique ID for the call/text
  • the body of a text message
  • location information for the caller (if available)

How do you tell twilio how to handle incoming calls and texts?

TwiML

Your webhook URL should return an XML document that contains instructions for how you want to handle the call or text. The set of XML tags twilio understands is called TwiML.


<?xml version="1.0" encoding="ISO-8859-1"?>
<Response>
    <Say voice="woman">Hello, world!</Say>
</Response>
                    

What can TwiML tell twilio to do?

A small sample...

<Say> Say a string of text, using our built in text-to-speech engine
<Gather> Gather input from the user via DTMF tones (generated by pressing buttons on a standard phone).
<Dial> Dial a specific number or VoIP client, connecting the caller with that number/client.
<Sms> Send an SMS text message to the incoming caller/text-er or another number.
fail

Things don't always work out like you planned

If there is an error in your TwiML or somewhere in telecom land, check the logs. There's usually detailed information there.

Challenge #2

Kicking @$$ and Taking Orders

pizza guy
  • Use Case: Pizza Orders via SMS
  • Requirements:
    • Take (and acknowledge) order via SMS
    • Display list of orders on a web page
    • Send an SMS notification when a pizza order is on the way

Resources

Plan of Attack

  • Buy a Twilio number (or use one you already have)
  • Write a server which will handle an HTTP callback from Twilio
  • Display a web page with all orders received
  • Click an order to indicate it has been finished
  • Use the Twilio REST API (via a helper library) to send an SMS to the orderer

Wrapping Up

  • twilio wants to help you change communications forever
  • Every application has an opportunity to communicate with users better
  • Phone, voice, and SMS interactions can be every bit as valuable as interactions on a screen

We're Here To Help!

Thank You!

Matt Makai

@mattmakai

mmakai@twilio.com