Book Image

Twilio Cookbook

By : Roger Stringer
Book Image

Twilio Cookbook

By: Roger Stringer

Overview of this book

Have you ever wanted to integrate phone features into a project you were working on? Maybe you wanted to send SMS messages to your customers about the latest sales? Maybe you want to set up a company directory with voice mail? Or maybe you want to add two factor authentication to your web sites to verify your users? Since Twilio was launched in 2007, developers have had a way to do these tasks. The power of Twilio's API is huge and lets you add any type of phone solution to your web site from 2-factor authentication for verifying your users, to setting up a company directory and a voice mail system. The possibilities are endless. "Twilio Cookbook" is your Swiss army knife for Twilio development, providing you with a number of clear step-by-step exercises. It helps you take advantage of the real power of the Twilio API, and gives you a good grounding in using it in your websites. This book looks at the Twilio API, and breaks down the mystery and confusion that surrounds adding telephone functionality to your websites. As you go through the recipes, you will learn how to take advantage of the Twilio API quickly and painlessly. You will learn how to build your own IVR system, company directory, and voicemail box, and also how to set up a 2-factor authentication system to verify users, track orders via SMS, send surveys using SMS, allow users to buy phone numbers, set up and delete sub-accounts, and check to see if a human is answering a phone call. We will also combine Twilio with other APIs to build a handy local search system such as a local business search, movie listings search, and web search. If you want to take advantage of using Twilio's API to add telephone functionality to your websites, then this book is for you. "Twilio Cookbook' will leave you with a black belt in Twilio development and enable you to integrate the API into your websites.
Table of Contents (17 chapters)
Twilio Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Preface

Phones are everywhere! From calling to texting, you use phones for your business and for personal use. Twilio provides an API that lets you combine phone calls and SMS messages with your websites.

Twilio Cookbook will get you on the fast lane to learning how to use Twilio with PHP and MySQL to add phone and SMS services to your websites; you'll also rapidly learn how to set up systems such as a company directory, PBX, a voicemail system, an order-tracking system, and finally how to set up two-factor authentication.

What this book covers

Chapter 1, Into the Frying Pan, covers what you need to know about adding two-factor authentication to a website to verify users. This chapter helps you set up a basic order-verification system, add the Click-to-Call functionality to a website, and record phone calls. We will also set up a company directory and learn how to use Twilio Client for Text-to-Speech.

Chapter 2, Now We're Cooking, begins by covering how to create usage records and then proceeds to topics such as screen calls to be actually answered by a person, buying a phone number, setting up a voicemail system, and building an emergency calling system.

Chapter 3, Conducting Surveys via SMS, builds a system that lets you add subscribers, build a survey, send surveys to subscribers, and view responses that come back.

Chapter 4, Building a Conference Calling System, shows you how to build a handy conference calling system that includes scheduling, notifying attendees, recording the conference call, joining the call from a browser or from a phone, monitoring the conference, and muting attendees.

Chapter 5, Combining Twilio with Other APIs, shows you how to use Twilio with other APIs to add features such as a local business search via text messages, a movie listings search, and a weather look-up. You'll also learn how to search Google.

Chapter 6, Sending and Receiving SMS Messages, digs into the many SMS messaging features that Twilio provides, beginning with sending messages from a website to replying to messages from a phone, sending bulk SMS messages to a list of people, SMS order tracking to check on orders, serving a group chat platform, and sending SMS messages from a phone call.

Chapter 7, Building a Reminder System, uses Twilio's SMS services to let you schedule reminders, get notifications of the reminders set, retrieve a list of reminders, cancel a reminder, and add another person to a reminder.

Chapter 8, Building an IVR System, shows you how to set up an Interactive Voice Response system, beginning with a basic phone tree, screening and recording calls, logging and reporting calls, looking up contacts on incoming calls using the HighRiseHQ API, and sending SMS messages to www.Salesforce.com contacts.

Chapter 9, Building Your Own PBX, shows you how to set up subaccounts for each of your users, letting them buy their own phone numbers, accept incoming phone calls, make outgoing phone calls, and delete their accounts.

Chapter 10, Digging into OpenVBX, takes you into the world of building plugins for the OpenVBX system, starting with a call log plugin, going into a searchable company directory, collecting payments over the phone using Stripe, tracking orders, setting up a caller ID system, and testing call flows.

What you need for this book

All you need to get started is a Twilio account, a web host, a simple text editor such as Notepad++, Emacs, or Vim, and an Internet connection.

Who this book is for

This book is for programmers who have already used PHP and MySQL in one way or another. It's for people who work with a lot of backend code and want to get up to speed with the world of Twilio. It's for people who want to use the capabilities of Twilio to let their websites handle phone calls and SMS messages.

The book is for both beginners and seasoned developers and assumes that you have some experience in PHP and MySQL already. In-depth knowledge of these applications is not necessary, however.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "Create a file called search.php in your views folder."

A block of code is set as follows:

<h3>Choose a Twilio number to buy</h3>
<?php   foreach($numbers->available_phone_numbers as $number){ ?>
  <form method="POST" action="<?=$uri?>/buy">
  <label><?php echo $number->friendly_name ?></label>
  <input type="hidden" name="PhoneNumber" value="<?php echo $number->phone_number ?>">
  <input type="hidden" name="action" value="buy" />
  <input type="submit" name="submit" value="BUY" />
  </form>
<?php   }  ?>

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "We now have a menu option under the Admin menu called Test Call Flow."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.