The Programmable Voice Guide is jam packed with volumes of amazing information about Twilio Programmable Voice. In this post I’m going to introduce you to three topics that are personal favorites:
Phone calls don’t have to be a one-way conversation and the Guide can show you how. By using the
<Gather> TwiML verb you can have Twilio listen for a caller to press the buttons on their phone’s dial pad and report which buttons they pressed via a webhook request.
<?xml version="1.0" encoding="UTF-8"?> <!— page located at http://example.com/complex_gather.xml —> <Response> <Gather action="/process_gather.php" method="GET"> <Say> Please enter your account number, followed by the pound sign </Say> </Gather> <Say>We didn't receive any input. Goodbye!</Say> </Response>
Your application can generate new TwiML commands based on the button press info to create a dynamic experience for each caller. For example, using
<Gather> you can create selection menus a caller can use to navigate to different functions in your app (called an “IVR” or “Phone Tree”) or accept information such as a passcode or account number.
Ask my wife, I forget stuff all the time. Honestly, most days I can’t remember what I had for breakfast so I’ve learned to write down everything. Of course, I also forget to bring along pen and paper. That’s where the
<Record> TwiML verb comes to your rescue. The Voice Guide shows you how to record a phone call until a number of seconds pass or a key on the dial pad is pressed.
<?xml version="1.0" encoding="UTF-8"?> <!— page located at http://example.com/voicemail_record.xml —> <Response> <Say> Please leave a message at the beep. Press the star key when finished. </Say> <Record action="http://example.com/handleRecording.php" method="GET" maxLength="20" finishOnKey="*" /> </Response>
When the recording is done Twilio lets your app know by making a webhook request so you can download the audio and store it for later playback. Voice notes are just one way that you can use
<Record>. Create a custom voicemail system, allow customers to leave product feedback or record customer support calls as part of a training program.
Modify an In-progress Call
You’ve dropped a caller into a
<Conference> so your agent can chat with them but once that conversation is done, then what? Did the service the agent provided meet your standards? Before the caller hangs up why not ask them to give you some feedback.
Moving the caller to this different experience means telling Twilio that you have a URL with new TwiML that you want it to execute. This is done using the REST API, and it’s really easy to do when you the Twilio Ruby helper library and follow the Modify Calls In Progress with Ruby guide.
# Get twilio-ruby from twilio.com/docs/ruby/install require 'rubygems' # This line not needed for ruby > 1.8 require 'twilio-ruby' # Get your Account Sid and Auth Token from twilio.com/user/account account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' auth_token = 'your_auth_token' @client = Twilio::REST::Client.new account_sid, auth_token # Get an object from its sid. If you do not have a sid, # check out the list resource examples on this page @call = @client.account.calls.get("CAe1644a7eed5088b159577c5802d8be38") @call.update(:url => "http://demo.twilio.com/docs/voice.xml", :method => "POST") puts @call.to
Notice that the code uses a Call Sid to get a reference to a specific Call, then updates the
url parameter if that Call. Twilio will immediately make a
POST request to that URL letting your application give Twilio some different TwiML to execute for the caller.
Wrapping it up
The Programmable Voice Quickstart gives you that first taste of making your phone ring and does it fast. The Programmable Voice Guides pick up where the quickstart leaves off, getting you moving towards your bigger goal whether that’s an advanced IVR, custom voicemail system or entire call center.
Programmable Voice not your thing? That’s OK, give the Programmable SMS guide a spin and keep your eye out for more guides coming soon!
I’m stoked to see what your building and to hear how Guides helped you get there. Drop me a line via Twitter and let me know how it’s going.