The <Redirect>
verb transfers control of a call to the TwiML at a different URL. All verbs after <Redirect>
are unreachable and ignored.
The <Redirect>
verb supports the following attributes that modify its behavior:
Attribute Name | Allowed Values | Default Value |
---|---|---|
method | GET , POST | POST |
The 'method' attribute takes the value GET
or POST
. This tells Twilio
whether to request the <Redirect>
URL via HTTP GET
or POST
. POST
is the default.
Use it in a <Redirect>
verb like so:
1const VoiceResponse = require('twilio').twiml.VoiceResponse;234const response = new VoiceResponse();5response.redirect({6method: 'POST'7}, 'http://pigeons.com/twiml.xml');89console.log(response.toString());
1<?xml version="1.0" encoding="UTF-8"?>2<Response>3<Redirect method="POST">http://pigeons.com/twiml.xml</Redirect>4</Response>
The "noun" of a TwiML verb is the stuff nested within the verb that's not a verb itself; it's the stuff the verb acts upon. These are the nouns for <Redirect>
:
Noun | TwiML Interpretation |
---|---|
plain text | An absolute or relative URL for a different TwiML document. |
No verbs can be nested within <Redirect>
and <Redirect>
can't be nested in any other verbs.
In this example, we have a <Redirect>
verb after a <Dial>
verb with no URL. When the <Dial>
verb finishes, the
<Redirect>
executes. <Redirect>
makes a request to http://www.foo.com/nextInstructions
and
transfers the call flow to the TwiML received in response to that request.
1const VoiceResponse = require('twilio').twiml.VoiceResponse;234const response = new VoiceResponse();5response.dial('415-123-4567');6response.redirect('http://www.foo.com/nextInstructions');78console.log(response.toString());
1<?xml version="1.0" encoding="UTF-8"?>2<Response>3<Dial>415-123-4567</Dial>4<Redirect>http://www.foo.com/nextInstructions</Redirect>5</Response>
Redirects call flow control to the TwiML at a URL relative to the current URL.
1const VoiceResponse = require('twilio').twiml.VoiceResponse;234const response = new VoiceResponse();5response.redirect('../nextInstructions');67console.log(response.toString());
1<?xml version="1.0" encoding="UTF-8"?>2<Response>3<Redirect>../nextInstructions</Redirect>4</Response>