Transfer A Call

In this example, we have a Redirect element after a Speak element. When theSpeak element finishes, the Redirect element executes, Plivo will then process the call based on the XML returned from the Redirect element.

Response

<Response>
    <Speak>Please wait while you call is being transferred.</Speak>
    <Redirect>http://foo.com/redirect/</Redirect>
</Response>

To connect the incoming call to a different number, you should return the following XML from the Redirect URL.

<Response>
    <Dial dialMusic="real">
        <Number>15671234567</Number>
    </Dial>
</Response>

Example Request

1
2
3
4
5
6
7
from plivo import plivoxml

response = plivoxml.ResponseElement()
response.add(
    plivoxml.SpeakElement('Please wait while you call is being transferred.'))
response.add(plivoxml.RedirectElement('http://foo.com/redirect/'))
print(response.to_string())
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'rubygems'
require 'plivo'

include Plivo::XML
include Plivo::Exceptions

begin
  response = Response.new

  speak_body = 'Please wait while you call is being transferred.'
  response.addSpeak(speak_body)

  redirect_url = 'https://www.foo.com/redirect/'
  response.addRedirect(redirect_url);

  xml = PlivoXML.new(response)
  puts xml.to_xml
rescue PlivoXMLError => e
  puts 'Exception: ' + e.message
end

begin
  response = Response.new

  params = {
    dialMusic: 'real'
  }
  dial = response.addDial(params)

  number = '1111111111'
  dial.addNumber(number)

  xml = PlivoXML.new(response)
  puts xml.to_xml
rescue PlivoXMLError => e
  puts 'Exception: ' + e.message
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var plivo = require('plivo');

var response = plivo.Response();

var speak_body = "Please wait while you call is being transferred.";
response.addSpeak(speak_body);

var redirect_url = "https://www.foo.com/redirect/";
response.addRedirect(redirect_url);

console.log(response.toXML());

/*
Sample Output
<Response>
    <Speak>Please wait while you call is being transferred.</Speak>
    <Redirect>https://www.foo.com/redirect/</Redirect>
</Response>
*/


/* Code to generate XML to be returned from url at
redirect_url */

var plivo = require('plivo');

var response = plivo.Response();

var params = {
        'dialMusic': "real"
};
var dial = response.addDial(params);

var number = "1111111111";
dial.addNumber(number);

console.log(response.toXML());

/*
Sample Output
<Response>
    <Dial dialMusic="real">
        <Number>1111111111</Number>
    </Dial>
</Response>
*/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
    require '../vendor/autoload.php';
    use Plivo\XML\Response;

    $response = new Response();

    $speak_body = "Please wait while you call is being transferred.";

    $response->addSpeak($speak_body);

    $redirect_url = "https://www.foo.com/redirect/";
    $response->addRedirect($redirect_url);

    Header('Content-type: text/xml');
    echo($response->toXML());

    /*
    Sample Output

    <Response>
        <Speak>Please wait while you call is being transferred.</Speak>
        <Redirect>https://www.foo.com/redirect/</Redirect>
    </Response>
    */
?>

<?php
    /* XML to be returned by the redirect URL */

    require '../vendor/autoload.php';
    use Plivo\XML\Response;

    $response = new Response();

    $params = array(
        'dialMusic' => "real"
    );

    $dial = $response->addDial($params);

    $number = "1111111111";
    $dial->addNumber($number);

    Header('Content-type: text/xml');
    echo($response->toXML());

    /*
    Sample Output

    <Response>
        <Dial dialMusic="real">
            <Number>1111111111</Number>
        </Dial>
    </Response>
    */
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Example for xml - transfer a call
package com.plivo.api.xml.samples.xml;

import com.plivo.api.exceptions.PlivoXmlException;
import com.plivo.api.xml.Redirect;
import com.plivo.api.xml.Response;
import com.plivo.api.xml.Speak;


class TransferACall {
    public static void main(String[] args) throws PlivoXmlException {
        Response response = new Response()
                .children(


                        new Speak("Your call is being transferred."),


                        new Redirect("http://foo.com/redirect")

                );
        System.out.println(response.toXmlString());
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Collections.Generic;
using Plivo.XML;

namespace Plivo
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			Plivo.XML.Response resp = new Plivo.XML.Response();
			resp.AddSpeak("Your call is being transferred.", 
             new Dictionary<string, string>() { });
			resp.AddRedirect("http://foo.com/redirect/", 
             new Dictionary<string, string>() { });
			var output = resp.ToString();
			Console.WriteLine(output);

		}
	}
}



//<Response>
//  <Speak>You call is being transferred.</Speak>
//  <Redirect>http://foo.com/redirect/</Redirect>
//</Response>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Example for xml - transfer call
package main

import "github.com/plivo/plivo-go/xml"


func main() {
	response := xml.ResponseElement{
		Contents: []interface{} {
			


			new(xml.SpeakElement).
			SetContents("Your call is being transferred."),

			


			new(xml.RedirectElement).
			SetContents("http://foo.com/redirect"),

		},
	}
	print(response.String())
}