Twilio Gather 不暂停输入

Twilio Gather not pausing for input

我在让 Twilio 执行 Gather 时遇到问题。调用初始化很好,但不是等待用户按键,Gather 只是进入下一个语句并挂断。

我的环境是Visual Studio2015..NET 4.6,MVC6,asp.net5。我安装了 RC1 更新。 Nuget 包是 Twilio 版本 4.4.1,Twilio.TwiML 3.3.6.

这是一个测试 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());
    }
}

当 Twilio 收到以下数据时,它立即说 "Test Message Here Fallthrough. Goodbye.",没有停顿,然后立即挂断。

使用 ngrok 我可以看到 Twilio POST 对我的控制器的响应是:

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

此外,我的 Twilio 日志看起来像(相同):

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

编辑:

我还尝试将 WebAPI 更改为 return 字符串而不是 IActionResult。没有任何变化,结果相同。

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

答案:

原来我没有return输入正确的内容类型,我修改了POST动作的return,完整的控制器代码如下:

[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 开发人员布道者。

我刚刚复制了您生成的 TwiML to twimlbin 并且能够在适当的暂停和不跳过的情况下让它工作。

这是 your generated TwiML 的精确副本。

很明显,当你按下一个数字时,它会失败,因为动作只设置为 foo。如果您将该操作设置为其他内容,如下例所示,您将看到在按下数字后,您还应该收到一条消息 "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>

此外,您的 C# 代码看起来不错,但让我知道您想创建端点 public 以便我对其进行测试。值得检查一下您返回到 Twilio 的内容是否真的是 XML(即它的顶部有 <?xml version="1.0" encoding="UTF-8"?>)并且它的内容类型真的是 XML.

很乐意帮助解决任何其他问题。