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://foo.com/get_recording/" startOnDialAnswer="true" redirect="false" maxLength="3600" />
      <Dial>
        <Number>15551234567</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://foo.com/get_recording/',
            start_on_dial_answer=True,
            redirect=False))
    response.add(plivoxml.DialElement().add(plivoxml.NumberElement('15551234567')))
    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://www.foo.com/get_recording/',
          startOnDialAnswer: 'true',
          redirect: 'false'
      }
    
      response.addRecord(params)
    
      dial = response.addDial()
      number = '1111111111'
      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://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\XML\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
    
    // 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://foo.com/get_recording/")
                                    .redirect(false)
                                    .startOnDialAnswer(true),
    
    
                            new Dial()
                                    .children(
                                            new Number("15551234567")
                                    )
                    );
            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://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
    
    // Example for record - record session
    package main
    
    import "github.com/plivo/plivo-go/xml"
    
    func main() {
    	response := xml.ResponseElement{
    		Contents: []interface{}{
    
    			new(xml.RecordElement).
    				SetAction("https://foo.com/get_recording/").
    				SetRedirect(false).
    				SetStartOnDialAnswer(true),
    
    			new(xml.DialElement).
    				SetContents([]interface{}{
    					new(xml.NumberElement).
    						SetContents("15551234567"),
    				}),
    		},
    	}
    	print(response.String())
    }