简体   繁体   中英

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. 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. 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. 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. Any way, my webhook method looks like:

    [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. This is OK and works as intended. When the call ends, Twilio makes a request to STATUS CALLBACK url, and this methos looks like:

    [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. I can see the recording in Twilio console, but cannot get them via API, that's my problem. 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.

When recording calls the recording might not be ready by the time you receive the statusCallback request. Instead you should set a recordingStatusCallback URL which will be called when the recording is complete and ready.

[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");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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