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

TwiML Redirect Widget


Studio uses Widgets to represent various parts of Twilio's functionality that can then be stitched together in your Studio Flow to build out robust applications that require no coding on your part.

(information)

Info

New to Twilio Studio? Check out our Getting Started Guide!

The TwiML Redirect Widget allows you to redirect a call or message to TwiML hosted somewhere other than your Studio Flow and, optionally, return control of the call back to Studio after the TwiML you redirect to is complete.

A TwiML Redirect widget: a rectangular box with a title 'redirectTwiML (Add TwiML Redirect)', a URL listed below the title, and handlers for return, timed, and failed.https://www.example.com/twimlNone

Note: Studio does not actually make the HTTP request to this URL. Instead, Studio prints the TwiML, which instructs Twilio Voice or Messaging to make a new request to the URL you specify.

How to pass parameters to a TwiML Redirect URL

how-to-pass-parameters-to-a-twiml-redirect-url page anchor

If you want to pass parameters to a TwiML Redirect URL from your Studio Flow, you can pass them in a query string as part of your URL.

For example, if you want to pass the Digits variable from the Gather Input on Call Widget, you should enter the following in the URL field for the TwiML Redirect widget:


_10
https://example.com/myfunction?Digits={{widgets.MY_WIDGET_NAME.Digits}}

How to return control to Studio

how-to-return-control-to-studio page anchor

To return control of the call or message to Studio, you must specify a <Redirect> to your Studio Webhook URL and append ?FlowEvent=return. Studio will inject any additional parameters specified in the return URL to your Studio context. These parameters will then be available in your Studio Flow via Liquid template variables.

Example:


_10
<Response>
_10
<Say>Returning you back to the Studio Flow.</Say>
_10
<Redirect>https://webhooks.twilio.com/v1/Accounts/{AccountSid}/Flows/{FlowSid}?FlowEvent=return&amp;foo=bar</Redirect>
_10
</Response>

The URL parameter foo illustrated above will be passed automatically into your Flow and can be referenced via Liquid as {{widgets.your_redirect_widget_name.foo}}.

(information)

Info

To retrieve the Studio Webhook URL in your Studio flow, click the red Trigger widget. The URL starting with https://webhooks.twilio.com/v1/... is the Webhook URL for this Flow.


Optional configuration for TwiML Redirect

optional-configuration-for-twiml-redirect page anchor

The TwiML Redirect Widget accepts a few configuration options that you can use to further customize how Studio redirects to your URL that hosts TwiML, and returning control back to Studio:

NameDescriptionPossible ValuesDefault
MethodThe HTTP method Twilio should use when accessing your redirect URLPOST, GETPOST
TimeoutThe number of seconds your Studio Flow will wait for control to return to it after the redirect. If you do not wish to return control to Studio, set this value to 0.0 to 14400 seconds (4 hours)14400

TwiML Redirect Transitions

twiml-redirect-transitions page anchor

These events trigger transitions from this Widget to another Widget in your Flow. For more information on working with Studio transitions, see this guide.

NameDescription
ReturnControl has been returned to Studio by Twilio Voice or Messaging TwiML by appending the parameter FlowEvent=return to your TwiML redirect URL
TimeoutThe timeout timer expired and control has not passed back to Studio via the FlowEvent=return parameter
FailedThe URL is invalid and cannot be parsed at runtime, therefore Studio cannot complete the request. Note that the Failed state will not occur if your URL returns an error (e.g., 404, 500)

Regaining control of a Voice call

regaining-control-of-a-voice-call page anchor

Please note that your Studio Flow will not be able to regain control of a Voice call that is timed out after passing the call to your TwiML Redirect URL. The only way your Studio Flow can regain control of a Voice call that has been passed to a TwiML URL is if you first append the parameter FlowEvent=return to your URL. This will tell the TwiML that executes to return control back to Studio when execution is complete.


Example: Sending and receiving variables to and from a TwiML document

example-sending-and-receiving-variables-to-and-from-a-twiml-document page anchor

You may want to send and receive information to and from a TwiML document. This example shows a Studio Flow using the TwiML Redirect Widget to run a TwiML document hosted by Twilio's TwiML Bins.

Twilio Studio TwiML Redirect Widget Example.Rate this page:

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.