Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Twilio Best Practices

You're reading from   Twilio Best Practices Learn how to build powerful real-time voice and SMS applications with Twilio

Arrow left icon
Product type Paperback
Published in Dec 2014
Publisher
ISBN-13 9781782175896
Length 178 pages
Edition 1st Edition
Tools
Arrow right icon
Toc

Table of Contents (10) Chapters Close

Digging deeper – Twilio's requests

In the preceding example, you've seen that Twilio includes some helpful data in its request when it hits your server to fetch the TwiML it needs in order to handle an incoming call or message.

We pulled out the country where the caller is located, which is stored in the FromCountry parameter. We grabbed this in PHP using $_GET, but you can do the same in any web language.

Alongside the caller's location, Twilio includes a whole lot of useful information.

Here are the highlights:

Parameter

What it means

CallSid/MessageSid

This refers to the unique reference for this call or message, as appropriate.

This can be particularly useful to store in a database if you might want to look up this call using the REST API later.

From

This refers to the caller's phone number in the international format (for example, +, then the country code, and then the local number).

To

This tells you which of your Twilio phone numbers is being dialed in the international format, as described previously.

CallStatus

This tells you about the current status of the call, which may be queued, ringing, in-progress, completed, busy, failed or no-answer.

ApiVersion

This refers to the Twilio API version being used for this call; you can safely ignore this parameter.

Direction

This refers to the direction—or in some sense, the type—of call in progress. This will be inbound for incoming calls, outbound-api for calls initiated with the REST API (we'll learn more about this in Chapter 2, Exploring REST API) and outbound-dial for calls initiated from the TwiML <Dial> verb.

ForwardedFrom

For some forwarded calls, this will include the number from which the call was forwarded, but this is not supported by all carriers.

CallerName

Twilio allows you to enable caller ID lookup on your phone numbers for $0.01 per lookup. If you've enabled this, this will contain the caller's name if a result was found.

From/To

City

This refers to the city where the caller/number being called is located (this will not necessarily be provided).

 

State

This refers to the state, province, or country where the caller/number being called is located (this will not necessarily be provided).

 

Zip

This refers to the zip or postal code of the caller/number being called (this will not necessarily be provided).

 

Country

This refers to the country where the caller/number being called is located.

Body

This refers to the text received in the SMS (SMS only).

This data, which Twilio provides, can help you implement a wide range of dynamic features into your TwiML, such as the following:

  • Changing how the call is handled depending on the number being called
  • Switching languages based on the location of the caller
  • Responding to what someone actually said in an SMS

Note

Further details are available in Twilio's comprehensive documentation at

https://www.twilio.com/docs/api/twiml/twilio_request

You have been reading a chapter from
Twilio Best Practices
Published in: Dec 2014
Publisher:
ISBN-13: 9781782175896
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime