Custom Caller Tone
When you make an outbound call and then connect that call to a different number using Dial element, you can play a custom caller tone using thedialMusic attribute.
Plivo will request the dialMusic
URL using the POST HTTP method for a valid Play, Speak or a Wait XML.
To play a message on the call while its being connected, you should return the second XML as shown.
Response
<Response>
<Dial dialMusic="http://foo.com/dial_music/">
<Number>15671234567</Number>
</Dial>
</Response>
Return the following 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='http://foo.com/dial_music/').add(
plivoxml.NumberElement('15671234567')))
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://www.foo.com/dial_music/"
}
dial = response.addDial(params)
first_number = "1111111111"
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://www.foo.com/dial_music/"
};
var dial = response.addDial(params);
var first_number = "1111111111";
dial.addNumber(first_number);
console.log(response.toXML());
/*
Sample Output
<Response>
<Dial dialMusic="https://www.foo.com/dial_music/">
<Number>1111111111</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://www.foo.com/dial_music/"
);
$dial = $response->addDial($params);
$number = "1111111111";
$dial->addNumber($number);
Header('Content-type: text/xml');
echo($response->toXML());
/*
Sample Output
<Response>
<Dial dialMusic="https://www.foo.com/dial_music/">
<Number>1111111111</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("http://foo.com/dial_music/")
.children(
new Number("15671234567")
)
);
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", "http://foo.com/dial_music/"}
});
dial.AddNumber("15551234567",
new Dictionary<string, string>() { });
resp.Add(dial);
var output = resp.ToString();
Console.WriteLine(output);
}
}
}
//<Response>
// <Dial dialMusic = "http://foo.com/dial_music/" >
// < Number > 15551234567 </ 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/xml"
func main() {
response := xml.ResponseElement{
Contents: []interface{}{
new(xml.DialElement).
SetDialMusic("http://foo.com/dial_music/").
SetContents(
[]interface{}{
new(xml.NumberElement).
SetContents("15671234567"),
},
),
},
}
print(response.String())
}
Rate this page
🥳 Thank you! It means a lot to us!
×
Help Us Improve
Thank you so much for rating the page, we would like to get your input for further improvements!
Subscribe to Updates
Thank you for your feedback!