简体   繁体   中英

Twilio Voice <Gather> - DotNetCore - Digits parameter always null

I'm trying to do the following:

  1. Call twilio #.
  2. Gather digits from user.
  3. Process digits.

I'm using DotNetCore webapi.

The problem I'm having is that when twilio posts to the Gather action uri, Digits is always null. I confirmed in the twilio debug console that the Digits parameter does have a value.

Here's a reduced version of my controller:

[ApiController]
[Route("api/[controller]")]
public class VoiceController : ControllerBase
{
    [HttpPost]
    public IActionResult Post()
    {
        var response = new VoiceResponse();
        var say = new Say("Please type your meeting password.");
        var gather = new Gather(action: "placeholderURI/JoinMeeting");

        response.Append(gather).Append(say);
        response.Redirect("placeholderURI");

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

    [HttpPost("JoinMeeting")]
    public IActionResult JoinMeeting(string Digits)
    {
        var response = new VoiceResponse();
        
        if(Digits != null){
            //do stuff
        }else{
            var say = new Say("WRONG");
            response.Append(say).Redirect("placeholderURI");
        }
        
        return Content(response.ToString(), "application/xml");
    }
}

Also, I can copy the RAW parameters from the debug console into postman's parameters and successfully post to my endpoint.

Am I missing something? Maybe some decoration on the JoinMeeting method?

I failed to read the manual...

On twilio POST, parameters will be in the body.

On twilio GET, parameters will be in the query string.

I updated the 2nd method to GET and made sure to specify the method:

var gather = new Gather(action: "uriPlaceholder", method: HttpMethods.Get);

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