TwiMLTM Voice: Your Response

When a phone call comes in to one of your Twilio numbers, Twilio makes an HTTP request to the URL configured for that number. In your response to that request you can tell Twilio what to do on the call.

Twilio Is a Well Behaved HTTP Client

Twilio behaves just like a web browser when making HTTP requests to URLs:


Twilio Understands MIME Types

Twilio does the right thing when your application responds with different MIME types:

MIME TypeBehavior
text/xml, application/xml, text/htmlTwilio interprets the returned document as an XML Instruction Set (which we like to call TwiML). See the TwiML Interpreter section for details. This is the most commonly used response.
various audio typesTwilio plays the audio file to the caller, and then hangs up. See the <Play> documentation for supported MIME types.
text/plainTwilio reads the content of the text out loud to the caller, and then hangs up.

Twilio's TwiML Interpreter


The interpreter starts at the top of your TwiML document and executes instructions ("verbs") in order from top to bottom. As an example, the following TwiML snippet reads "Hello World" to the caller before playing Cowbell.mp3 for the caller and then hanging up.

    <Say>Hello World</Say>

TwiML elements ("verbs" and "nouns") have case-sensitive names. For example, using <say> instead of <Say> will result in an error. Attribute names are also case sensitive and "camelCased." And you can use XML comments freely; the interpreter ignores them.

The <Response> Element



TwiML Verbs

Most XML elements in a TwiML document are TwiML verbs. Verb names are case sensitive, as are their attribute names. There are only six core TwiML Voice verbs and four secondary verbs, with detailed documentation on each. The six core verbs are:

  • <Say>: Read some text to the caller.
  • <Play>: Play an audio file to the caller.
  • <Record>: Record a call or part of a call.
  • <Gather>: Get the digits a caller presses.
  • <Dial>: Call another phone number or conference and connect the current caller.
  • <Sms>: Send an SMS message during a call.

Note that there are certain situations when the TwiML interpreter may not reach verbs in a TwiML document because control flow has passed to a different document. This usually happens when a verb's 'action' attribute is set. For example, if a <Say> verb is followed by a <Sms> and then another <Say>, the 2nd <Say> is unreachable if the <Sms> verb's 'action' URL is set. In this case, call flow continues with the TwiML received in your response to the 'action' URL request.

The following verbs may impact control flow: <Gather>, <Record>, <Dial>, <Sms>, <Redirect>, <Hangup> and <Reject>.

TwiML Nouns

A Noun in TwiML is anything nested inside a verb that is not itself a verb. It's whatever the verb is acting on. This is usually just text. But sometimes, as in the case of <Dial> with its <Number> and <Conference> nouns, there are nested XML elements that are nouns.