Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

TwiML™ Voice: <Number>


<Number> is a noun for the TwiML verb <Dial> and it specifies a phone number to dial. Using the noun's attributes you can specify particular behaviors that Twilio should apply when dialing the number.

You can use up to ten <Number> nouns within a <Dial> verb to simultaneously call all of them at once. The first call to pick up is connected to the current call and the rest are hung up. For each <Number> noun you can specify what call progress events you want to receive webhooks for.


Noun Attributes

attributes page anchor

The <Number> noun supports the following attributes that modify its behavior:

Attribute NameAllowed ValuesDefault Value
sendDigitsAny digitsNone
urlRelative or absolute URLNone
methodGET, POSTPOST
byocBYOC Trunk SIDNone
statusCallbackEventinitiated, ringing, answered, completedcompleted
statusCallbackAny URLNone
statusCallbackMethodGET, POSTPOST
machineDetectionEnable, DetectMessageEndNone
machineDetectionTimeout3-6030
machineDetectionSpeechThreshold1000-60002400
machineDetectionSpeechEndThreshold500-50001200
machineDetectionSilenceTimeout2000-100005000
amdStatusCallbackAny URLNone
amdStatusCallbackMethodGET, POSTPOST

Phone numbers should be formatted with a + and country code, for example: +16175551212 ([E.164][1] format). Twilio will also accept unformatted US numbers, e.g., (415) 555-1212 or 415-555-1212.

sendDigits

attributes-senddigits page anchor

The sendDigits attribute tells Twilio to play DTMF tones when the call is answered. This is useful when dialing a phone number and an extension. Twilio will dial the number, and when the automated system picks up, send the DTMF tones to connect to the extension.

The url attribute allows you to specify a URL that will return a TwiML response to be run on the called party's end, after they answer, but before the parties are connected.

You can use this TwiML to privately <Play> or <Say> information to the called party. You could also provide a chance to decline the phone call using <Gather> and <Hangup>. The url attribute does not support any other TwiML verbs.

If the [answerOnBridge][dial-answer-on-bridge] attribute is used on <Dial>, the current caller will continue to hear ringing while the TwiML document executes on the other end. TwiML documents executed in this manner are not allowed to contain the <Dial> verb.

The method attribute allows you to specify which HTTP method Twilio should use when requesting the URL in the url attribute. The default is POST.

The byoc attribute allows you to specify which configured customer [BYOC Trunk][bring-your-own-carrier] Twilio should use to route the call to the PSTN. The default is none, in which case the call will be routed via the Twilio Super Network.

When dialing out to a number using <Dial>, an outbound call is initiated. The call transitions from the initiated state to the ringing state when the phone starts ringing. It transitions to the answered state when the call is picked up, and finally to the completed state when the call is over.

With statusCallbackEvent, you can subscribe to receive webhooks for the different call progress events for a given call: initiated, ringing, answered, or completed. Non-relative URLs must contain a valid hostname (underscores are not permitted).

The statusCallbackEvent attribute allows you to specify which events Twilio should trigger a webhook on. To specify multiple events separate them with a space: initiated ringing answered completed. If a statusCallback is provided and no status callback events are specified, the completed event will be sent by default.

As opposed to creating an outbound call via the API, outbound calls created using <Dial> are initiated right away and never queued. The following shows a timeline of possible call events that can be returned and the different call statuses that a <Dial> leg may experience:

Outbound Dial call events diagram.
Node.js
Python
C#
Java
PHP
Ruby

_10
const VoiceResponse = require('twilio').twiml.VoiceResponse;
_10
_10
_10
const response = new VoiceResponse();
_10
const dial = response.dial();
_10
dial.number({
_10
sendDigits: 'wwww1928'
_10
}, '415-123-4567');
_10
_10
console.log(response.toString());

Output

_10
<?xml version="1.0" encoding="UTF-8"?>
_10
<Response>
_10
<Dial>
_10
<Number sendDigits="wwww1928">
_10
415-123-4567
_10
</Number>
_10
</Dial>
_10
</Response>

Example 2: Simultaneous Dialing

examples-2 page anchor

In this case, we use several <Number> tags to dial three phone numbers at the same time. The first of these calls to answer will be connected to the current caller, while the rest of the connection attempts are canceled.

Node.js
Python
C#
Java
PHP
Ruby

_10
const VoiceResponse = require('twilio').twiml.VoiceResponse;
_10
_10
_10
const response = new VoiceResponse();
_10
const dial = response.dial();
_10
dial.number('858-987-6543');
_10
dial.number('415-123-4567');
_10
dial.number('619-765-4321');
_10
_10
console.log(response.toString());

Output

_14
<?xml version="1.0" encoding="UTF-8"?>
_14
<Response>
_14
<Dial>
_14
<Number>
_14
858-987-6543
_14
</Number>
_14
<Number>
_14
415-123-4567
_14
</Number>
_14
<Number>
_14
619-765-4321
_14
</Number>
_14
</Dial>
_14
</Response>

Example 3: Call Progress Events

examples-3 page anchor

In this case, we want to receive a webhook for each call progress event when dialing a number using <Dial>.

Node.js
Python
C#
Java
PHP
Ruby

_12
const VoiceResponse = require('twilio').twiml.VoiceResponse;
_12
_12
_12
const response = new VoiceResponse();
_12
const dial = response.dial();
_12
dial.number({
_12
statusCallbackEvent: 'initiated ringing answered completed',
_12
statusCallback: 'https://myapp.com/calls/events',
_12
statusCallbackMethod: 'POST'
_12
}, '+12349013030');
_12
_12
console.log(response.toString());

Output

_11
<?xml version="1.0" encoding="UTF-8"?>
_11
<Response>
_11
<Dial>
_11
<Number
_11
statusCallbackEvent="initiated ringing answered completed"
_11
statusCallback="https://myapp.com/calls/events"
_11
statusCallbackMethod="POST">
_11
+12349013030
_11
</Number>
_11
</Dial>
_11
</Response>

Example 4: Multi Dial with Call Progress Events

example-4-multi-dial-with-call-progress-events page anchor

In this case, we want to receive a webhook for each call progress event for each number when dialing multiple numbers using <Dial>.

Multi Dial with Call Progress Events

multi-dial-with-call-progress-events page anchor
Node.js
Python
C#
Java
PHP
Ruby

_17
const VoiceResponse = require('twilio').twiml.VoiceResponse;
_17
_17
_17
const response = new VoiceResponse();
_17
const dial = response.dial();
_17
dial.number({
_17
statusCallbackEvent: 'initiated ringing answered completed',
_17
statusCallback: 'https://myapp.com/calls/events',
_17
statusCallbackMethod: 'POST'
_17
}, '+14155555555');
_17
dial.number({
_17
statusCallbackEvent: 'initiated ringing answered completed',
_17
statusCallback: 'https://example.com/events',
_17
statusCallbackMethod: 'POST'
_17
}, '+14153333333');
_17
_17
console.log(response.toString());

Output

_17
<?xml version="1.0" encoding="UTF-8"?>
_17
<Response>
_17
<Dial>
_17
<Number
_17
statusCallbackEvent='initiated ringing answered completed'
_17
statusCallback='https://myapp.com/calls/events'
_17
statusCallbackMethod='POST'>
_17
+14155555555
_17
</Number>
_17
<Number
_17
statusCallbackEvent='initiated ringing answered completed'
_17
statusCallback='https://example.com/events'
_17
statusCallbackMethod='POST'>
_17
+14153333333
_17
</Number>
_17
</Dial>
_17
</Response>

Example 5: Running TwiML Before Parties Are Connected

example-5-running-twiml-before-parties-are-connected page anchor

In this case, we want to connect two parties using <Dial>, but we also want TwiML instructions to be sent to the party we are calling before they are connected to the call. By setting the url attribute, we can specify a URL that will return a TwiML response to be run on the called party's end. This TwiML will run after they answer, but before the parties are connected.

Running TwiML before parties are connected

running-twiml-before-parties-are-connected page anchor
Node.js
Python
C#
Java
PHP
Ruby

_10
const VoiceResponse = require('twilio').twiml.VoiceResponse;
_10
_10
const response = new VoiceResponse();
_10
const dial = response.dial();
_10
dial.number({
_10
url: 'http://example.com/agent_screen_call'
_10
}, '415-123-4567');
_10
_10
console.log(response.toString());

Output

_10
<?xml version="1.0" encoding="UTF-8"?>
_10
<Response>
_10
<Dial>
_10
<Number url="http://example.com/agent_screen_call">415-123-4567</Number>
_10
</Dial>
_10
</Response>


Hints and Advanced Uses

hints page anchor
  • You can specify up to ten numbers within a <Dial> verb to dial simultaneously.
  • Simultaneous dialing is useful when you have several phones (or several people) that you want to ring when you receive an incoming call. Keep in mind that the first call that connects will cancel all the other attempts. If you dial an office phone system or a cellphone in airplane mode, it may pick up after a single ring, preventing the other phone numbers from ringing long enough for a human ever to answer. So you should take care to use simultaneous dialing only in situations where you know the behavior of the called parties.

Rate this page: