Latest Legacy

Transfer a call

In this example, we have a Redirect element after a Speak element. When the Speak element finishes, the Redirect element executes, and Plivo processes the call based on the XML returned from the Redirect element.

Response

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

 

To connect the incoming call to a different number, you should return the section example’s XML from the Redirect URL.

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

Example Request

1
2
3
4
5
6
7
from plivo import plivoxml

response = plivoxml.ResponseElement()
response.add(
    plivoxml.SpeakElement('Your call is being transferred.'))
response.add(plivoxml.RedirectElement('https://<yourdomain>.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
require 'rubygems'
require 'plivo'

include Plivo::XML
include Plivo::Exceptions

begin
  response = Response.new

  speak_body = 'Your call is being transferred.'
  response.addSpeak(speak_body)

  redirect_url = 'https://<yourdomain>.com/redirect/'
  response.addRedirect(redirect_url);

  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
var plivo = require('plivo');

var response = plivo.Response();

var speak_body = "Your call is being transferred.";
response.addSpeak(speak_body);

var redirect_url = "https://<yourdomain>.com/redirect/";
response.addRedirect(redirect_url);

console.log(response.toXML());

/*
Sample Output
<Response>
    <Speak>Your call is being transferred.</Speak>
    <Redirect>https://<yourdomain>.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
<?php
    require '../vendor/autoload.php';
    use Plivo\XML\Response;

    $response = new Response();

    $speak_body = "Your call is being transferred.";

    $response->addSpeak($speak_body);

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

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

    /*
    Sample Output

    <Response>
        <Speak>Your call is being transferred.</Speak>
        <Redirect>https://<yourdomain>.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
// 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("https://<yourdomain>.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("https://<yourdomain>.com/redirect/", 
             new Dictionary<string, string>() { });
			var output = resp.ToString();
			Console.WriteLine(output);

		}
	}
}



//<Response>
//  <Speak>You call is being transferred.</Speak>
//  <Redirect>https://<yourdomain>.com/redirect/</Redirect>
//</Response>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Example for xml - transfer call
package main

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

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

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

			new(xml.RedirectElement).
				SetContents("https://<yourdomain>.com/redirect/"),
		},
	}
	print(response.String())
}