Sachin Trivedi
Sachin Trivedi

Reputation: 2053

Download Twilio Recordings using C#

I am working on one small utility using Twilio API which intend to download the recording of the call as soon as call ends ( can be done using webhooks ? ). I am not sure if twilio supports this kind of webhooks or not.

The second approach that i have in mind is to create nightly job that can fetch all the call details for that day and download the recordings.

Can anyone suggest me which is the best approach to follow. I checked the webhooks but i am not sure if they provide the call ended event.

I would appreciate if anyone can provide me code sample on how to get the recordings for particular date and download them using C# from twilio.

Upvotes: 1

Views: 1111

Answers (1)

philnash
philnash

Reputation: 73057

Twilio developer evangelist here.

You can get recording webhooks, but how you do so depends on how you record the call.

Using <Record>

Set a URL for the recordingStatusCallback attribute on <Record> and when the recording is ready you will receive a webhook with the link.

Using <Dial>

If you record a call from the <Dial> verb using the record attribute set to any of record-from-answer, record-from-ringing, record-from-answer-dual, record-from-ringing-dual then you can also set a recordingStatusCallback.

Using <Conference>

If you record a conference then you can also set a recordingStatusCallback.

Recording an outbound dial

If you record the call by setting Record=true on an outbound call made with the REST API then you can also set a webhook URL by setting a RecordingStatusCallback parameter in the request.

Retrieving recordings from the REST API

You can also use your second option and call the REST API to retrieve recordings. To do so, you would use the Recordings List resource. You can restrict this to the recordings before or after a date using the list filters.

Here is a quick example of how you would use the Twilio C# library to fetch recent recordings:

using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "AC81ebfe1c0b5c6769aa5d746121284056";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var recordings = twilio.ListRecordings(null, null, null, null);

    foreach (var recording in recordings.Recordings)
    {
      Console.WriteLine(recording.Duration);
      // Download recording.Uri here
    }
  }
}

Let me know if this helps at all.

Upvotes: 3

Related Questions