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.
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.
https://www.example.com/twiml
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.
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:
_10https://example.com/myfunction?Digits={{widgets.MY_WIDGET_NAME.Digits}}
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&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}}
.
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.
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:
Name | Description | Possible Values | Default |
---|---|---|---|
Method | The HTTP method Twilio should use when accessing your redirect URL | POST, GET | POST |
Timeout | The 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 |
These events trigger transitions from this Widget to another Widget in your Flow. For more information on working with Studio transitions, see this guide.
Name | Description |
---|---|
Return | Control has been returned to Studio by Twilio Voice or Messaging TwiML by appending the parameter FlowEvent=return to your TwiML redirect URL |
Timeout | The timeout timer expired and control has not passed back to Studio via the FlowEvent=return parameter |
Failed | The 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) |
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.
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.