简体   繁体   English

ASP.Core中的Twilio语音录制

[英]Twilio voice recording in ASP.Core

I'm building a new application and one of the its function is communication between seller and customer. 我正在构建一个新的应用程序,其功能之一是卖方和客户之间的通信。 For this reason I want to use Twilio API. 因此,我想使用Twilio API。 So let's imagine we have two person: seller and customer, and they are going to communicate. 让我们想象一下,我们有两个人:卖方和顾客,他们将进行交流。 My idea is that these two person shouldn't know real phone number each other, so I buy two phone numbers from Twilio, one for seller and one for customer and connect them with real phones in my app. 我的想法是,这两个人不应该彼此知道真实的电话号码,因此我从Twilio购买了两个电话号码,一个用于卖方,一个用于客户,然后将它们与我的应用程序中的真实电话联系起来。 For convenience I've created TwiML App in Twilio console and set REQUEST and STATUS CALLBACK URLs for Voice calls, these urls are pointed to Webhook in my app. 为了方便起见,我在Twilio控制台中创建了TwiML App,并设置了语音呼叫的REQUEST和STATUS CALLBACK URL,这些URL指向我应用中的Webhook。 My application is based on .Net Core, but I still use full .Net4.6 framework, because there are no some .dlls for .Net Core and seems Twilio helpers for C# have also been built for full .Net framework. 我的应用程序基于.Net Core,但是我仍然使用完整的.Net4.6框架,因为没有用于.Net Core的.dll,并且似乎Cwild的C#Twilio帮助程序也已针对完整.Net框架构建。 Any way, my webhook method looks like: 无论如何,我的webhook方法看起来像:

    [HttpPost("call")]
    public IActionResult IncomingCall(VoiceRequest request) {
        // some logic
        VoiceResponse response = new VoiceResponse();
        response.Dial({real_seller_number}, callerId: {virtual_customer_number}, record: "record-from-ringing-dual");

        return Content(response.ToString(), "application/xml");
    }

Here, let's imagine I'm customer, I want to call seller, I call its virtual Twilio number, Twilio makes a request to this webhook and it make a call to real seller's number from virtual customer number. 假设我是客户,我想打电话给卖家,我叫它的虚拟Twilio号码,Twilio向该Webhook发出请求,并从虚拟客户号向真实的卖家号码打电话。 This is OK and works as intended. 可以,可以正常运行。 When the call ends, Twilio makes a request to STATUS CALLBACK url, and this methos looks like: 通话结束时,Twilio向STATUS CALLBACK网址发出请求,此方法如下:

    [HttpPost("call/callback")]
    public IActionResult IncomingCallCallback(StatusCallbackRequest request) { 
        // some logic
        return Ok("Handled");
    }

In a first method you can see I want to record conversation for internal reason, and I expected RecordingSid and RecordingUrl in second method, but I always get them null. 在第一种方法中,您可以看到我出于内部原因要记录对话,并且在第二种方法中希望使用RecordingSid和RecordingUrl,但是我总是将它们设置为null。 I can see the recording in Twilio console, but cannot get them via API, that's my problem. 我可以在Twilio控制台中看到记录,但是无法通过API获取它们,这是我的问题。 I spent a lot of time and read a lot of docs, but didn't find clear explanation how to do it right. 我花了很多时间阅读了许多文档,但没有找到明确的解释说明如何正确执行操作。 Can someone help me? 有人能帮我吗?

Twilio developer evangelist here. Twilio开发人员布道者在这里。

When recording calls the recording might not be ready by the time you receive the statusCallback request. 录制呼叫时,在您收到statusCallback请求时,录制可能尚未准备好。 Instead you should set a recordingStatusCallback URL which will be called when the recording is complete and ready. 相反,您应该设置一个recordingStatusCallback URL ,在录制完成并准备就绪时将调用它。

[HttpPost("call")]
public IActionResult IncomingCall(VoiceRequest request) {
    // some logic
    VoiceResponse response = new VoiceResponse();
    response.Dial({real_seller_number},
        callerId: {virtual_customer_number},
        record: "record-from-ringing-dual",
        recordingStatusCallback: {url_in_your_application_that_processes_recordings}
    );

    return Content(response.ToString(), "application/xml");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM