We have an automation for our IT tickets, when an agent hangs up with a caller it creates a ticket and then links to RingCentral's call recording for the call to listen to later.
What we would like to do is dump the recording as an attachment to that ticket/email, this would allow us to keep recordings longer.
How am I able to do that? We looked through "Get Call Recordings Data" (https://developers.ringcentral.com/api-reference/Call-Recordings/listCallRecordingData) but are not sure how to take that data in Python and save it as a MP3/WAV file.
We have tried taking r.text() and exporting the bytes to a WAV file, but then it returns that r.text() is does not contain only byes(which it doesn't). We have tried loading r.text() into pydub as well, but it does not read it either.
Is this not possible with Python?
Retrieve Call MP3 / WAV - Python
Here is the sample code for you Nate. If you need to read the call log and download lots of call recordings, you will need to handle the [API rate limit][1]. If you need to detect the file format as wav or mp3, you need to read the [recording metadata][2] and detect the type to create a correct filename extension.
def read_account_call_log():
path = os.getcwd() + "/recording_content/"
if not os.path.isdir(path):
print("create folder")
try:
os.mkdir(path)
except OSError as e:
print(e)
params = {
'dateFrom': "2022-01-01T00:00:00.000Z",
'perPage': 1000
}
resp = platform.get('/restapi/v1.0/account/~/call-log', params)
jsonObj = resp.json()
for record in jsonObj.records:
if hasattr(record, 'recording'):
fileName = str(record.recording.id) + ".mp3"
try:
res = platform.get(record.recording.contentUri)
file = open(("%s%s" % (path, fileName)),'wb')
file.write(res.body())
file.close()
print ("Call recording saved in " + fileName)
except ApiException as e:
print (e.getMessage())
[1]: https://medium.com/ringcentral-developers/ringcentral-api-rate-limit-explained-2280fe53cb16
[2]: https://developers.ringcentral.com/api-reference/Call-Recordings/readCallRecording
You're awesome as always, Phong! Thank you!
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.