0

I am able to make a call doing this. The call goes out, but how do I set it so when I make the outgoing call, the conversation is recorded, and once the call is done, I want to tie that recording id (retrieve the call/recording sid) and store it in some model.

export function callCustomer(phoneNumber) {
    const params = {
        phone_number: phoneNumber,
    };
    Twilio.Device.connect(params);
}

In my views.py

@csrf_exempt
def call(request):
    """Returns TwiML instructions to Twilio's POST requests"""
    response = twiml.Response()

    with response.dial(callerId=settings.TWILIO['SOURCE_NUMBER']) as r:
        r.number(request.POST['phone_number'])

    return HttpResponse(str(response))
rak1n
  • 671
  • 1
  • 8
  • 17

1 Answers1

1

Twilio developer evangelist here.

You can record the call by using the record attribute on the <Dial> verb. Set it to "record-from-answer" to record the call.

You will also want to set the recordingStatusCallback attribute to a URL in your application. Twilio will make an HTTP request with the details of the call and recording when the recording is ready, passing these parameters.

@csrf_exempt
def call(request):
    """Returns TwiML instructions to Twilio's POST requests"""
    response = twiml.Response()

    with response.dial(callerId=settings.TWILIO['SOURCE_NUMBER'], record='record-from-answer', recordingStatusCallback='/recording') as r:
        r.number(request.POST['phone_number'])

    return HttpResponse(str(response))

Then you can use the parameters passed to the recordingStatusCallback to save the details in your database.

Let me know if that helps.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • recordingStatusCallback uses the same POST object? So if i pass an account_id in my post, I can tie the recording to the associated account? The recording feature works by the way, thanks. – rak1n Mar 17 '17 at 17:39
  • You can see all [the parameters that the `recordingStatusCallback` passes in the POST request in the docs here](https://www.twilio.com/docs/api/twiml/dial#attributes-recording-status-callback-parameters). – philnash Mar 17 '17 at 17:42
  • yes it's missing few data I would like to pass, such as From, To, and an internal variable (ticket_id) – rak1n Mar 17 '17 at 19:58
  • It will pass the `CallSid` though. So if you save those other parameters along with the `CallSid` earlier in the call, then you can look them up when you need them in the recording status callback. – philnash Mar 19 '17 at 16:48