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 | |
---|---|---|
|
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. | |
|
This refers to the caller's phone number in the international format (for example, +, then the country code, and then the local number). | |
|
This tells you which of your Twilio phone numbers is being dialed in the international format, as described previously. | |
|
This tells you about the current status of the call, which may be | |
|
This refers to the Twilio API version being used for this call; you can safely ignore this parameter. | |
|
This refers to the direction—or in some sense, the type—of call in progress. This will be | |
|
For some forwarded calls, this will include the number from which the call was forwarded, but this is not supported by all carriers. | |
|
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. | |
|
|
This refers to the city where the caller/number being called is located (this will not necessarily be provided). |
|
This refers to the state, province, or country where the caller/number being called is located (this will not necessarily be provided). | |
|
This refers to the zip or postal code of the caller/number being called (this will not necessarily be provided). | |
|
This refers to the country where the caller/number being called is located. | |
|
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