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
Copy
Ask AI
from plivo import plivoxmlresponse = 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())
Copy
Ask AI
from plivo import plivoxmlresponse = 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())
Copy
Ask AI
from flask import Flask, Response, requestimport plivoxmlapp=Flask(__name__)@app.route('/record/voice_mail', methods=['GET','POST'])def voice_mail(): response = plivoxml.Response() response.addSpeak("Leave message. Press star key when done") params = { 'maxLength' : "20", 'action' : "https://foo.com/get_recording/", 'finishOnKey' : "*" } response.addRecord(**params) response.addSpeak("Recording not received.") return Response(str(response), mimetype='text/xml')if __name__ == "__main__": app.run(host='0.0.0.0', debug=True)# Sample Conference XML# <Response># <Speak># Leave message. # Press star key when done# </Speak># <Record action="https://foo.com/get_recording/" # finishOnKey="*" maxLength="20"/># <Speak>Recording not received.</Speak># </Response>
Response
Copy
Ask AI
<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
Copy
Ask AI
from plivo import plivoxmlresponse = 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())
Copy
Ask AI
from plivo import plivoxmlresponse = 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())