VoiceML

VoiceML: <Redirect>

On this page
  1. Attributes
  2. Body
  3. Failover
  4. Examples
  5. Example 1: Transfer control to a different handler
  6. Example 2: Transfer control with a backup handler
  7. Tips and Tricks

The <Redirect> action transfers control of the call to another URI.

Attributes

The <Redirect> action does not support any attributes.

Body

The body of an action is the content nested within the action. The following is supported for <Redirect>.

You can use plain text to transfer control to a single URI. For example:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect>https://example.com/handler</Redirect>
</Response>

Alternatively, you can specify one or more <Uri> elements. The following example is equivalent to the previous plain text example.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect>
        <Uri>https://example.com/handler</Uri>
    </Redirect>
</Response>

Using this syntax, you can specify more than one URI. Each <Uri> contains a relative or absolute URI, and takes no attributes. A <Redirect> can have up to 5 <Uri> elements. You can't mix plain text and <Uri> elements in the same <Redirect>.

Failover

When a <Redirect> has more than one URI, Enfonica tries each one once, in order, and stops at the first that succeeds. A phone number's handler URIs fail over the same way: see Failure handling.

Enfonica tries the next URI only if the one before it fails:

  • For http and https URIs, a failure is a non-2xx response, a network error, or no response within 10 seconds. A 2xx response that isn't valid VoiceML isn't a failure: the call ends with an error, and Enfonica doesn't try the next URI.
  • For tel and sip URIs, a failure is a call attempt that fails (a callStatus of FAILED, see <Call>). Busy and no answer aren't failures.

If every URI fails, the call ends.

Relative URIs are resolved against the URI of the current VoiceML document.

Examples

Example 1: Transfer control to a different handler

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect>different-handler.php</Redirect>
</Response>

Example 2: Transfer control with a backup handler

If https://example.com/handler fails, Enfonica requests https://backup.example.net/handler.

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Redirect>
        <Uri>https://example.com/handler</Uri>
        <Uri>https://backup.example.net/handler</Uri>
    </Redirect>
</Response>

Tips and Tricks

  • In addition to http and https URIs, you may also redirect to tel and sip URIs. This behaves the same as using the <Call> action and can be useful in certain use-cases.
  • The relative URIs example and ./example behave the same way. If you are using a colon towards the start of a relative URI (eg my:uri), you may encounter an invalid scheme error. To disambiguate your relative URI, add the ./ prefix (eg ./my:uri).
  • Make sure your URL is properly XML serialized (eg & should be serialized as &amp;).