Twilio/TwiML 上的交互式语音菜单

Interactive voice menu on Twilio/TwiML

我需要一个与 TwiML 配合使用的交互式菜单,对此我有一些疑问:

  1. 我可以纯粹在 TwiML 中完成吗,还是需要带有表单处理的服务器端安装?
  2. 我基本上需要接听电话,询问用户几个选项(按 1 表示 yada yada,按 2 表示 blah blah),然后根据响应需要拨打一个或另一个号码。有点像交互式总机

以上可能吗?关于我如何去做的任何迹象?

这里是 Twilio 开发人员布道者。

您无法使用静态 TwiML 生成交互式菜单,您需要能够对所做的选择作出反应并且需要服务器端组件的东西。

谢天谢地,您在这里有一些选择。

正如 Alex 在评论中指出的那样,Twilio Studio is a visual builder for Twilio which lets you create a flow like this and leave the server side component to Twilio. There's a video tutorial and guide 向您展示了如何使用 Studio 构建 IVR。

另一方面,如果您乐于编写代码来创建这类东西,但不想托管它,那么Twilio Functions might be what you're looking for. Twilio Functions is a serverless environment for running code. You can write your initial TwiML with a TwiML Bin as it can be static TwiML, something like the following, which uses <Gather> 收集用户输入:

<Response>
  <Gather action="FUNCTION_URL" numDigits="1">
    <Say>Welcome to my menu, please press 1 for sales or 2 for support</Say>
  </Gather>
</Response>

然后在函数中你需要写一些 Node.js 来响应传入的 Digits parameter that <Gather> 将在用户输入后发送到 action URL。您可以使用看起来有点像这样的函数来响应它:

exports.handler = function(context, event, callback) {
  const twiml = new Twilio.twiml.VoiceResponse();
  if (event.Digits === '1') {
    twiml.dial(SALES_NUMBER);
  } else if (event.Digits === '2') {
    twiml.dial(SUPPORT_NUMBER);
  } else {
    const gather = twiml.gather({ action: 'FUNCTION_URL', numDigits: '1' })
    gather.say('That was not an option, please dial 1 for sales and 2 for support')
  }
  callback(null, twiml);
}

taking user input using <Gather> 中还有一个更深入的指南。

如果有帮助请告诉我。