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.

Example Request

from plivo import plivoxml

response = plivoxml.ResponseElement()
response.add(
    plivoxml.SpeakElement(
        "Please leave a message. Press the star key or hang up when you're done."))
response.add(
    plivoxml.RecordElement(
        action='https://<yourdomain>.com/get_recording/',
        max_length=30,
        finish_on_key='*'))
response.add(plivoxml.SpeakElement('Recording not received.'))
print(response.to_string())

Response

<Response>
  <Speak>Please leave a message after the beep. Press the star key when done.</Speak>
  <Record action="https://<yourdomain>.com/get_recording/" finishOnKey="*" maxLength="30"></Record>
  <Speak>Recording not received.</Speak>
</Response>

Example Request

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())

Response

<Response>
  <Record action="https://<yourdomain>.com/get_recording/" startOnDialAnswer="true" redirect="false" maxLength="3600" />
  <Dial>
    <Number>12025551111</Number>
  </Dial>
</Response>