Search code examples
c#twiliotwilio-twiml

Twilio action in Dial method not working, C#


I have encountered a small problem using Twilio with C#. Basically, I'm having trouble controlling the call after the .Dial method is called.

Considering I have the following piece of code:

   TwilioResponse _twiml = new TwilioResponse();
   _twiml.Dial(RedirectPhoneNumner, new { action = Url.Action("BusyCallAction"), timeout = 5 });`

The following is being rendered in my application:

<Response>
<Dial action="/Home/BusyCallAction" timeout="5">*RedirectPhoneNumber*</Dial>
</Response>

For testing purposes, I've added a timeout of 5 seconds. After the timeout has passed, the call ends, instead of redirecting the user to the following controller:

[HttpPost]
public ActionResult BusyCallAction(string dialCallStatus)
    {
        if (dialCallStatus == "busy")
        {
            _twiml.Say(dialCallStatus);
            //more code here
        }
        return TwiML(_twiml);
    }

Note: The method has the HttpPost data annotation because the default method attribute in the dial method is set to POST.

I need to know whether the call was answered, or if it was busy.


Solution

  • NOTE:This question was answered by one of Twilio's agents. I told him that he should post the answer here, but he doesnt have an SO account, yet.

    The solution was indeed quite simple, the code works as expected, but the condition of

    if (dialCallStatus == "busy")
            {
                _twiml.Say(dialCallStatus);
                //more code here
            }
    

    Would never be triggered in this test scenario, as when the timeout occurs, the status is "no-answer", as specified here: https://www.twilio.com/docs/api/twiml/dial

    Hope this answer helps anyone with the same situation.