简体   繁体   English

Twilio Gather不暂停输入

[英]Twilio Gather not pausing for input

I'm having trouble getting Twilio to perform a Gather. 我无法让Twilio进行聚会。 The call initializes just fine but instead of waiting for a user keypress, the Gather just falls through to the next statement and hangs up. 调用可以很好地进行初始化,但无需等待用户按键,Gather便会转到下一条语句并挂断。

My environment is Visual Studio 2015. .NET 4.6, MVC6, asp.net5. 我的环境是Visual Studio 2015.NET 4.6,MVC6,asp.net5。 I have the RC1 Update installed. 我已经安装了RC1更新。 Nuget packages are Twilio version 4.4.1, Twilio.TwiML 3.3.6. Nuget软件包是Twilio版本4.4.1,Twilio.TwiML 3.3.6。

Here is a test WebAPI 2 controller: 这是一个测试WebAPI 2控制器:

[Route("api/[controller]")]
public class OutboundCallController : Controller
{
    [HttpPost]
    public IActionResult Post()
    {
        var twilioResponse = new TwilioResponse();
        twilioResponse.BeginGather(new { timeout = "60", numDigits = "1", action = "Foo", method = "POST" });
        twilioResponse.Say("Test Message Here");
        twilioResponse.EndGather();
        twilioResponse.Say("Fallthrough.  Goodbye.");
        return new ObjectResult(twilioResponse.ToString());
    }
}

When Twilio receives the below data it Says "Test Message Here Fallthrough. Goodbye." 当Twilio收到以下数据时,它说“测试消息在此失败。再见。” all at once, without pausing, then promptly hangs up. 立即完成所有操作,而不会暂停,然后立即挂断。

Using ngrok I can see that the reponse to the Twilio POST to my controller is: 使用ngrok,我可以看到对Twilio POST到控制器的响应是:

<Response>
  <Gather timeout="60" numDigits="1" action="Foo" method="POST">
    <Say>Test Message Here</Say>
  </Gather>
  <Say>Fallthrough.  Goodbye.</Say>
</Response>

Additionally, my Twilio log looks like (identical): 另外,我的Twilio日志看起来像(相同):

<Response>
  <Gather timeout="60" numDigits="1" action="Foo" method="POST">
    <Say>Test Message Here</Say>
  </Gather>
  <Say>Fallthrough.  Goodbye.</Say>
</Response>

EDIT: 编辑:

I've also tried changing the WebAPI to return a string instead of IActionResult. 我还尝试过更改WebAPI以返回字符串而不是IActionResult。 Nothing changes, same result. 没有任何变化,结果相同。

[HttpPost]
    public string Post()
    {....}

ANSWER: 回答:

Turns out I wasn't returning the correct content type, I modified the return of the POST action, the full controller code is below: 原来我没有返回正确的内容类型,我修改了POST操作的返回,完整的控制器代码如下:

[Route("api/[controller]")]
public class OutboundCallController : Controller
{
    [HttpPost]
    public IActionResult Post()
    {
        var twilioResponse = new TwilioResponse();
        twilioResponse.BeginGather(new { timeout = "60", numDigits = "1", action = "Foo", method = "POST" });
        twilioResponse.Say("Test Message Here");
        twilioResponse.EndGather();
        twilioResponse.Say("Fallthrough.  Goodbye.");
        return Content(twilioResponse.ToString(), "application/xml");
    }
}

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

I just copied your generated TwiML to twimlbin and was able to get it working with proper pause and without skipping. 我只是将您生成的TwiML复制到twimlbin,并且能够使其在适当的暂停下正常工作而不会跳过。

Here's an exact copy of your generated TwiML . 这是您生成的TwiML的精确副本。

Obviously when you press a number, it fails because the action is only set to be foo . 显然,当您按数字时,它会失败,因为操作仅设置为foo If you set that action to something else like the example below, you will see that upon pressing a number, you should also get a message that says "Hi there" 如果您将该操作设置为以下示例中的其他内容,则会看到在按数字时,还应该显示一条消息,提示“嗨,那里”

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Gather timeout="60" numDigits="1" action="http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%3EHi+there.%3C%2FSay%3E%3C%2FResponse%3E" method="POST">
    <Say>Test Message Here</Say>
  </Gather>
  <Say>Fallthrough.  Goodbye.</Say>
</Response>

Also, your C# code looks right but let me know you want to make your endpoint public so I can test it. 另外,您的C#代码看起来不错,但请告诉我您想将端点公开,以便我对其进行测试。 It will be worth checking that what you're returning to Twilio is really XML (ie that it has <?xml version="1.0" encoding="UTF-8"?> on top) and that its content type is really XML. 值得检查的是,您返回给Twilio的内容确实是XML(即,它的顶部是<?xml version="1.0" encoding="UTF-8"?> ),并且其内容类型确实是XML。

Happy to help with any other questions. 很高兴为您解决其他任何问题。

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

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