使用 C# 下载 Twilio 录音

Download Twilio Recordings using C#

我正在使用 Twilio API 开发一个小型实用程序,它打算在通话结束后立即下载通话录音(可以使用 webhook 完成吗?)。我不确定 twilio 是否支持这种 webhooks。

我想到的第二种方法是创建夜间作业,可以获取当天的所有通话详细信息并下载录音。

谁能建议我最好的方法。我检查了 webhooks 但我不确定他们是否提供呼叫结束事件。

如果有人能向我提供有关如何获取特定日期的录音并使用 C# 从 twilio 下载它们的代码示例,我将不胜感激。

这里是 Twilio 开发人员布道者。

您可以获得录音 webhook,但如何录音取决于您如何录音通话。

使用<Record>

recordingStatusCallback attribute on <Record> 设置 URL,当录制准备就绪时,您将收到一个带有 link.

的网络钩子

使用<Dial>

如果您录制来自 <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 的通话。

使用<Conference>

如果你record a conference then you can also set a recordingStatusCallback.

正在录音外拨

如果您通过在 outbound call made with the REST API then you can also set a webhook URL by setting a RecordingStatusCallback parameter in the request 上设置 Record=true 来记录通话。

正在从 REST 中检索录音 API

您还可以使用第二个选项并调用 REST API 来检索录音。为此,您可以使用 Recordings List resource. You can restrict this to the recordings before or after a date using the list filters.

这是一个简单的示例,说明如何使用 Twilio C# library 获取最近的录音:

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
    }
  }
}

让我知道这是否有帮助。