-1

Very similar to this question: How to use twilio and twiml to record a call and redirect the call or join someone else to the call

I'm trying to record an incoming call. The solution in the post above is written in JavaScript. How do you write the same solution in Python? There is no method in twilio's Python library like client.calls(callSid).recordings.create(). I'm trying the following:

client = Client(os.getenv("TWILIO_ACCOUNT_SID"), os.getenv("TWILIO_AUTH_TOKEN"))
callCon = client.calls(request.form["CallSid"])

recordings = callCon.recordings(request.form["CallSid"]).create() # this line errors out

I was expecting twilio to start recording the call. Instead I get an error saying no create() method exists.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Nick Garyu
  • 506
  • 2
  • 5

1 Answers1

0

The Twilio documentation site provides code in multiple languages including Python.

To record a call, use this code:

//Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client


# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)

recording = client.calls('CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \
                  .recordings \
                  .create()

print(recording.sid)

For your error about missing the create function, if you are sure you don't have any typos, make sure to install the Twilio Python Help Library and reference it in your code as shown above.

The code you provided with the error has incorrect syntax. This is your code edited to create a recording:

client.calls(request.Form["CallSid"]).recordings.create()
jassent
  • 529
  • 3
  • 10