Sequential dialing
This example calls out to two phone numbers sequentially. The first call is made to a number with a timeout value of 20 seconds. If the call is not answered within that time, Plivo will dial out to the second number.
Response
<Response>
<Dial timeout= "20" action= "https://<yourdomain>.com/dial_action/" >
<Number> 12025551111</Number>
</Dial>
<Dial>
<Number> 12025552222</Number>
</Dial>
</Response>
Example Request
1
2
3
4
5
6
7
8
from plivo import plivoxml
response = plivoxml . ResponseElement ()
response . add (
plivoxml . DialElement ( action = 'https://<yourdomain>.com/dial_action/' , time_limit = 20 )
. add ( plivoxml . NumberElement ( '12025551111' )))
response . add ( plivoxml . DialElement (). add ( plivoxml . NumberElement ( '12025552222' )))
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
require 'rubygems'
require 'plivo'
include Plivo :: XML
include Plivo :: Exceptions
begin
response = Response . new
params = {
'timeout' => "20" ,
'action' => "https://<yourdomain>.com/dial_status/"
}
first_dial = response . addDial ( params )
first_number = "12025551111"
first_dial . addNumber ( first_number )
second_dial = response . addDial ()
second_number = "12025552222"
second_dial . addNumber ( second_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
var plivo = require ( ' plivo ' );
var response = plivo . Response ();
var params = {
' timeout ' : " 20 " ,
' action ' : " https://<yourdomain>.com/dial_action/ "
};
var first_dial = response . addDial ( params );
var first_number = " 12025551111 " ;
first_dial . addNumber ( first_number );
var second_dial = response . addDial ();
var second_number = " 12025552222 " ;
second_dial . addNumber ( second_number );
console . log ( response . toXML ());
/*
Sample Output
<Response>
<Dial timeout="20" action="https://<yourdomain>.com/dial_action/">
<Number>12025551111</Number>
</Dial>
<Dial>
<Number>12025552222</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
<?php
require '../vendor/autoload.php' ;
use Plivo\XML\Response ;
$response = new Response ();
$first_params = array (
'timeout' => "20" ,
'action' => "https://<yourdomain>.com/dial_action/"
);
$first_dial = $response -> addDial ( $first_params );
$first_number = "12025551111" ;
$first_dial -> addNumber ( $first_number );
$second_dial = $response -> addDial ();
$second_number = "12025552222" ;
$second_dial -> addNumber ( $second_number );
Header ( 'Content-type: text/xml' );
echo ( $response -> toXML ());
/*
Sample Output
<Response>
<Dial timeout="20" action="https://<yourdomain>.com/dial_action/">
<Number>12025551111</Number>
</Dial>
<Dial>
<Number>12025552222</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
// Example for dial - sequential dialing
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 SequentialDialing {
public static void main ( String [] args ) throws PlivoXmlException {
Response response = new Response ()
. children (
new Dial ()
. children (
new Number ( "12025551111" )
),
new Dial ()
. children (
new Number ( "12025552222" )
)
);
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
35
36
37
38
39
40
41
42
43
44
45
46
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 dial1 = new Plivo . XML . Dial ( new
Dictionary < string , string >() {
{ "timeout" , "20" },
{ "action" , "https://<yourdomain>.com/dial_action/" }
});
dial1 . AddNumber ( "12025551111" ,
new Dictionary < string , string >() { });
Plivo . XML . Dial dial2 = new Plivo . XML . Dial ( new
Dictionary < string , string >()
{ });
dial2 . AddNumber ( "12025552222" ,
new Dictionary < string , string >() { });
resp . Add ( dial1 );
resp . Add ( dial2 );
var output = resp . ToString ();
Console . WriteLine ( output );
}
}
}
//<Response>
// <Dial timeout = "20"
// action="https://<yourdomain>.com/dial_action/">
// <Number>12025551111</Number>
// </Dial>
// <Dial>
// <Number>12025552222</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 dial - sequential dialing
package main
import "github.com/plivo/plivo-go/v7/xml"
func main () {
response := xml . ResponseElement {
Contents : [] interface {}{
new ( xml . DialElement ) .
SetContents ([] interface {}{
new ( xml . NumberElement ) .
SetContents ( "12025551111" ),
}),
new ( xml . DialElement ) .
SetContents ([] interface {}{
new ( xml . NumberElement ) .
SetContents ( "12025552222" ),
}),
},
}
print ( response . String ())
}
Example Request
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
from flask import Flask , Response , request
import plivoxml
app = Flask ( __name__ )
@ app . route ( '/dial/sequential_dialing/' , methods = [ 'GET' , 'POST' ])
def sequential_dialing ():
response = plivoxml . Response ()
params = {
'timeout' : "20" ,
'action' : "https://foo.com/dial_action/"
}
Dial1 = response . addDial ( ** params )
Dial1 . addNumber ( "18217654321" )
Dial2 = response . addDial ()
Dial2 . addNumber ( "15671234567" )
return Response ( str ( response ), mimetype = 'text/xml' )
if __name__ == "__main__" :
app . run ( host = '0.0.0.0' , debug = True )
# Sample Conference XML
# <Response>
# <Dial action="https://foo.com/dial_action/" timeout="20">
# <Number>18217654321</Number>
# </Dial>
# <Dial>
# <Number>15671234567</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
require 'rubygems'
require 'plivo'
include Plivo
response = Response . new ()
params = {
'timeout' => "20" ,
'action' => "https://www.foo.com/dial_status/"
}
first_dial = response . addDial ( params )
first_number = "1111111111"
first_dial . addNumber ( first_number )
second_dial = response . addDial ()
second_number = "2222222222"
second_dial . addNumber ( second_number )
puts response . to_xml ()
=begin
Sample Output
<Response>
<Dial action='https://www.foo.com/dial_status/' timeout='20'>
<Number>1111111111</Number>
</Dial>
<Dial>
<Number>2222222222</Number>
</Dial>
</Response>
=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
var plivo = require ( ' plivo ' );
var response = plivo . Response ();
var params = {
' timeout ' : " 20 " ,
' action ' : " https://www.foo.com/dial_action "
};
var first_dial = response . addDial ( params );
var first_number = " 1111111111 " ;
first_dial . addNumber ( first_number );
var second_dial = response . addDial ();
var second_number = " 2222222222 " ;
second_dial . addNumber ( second_number );
console . log ( response . toXML ());
/*
Sample Output
<Response>
<Dial timeout="20" action="https://www.foo.com/dial_action">
<Number>1111111111</Number>
</Dial>
<Dial>
<Number>2222222222</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
<?php
require '../vendor/autoload.php' ;
use Plivo\Response ;
$response = new Response ();
$first_params = array (
'timeout' => "20" ,
'action' => "https://www.foo.com/dial_action/"
);
$first_dial = $response -> addDial ( $first_params );
$first_number = "1111111111" ;
$first_dial -> addNumber ( $first_number );
$second_dial = $response -> addDial ();
$second_number = "2222222222" ;
$second_dial -> addNumber ( $second_number );
Header ( 'Content-type: text/xml' );
echo ( $response -> toXML ());
/*
Sample Output
<Response>
<Dial timeout="20" action="https://www.foo.com/dial_action/">
<Number>1111111111</Number>
</Dial>
<Dial>
<Number>2222222222</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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.io.IOException ;
import com.plivo.helper.exception.PlivoException ;
import com.plivo.helper.xml.elements.Number ;
import com.plivo.helper.xml.elements.Dial ;
import com.plivo.helper.xml.elements.PlivoResponse ;
import javax.servlet.ServletException ;
import javax.servlet.http.HttpServlet ;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletResponse ;
import org.eclipse.jetty.server.Server ;
import org.eclipse.jetty.servlet.ServletContextHandler ;
import org.eclipse.jetty.servlet.ServletHolder ;
public class sequentialDialing extends HttpServlet {
private static final long serialVersionUID = 1L ;
@Override
protected void doGet ( HttpServletRequest req ,
HttpServletResponse resp )
throws ServletException , IOException {
PlivoResponse response = new PlivoResponse ();
Dial dial1 = new Dial ();
dial1 . setTimeout ( 20 );
dial1 . setAction ( "https://foo.com/dial_action" );
Number number1 = new Number ( "18217654321" );
Dial dial2 = new Dial ();
Number number2 = new Number ( "15671234567" );
try {
response . append ( dial1 );
dial1 . append ( number1 );
response . append ( dial2 );
dial2 . append ( number2 );
System . out . println ( response . toXML ());
resp . addHeader ( "Content-Type" , "text/xml" );
resp . getWriter (). print ( response . toXML ());;
} catch ( PlivoException e ) {
e . printStackTrace ();
}
}
public static void main ( String [] args ) throws Exception {
String port = System . getenv ( "PORT" );
if ( port == null )
port = "8000" ;
Server server = new Server ( Integer . valueOf ( port ));
ServletContextHandler context = new
ServletContextHandler ( ServletContextHandler . SESSIONS );
context . setContextPath ( "/" );
server . setHandler ( context );
context . addServlet ( new
ServletHolder ( new
sequentialDialing ()),
"/dial/sequential_dialing" );
server . start ();
server . join ();
}
}
/*
Sample Output
<Response>
<Dial action="https://foo.com/dial_action" timeout="20">
<Number>18217654321</Number>
</Dial>
<Dial>
<Number>15671234567</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
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 dial1 = new Plivo . XML . Dial ( new
Dictionary < string , string >() {
{ "timeout" , "20" },
{ "action" , "https://foo.com/dial_action/" }
});
dial1 . AddNumber ( "18217654321" ,
new Dictionary < string , string >() { });
Plivo . XML . Dial dial2 = new Plivo . XML . Dial ( new
Dictionary < string , string >()
{ });
dial2 . AddNumber ( "15671234567" ,
new Dictionary < string , string >() { });
resp . Add ( dial1 );
resp . Add ( dial2 );
var output = resp . ToString ();
Console . WriteLine ( output );
}
}
}
//<Response>
// <Dial timeout = "20"
// action="https://foo.com/dial_action/">
// <Number>18217654321</Number>
// </Dial>
// <Dial>
// <Number>15671234567</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
// Example for dial - sequential dialing
package main
import "github.com/plivo/plivo-go/v7/xml"
func main () {
response := xml . ResponseElement {
Contents : [] interface {}{
new ( xml . DialElement ) .
SetContents ([] interface {}{
new ( xml . NumberElement ) .
SetContents ( "12025551111" ),
}),
new ( xml . DialElement ) .
SetContents ([] interface {}{
new ( xml . NumberElement ) .
SetContents ( "12025552222" ),
}),
},
}
print ( response . String ())
}
🥳 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!
Thank you for your feedback!