Latest Legacy

Custom caller tone

When you make an outbound call and then connect that call to a different number using the Dial element, you can play a custom caller tone using the dialMusic attribute.

Plivo requests the dialMusic URL using the POST HTTP method for a valid Play, Speak, or Wait XML element.

To play a message on a call while it’s being connected, you should return the second XML example response.

Response

<Response>
    <Dial dialMusic="https://<yourdomain>.com/dial_music/">
        <Number>12025551111</Number>
    </Dial>
</Response>

 

Return this XML to play the message

<Response>
    <Speak>Your call is being connected</Speak>
</Response>

Example Request

1
2
3
4
5
6
7
8
9
10
11
12
13
from plivo import plivoxml

response = plivoxml.ResponseElement()
response.add(
    plivoxml.DialElement(dial_music='https://<yourdomain>.com/dial_music/').add(
        plivoxml.NumberElement('12025551111')))
print(response.to_string())

# XML to play the message
play_message_response = plivoxml.ResponseElement()
play_message_response.add(
    plivoxml.SpeakElement('Your call is being connected'))
print(play_message_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
require 'rubygems'
require 'plivo'

include Plivo::XML
include Plivo::Exceptions

begin
  response = Response.new

  params = {
      'dialMusic' => "https://<yourdomain>.com/dial_music/"
  }

  dial = response.addDial(params)
  first_number = "12025551111"
  dial.addNumber(first_number)

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

begin
  response = Response.new

  speak_body = "Your call is being connected"
  response.addSpeak(speak_body)

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

var response = plivo.Response();

var params = {
    'dialMusic': "https://<yourdomain>.com/dial_music/"
};
var dial = response.addDial(params);

var first_number = "12025551111";
dial.addNumber(first_number);

console.log(response.toXML());

/*
Sample Output
<Response>
    <Dial dialMusic="https://<yourdomain>.com/dial_music/">
        <Number>12025551111</Number>
    </Dial>
</Response>
*/


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

var plivo = require('plivo');

var response = plivo.Response();

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

console.log(response.toXML());

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

    $response = new Response();

    $params = array(
        'dialMusic' => "https://<yourdomain>.com/dial_music/"
    );

    $dial = $response->addDial($params);
    $number = "12025551111";
    $dial->addNumber($number);

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

    /*
    Sample Output

    <Response>
        <Dial dialMusic="https://<yourdomain>.com/dial_music/">
            <Number>12025551111</Number>
        </Dial>
    </Response>
    */
?>

<?php
    /* XML to be returned by dialMusic */
    require '../vendor/autoload.php';
    use Plivo\XML\Response;

    $response = new Response();

    $speak_body = "Your call is being connected";
    $response->addSpeak($speak_body);

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

    /*
    Sample Output

    <Response>
        <Speak>Your call is being connected</Speak>
    </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 dial - custom caller tone
package com.plivo.api.xml.samples.dial;

import com.plivo.api.exceptions.PlivoXmlException;
import com.plivo.api.xml.Dial;
import com.plivo.api.xml.Number;
import com.plivo.api.xml.Response;


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


                        new Dial()
                                .dialMusic("https://<yourdomain>.com/dial_music/")
                                .children(
                                        new Number("12025551111")
                                )
                );
        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
29
30
31
32
33
34
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();
			Plivo.XML.Dial dial = new Plivo.XML.Dial(new
				Dictionary<string, string>() {
				{"dialMusic", "https://<yourdomain>.com/dial_music/"}
			});

			dial.AddNumber("12025551111",
				new Dictionary<string, string>() { });
			resp.Add(dial);

			var output = resp.ToString();
			Console.WriteLine(output);

		}
	}
}



//<Response>
//  <Dial dialMusic = "https://<yourdomain>.com/dial_music/" >
//    < Number >12025551111</ Number >
//  </ Dial >
//</ Response >
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Example for dial - caller tone
package main

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

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

			new(xml.DialElement).
				SetDialMusic("https://<yourdomain>.com/dial_music/").
				SetContents(
					[]interface{}{
						new(xml.NumberElement).
							SetContents("12025551111"),
					},
				),
		},
	}
	print(response.String())
}