Building Static Applications

Congratulations! Now that you’ve built and debugged your first Twilio application, let’s start building Twilio applications with some of the other TwiML verbs. These applications can be hosted on Twimlbin.

Call Forwarding

The Dial verb allows you to connect calls to other people. The following TwiML will forward any call received on your Twilio phone number to your personal phone number. Once you’ve wired up this TwiML to your number get a neighbor to test it out.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>Please wait while we forward your call.</Say>
  <Dial>YOUR PHONE NUMBER</Dial>
</Response>

Twilio Call Legs

Find this call in your Call Logs. You should notice two call records listed. What’s the difference between the two call records?

Direction
For applications like Call Forwarding, your call will include two call legs. The inbound call leg noted under Incoming is the call made into Twilio. The outbound call leg noted under Outgoing Dial is the call made from Twilio with the Dial verb out to another phone number. Call Forwarding applications include both an inbound leg and an outbound leg.
Cost
The cost of inbound and outbound calls are different. Inbound calls cost 1¢ per minute while outbound calls start at 2¢ per minute. The cost of outbound calls may also differ depending on the end destination of your outbound call. See the Voice Pricing page for more pricing information.
To
While the “From” phone numbers are the same, the “To” phone number are different based on the phone number receiving your call.

Introducing Attributes

Each TwiML verb and noun has a set of attributes that allow you to modify its behavior. Let’s change our robot voice to a female voice by adding the voice attribute and setting it to “woman” like so, <Say voice="woman">. Additionally, let’s record our call by including the record attribute and mark that as “true”, <Dial record="true".

For our last call, the caller ID displayed was the phone number where the call originated from. Let’s change your caller ID using the callerId attribute so that it displays your Twilio phone number instead, <Dial callerId="YOUR TWILIO PHONE NUMBER">.

Earlier we verified your personal phone number so you may also use that as your caller ID. To use other phone numbers as your caller ID you can verify those numbers in your Twilio Account.

Test out the following code and see how the attributes have changed your application.

 <?xml version="1.0" encoding="UTF-8"?>
 <Response>
   <Say voice="woman">Please wait while we forward your call</Say>
   <Dial record="true" callerId="YOUR TWILIO PHONE NUMBER">
     YOUR PHONE NUMBER
   </Dial>
 </Response>

Now try out some the Say verb and Dial verb attributes and see what they do.

Voice Mailbox

Recording audio is accomplished through the Record verb. The Record verb will play a beep and wait until a user presses # or hangs up. While the record attribute used earlier will record both sides of the conversation, the Record verb is used to record just the inbound call leg. Copy this TwiML into your bin and save. You can now leave messages on your number.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>After the beep, record your message</Say>
  <Record/>
</Response>

After you’re done recording your message hang up. Twilio begins processing the recording right after your done. Head to your recordings log to listen to your message.

To delete your recording through the User Interface, click on the date of the recording. There’s a “Delete Recording” link at the bottom right hand corner.

_images/recording.png

Transcriptions of your recordings can also be made by Twilio with the transcribe attribute.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>After the beep, record your message</Say>
  <Record transcribe="true"/>
</Response>

Rerecord your message. This time, record a longer message.

Head over to your transcription log to see your transcription and listen to your message.

Private Conference Line

Many times during project collaboration, you just need to get everyone on the same page. You can now have your own private conference line using the Conference noun and Dial verb. Put the following TwiML into your bin and save.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Dial>
    <Conference>vip</Conference>
  </Dial>
</Response>

Now, you can give your Twilio number to a few people around you, have everyone call in, and start up a conversation.

One Song Music Hotline

To play an audio file back to the caller, use the Play verb. We can build a simple music hotline that just plays just one song to the caller.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>You are about to listen to Flight of Young Hearts by Mellotroniac.</Say>
  <Play>http://com.twilio.music.classical.s3.amazonaws.com/Mellotroniac_-_Flight_Of_Young_Hearts_Flute.mp3</Play>
</Response>

SMS Follow-Up

Using the Sms verb you can send SMS messages right after your call has ended.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say>I have received your call.</Say>
  <Sms>Thank you for calling.</Sms>
</Response>

That was easy!

Swiss-Army Phone Number

Equipped with the knowledge of TwiML, you can now bend your Twilio phone number to your will. You’ve forwarded a call, recorded a message, and started a private conference line. Your phone is now yours to control.

But with this many applications, we definitely want more than one Twilio phone number. Let’s purchase another number.

To purchase a Twilio phone number you will want to navigate to the Numbers tab. Click on the blue button titled Buy a number.

_images/buy_number.png

You may search for the Twilio phone number you would like to purchase by area code, digits, and phrases as well as by the location.