Twilio .NET 7: The action method I am setting in Gather is getting hit but SpeechResult is always null

89 Views Asked by At
[HttpPost]
public TwiMLResult Index()
   {
        var redirectUrl = Url.Action(nameof(IncomingCallController.HandleGather), nameof(IncomingCallController).RemoveController());
        var uri = new Uri(redirectUrl, UriKind.Relative);
        var response = new VoiceResponse();
        var gather =
            new Gather(
                action: uri,
                input: new[] { Gather.InputEnum.Speech }.ToList(),
                speechTimeout: "auto",
                timeout: 3,
                enhanced: true,
                speechModel: Gather.SpeechModelEnum.PhoneCall,
                language: Gather.LanguageEnum.EnUs
            );
        var say = new Say("Hello!", Say.VoiceEnum.PollyJoannaNeural, language: Say.LanguageEnum.EnUs);
        response.Append(gather.Append(say));
        
       return TwiML(response);
    }

[HttpPost]
public TwiMLResult HandleGather(string SpeechResult, double Confidence, string SpeechError)
    {
        if (!string.IsNullOrEmpty(SpeechError))
        {
            Console.WriteLine($"Error: {SpeechError}");
        }
        else if (!string.IsNullOrEmpty(SpeechResult))
        {
            if (Confidence >= 0.8)
            {
                Console.WriteLine($"You said: {SpeechResult}. Thank you!");
            }
            else
            {
                Console.WriteLine($"I think you said: {SpeechResult}, but I'm not sure. Please try again.");
            }
        }
        else
        {
            Console.WriteLine("Sorry, I didn't catch that.");
        }
    }

The SpeechResult parameter is always null. I have tried getting the raw body and parsing it to json. I have tried looking in the Request.QueryString. It doesn't seem to exist anywhere in the request object. I have scoured the docs and the web and I have not found anything relating to this.

Any help with this would be greatly appreciated! Thank you in advance!

1

There are 1 best solutions below

1
jassent On

Did you check in the Twilio console? Login, locate a call, and view the webhooks that it is sending and your actual Twiml.

If the webhook is not including the text, then something is probably wrong with your Gather Twiml. A timeout of 3 seems pretty short. Maybe you are timing out before gathering the speech?