Record a complete call session
To record an entire call leg from start to end, set the recordSession
attribute of the Record XML element to true in the Answer XML element. recordSession="true" silently initiates a recording of the call in the background.
To record just the conversation between the A leg and the connected B leg (initiated using the Dial XML element), add a Record XML element with startOnDialAnswer="true" just before the Dial XML.
In either scenario, the call is recorded until it’s hung up or the maxLength recording duration is reached. Set maxLength to a high value based on the maximum duration you expect your calls to go on for.
If the maxLength value is not set, it defaults to 60 seconds.
If maxLength is < 1 or an invalid integer, it will trigger the error “Record ‘maxLength’ must be a positive integer” and disconnect the call.
If maxLength is > 1 and a valid integer, it will be set to the value.
Response
<Response>
<Record action= "https://<yourdomain>.com/get_recording/" startOnDialAnswer= "true" redirect= "false" maxLength= "3600" />
<Dial>
<Number> 12025551111</Number>
</Dial>
</Response>
Example Request
1
2
3
4
5
6
7
8
9
10
from plivo import plivoxml
response = plivoxml . ResponseElement ()
response . add (
plivoxml . RecordElement (
action = 'https://<yourdomain>.com/get_recording/' ,
start_on_dial_answer = True ,
redirect = False ))
response . add ( plivoxml . DialElement (). add ( plivoxml . NumberElement ( '12025551111' )))
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
require 'rubygems'
require 'plivo'
include Plivo :: XML
include Plivo :: Exceptions
begin
response = Response . new
params = {
action: 'https://<yourdomain>.com/get_recording/' ,
startOnDialAnswer: 'true' ,
redirect: 'false'
}
response . addRecord ( params )
dial = response . addDial ()
number = '12025551111'
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
var plivo = require ( ' plivo ' );
var response = plivo . Response ();
var params = {
' action ' : " https://<yourdomain>.com/get_recording/ " ,
' startOnDialAnswer ' : " true " ,
' redirect ' : " false "
};
response . addRecord ( params );
var dial = response . addDial ();
var number = " 12025551111 " ;
dial . addNumber ( number );
console . log ( response . toXML ());
/*
Sample Output
<Response>
<Record action="https://<yourdomain>.com/get_recording/" startOnDialAnswer="true" redirect="false"/>
<Dial>
<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
22
23
24
25
26
27
28
29
30
31
32
<?php
require '../vendor/autoload.php' ;
use Plivo\XML\Response ;
$response = new Response ();
$params = array (
'action' => "https://<yourdomain>.com/get_recording/" ,
'startOnDialAnswer' => "true" ,
'redirect' => "false"
);
$response -> addRecord ( $params );
$dial = $response -> addDial ();
$number = "12025551111" ;
$dial -> addNumber ( $number );
Header ( 'Content-type: text/xml' );
echo ( $response -> toXML ());
/*
Sample Output
<Response>
<Record action="https://<yourdomain>.com/get_recording/" startOnDialAnswer="true" redirect="false"/>
<Dial>
<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
22
23
24
25
26
27
28
29
// Example for record - record a complete call session
package com.plivo.api.xml.samples.record ;
import com.plivo.api.exceptions.PlivoXmlException ;
import com.plivo.api.xml.Dial ;
import com.plivo.api.xml.Number ;
import com.plivo.api.xml.Record ;
import com.plivo.api.xml.Response ;
class RecordACompleteCallSession {
public static void main ( String [] args ) throws PlivoXmlException {
Response response = new Response ()
. children (
new Record ( "https://<yourdomain>.com/get_recording/" )
. redirect ( false )
. startOnDialAnswer ( true ),
new Dial ()
. 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
35
36
37
38
39
40
41
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 . AddRecord ( new Dictionary < string , string >() {
{ "action" , "https://<yourdomain>.com/get_recording/" },
{ "startOnDialAnswer" , "true" },
{ "redirect" , "false" }
});
Plivo . XML . Dial dial = new Plivo . XML . Dial ( new
Dictionary < string , string >()
{ });
dial . AddNumber ( "12025551111" ,
new Dictionary < string , string >() { });
resp . Add ( dial );
var output = resp . ToString ();
Console . WriteLine ( output );
}
}
}
//<Response>
// <Record action = "https://<yourdomain>.com/get_recording/"
// startOnDialAnswer="true" redirect="false" />
// <Dial>
// <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
22
23
// Example for record - record session
package main
import "github.com/plivo/plivo-go/v7/xml"
func main () {
response := xml . ResponseElement {
Contents : [] interface {}{
new ( xml . RecordElement ) .
SetAction ( "https://<yourdomain>.com/get_recording/" ) .
SetRedirect ( false ) .
SetStartOnDialAnswer ( true ),
new ( xml . DialElement ) .
SetContents ([] interface {}{
new ( xml . NumberElement ) .
SetContents ( "12025551111" ),
}),
},
}
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 ( '/record/session/' , methods = [ 'GET' , 'POST' ])
def session ():
response = plivoxml . Response ()
params = {
'startOnDialAnswer' : "true" ,
'action' : "https://foo.com/get_recording/" ,
'redirect' : "false"
}
response . addRecord ( ** params )
dial = response . addDial ()
dial . addNumber ( "15551234567" )
return Response ( str ( response ), mimetype = 'text/xml' )
if __name__ == "__main__" :
app . run ( host = '0.0.0.0' , debug = True )
# Sample Conference XML
# <Response>
# <Record action="https://foo.com/get_recording/"
# redirect="false" startOnDialAnswer="true"/>
# <Dial>
# <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
22
23
24
25
26
27
28
29
require 'rubygems'
require 'plivo'
include Plivo
response = Response . new ()
params = {
'action' => "https://www.foo.com/get_recording/" ,
'startOnDialAnswer' => "true" ,
'redirect' => "false"
}
response . addRecord ( params )
dial = response . addDial ()
number = "1111111111"
dial . addNumber ( number )
puts response . to_xml ()
=begin
Sample Output
<Response>
<Record action='https://www.foo.com/get_recording/' redirect='false' startOnDialAnswer='true'/>
<Dial>
<Number>1111111111</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
var plivo = require ( ' plivo ' );
var response = plivo . Response ();
var params = {
' action ' : " https://www.foo.com/get_recording/ " ,
' startOnDialAnswer ' : " true " ,
' redirect ' : " false "
};
response . addRecord ( params );
var dial = response . addDial ();
var number = " 1111111111 " ;
dial . addNumber ( number );
console . log ( response . toXML ());
/*
Sample Output
<Response>
<Record action="https://www.foo.com/get_recording/" startOnDialAnswer="true" redirect="false"/>
<Dial>
<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
<?php
require '../vendor/autoload.php' ;
use Plivo\Response ;
$response = new Response ();
$params = array (
'action' => "https://www.foo.com/get_recording/" ,
'startOnDialAnswer' => "true" ,
'redirect' => "false"
);
$response -> addRecord ( $params );
$dial = $response -> addDial ();
$number = "1111111111" ;
$dial -> addNumber ( $number );
Header ( 'Content-type: text/xml' );
echo ( $response -> toXML ());
/*
Sample Output
<Response>
<Record action="https://www.foo.com/get_recording/" startOnDialAnswer="true" redirect="false"/>
<Dial>
<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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.io.IOException ;
import com.plivo.helper.exception.PlivoException ;
import com.plivo.helper.xml.elements.Record ;
import com.plivo.helper.xml.elements.Dial ;
import com.plivo.helper.xml.elements.Number ;
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 recordSession extends HttpServlet {
private static final long serialVersionUID = 1L ;
@Override
protected void doGet ( HttpServletRequest req ,
HttpServletResponse resp )
throws ServletException , IOException {
PlivoResponse response = new PlivoResponse ();
Record record = new Record ();
record . setAction ( "https://foo.com/get_recording" );
record . setStartOnDialAnswer ( true );
record . setRedirect ( false );
Dial dial = new Dial ();
Number number = new Number ( "15551234567" );
try {
response . append ( record );
response . append ( dial );
dial . append ( number );
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
recordSession ()), "/record/session" );
server . start ();
server . join ();
}
}
/*
Sample Output
<Response>
<Record redirect="false" startOnDialAnswer="true"
action="https://foo.com/get_recording"/>
<Dial>
<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
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 . AddRecord ( new Dictionary < string , string >() {
{ "action" , "https://foo.com/get_recording/" },
{ "startOnDialAnswer" , "true" },
{ "redirect" , "false" }
});
Plivo . XML . Dial dial = new Plivo . XML . Dial ( new
Dictionary < string , string >()
{ });
dial . AddNumber ( "15551234567" ,
new Dictionary < string , string >() { });
resp . Add ( dial );
var output = resp . ToString ();
Console . WriteLine ( output );
}
}
}
//<Response>
// <Record action = "https://foo.com/get_recording/"
// startOnDialAnswer="true" redirect="false" />
// <Dial>
// <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
22
23
24
25
// Example for record - record session
package main
import "github.com/plivo/plivo-go/v7/xml"
func main () {
response := xml . ResponseElement {
Contents : [] interface {}{
new ( xml . RecordElement ) .
SetAction ( "https://<yourdomain>.com/get_recording/" ) .
SetRedirect ( false ) .
SetStartOnDialAnswer ( true ),
new ( xml . DialElement ) .
SetContents ([] interface {}{
new ( xml . NumberElement ) .
SetContents ( "12025551111" ),
}),
},
}
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!