【问题标题】:How can I capture a dtmf code on for a call sent out of twilio?如何为从 twilio 发出的呼叫捕获 dtmf 代码?
【发布时间】:2017-06-28 01:22:31
【问题描述】:

我通过构建一个包含 twiml 标记的 html 文件来发送呼叫,并使用 php lib 将呼叫置于拨出号码(参见例如)

$tw_call = $twilio_client->calls->create(
        "+1".$recipient['address'], "+1".$org['twilio_number'], 
        array(
            'Url' => VOICE_CALL_LINK.'/'.$file, (this contains the SAY verbs and text)
            'Timeout' => '30',
            'StatusCallback' => CALLBACK_LINK.'/voice_call_handler.php',
            'StatusCallbackEvent' => array('initiated', 'ringing', 'answered', 'completed')
            )

我想知道是否可以通过我用来拨打电话的方法记录来自呼叫接收方的 dtmf 代码?

可以在文本文件中放置额外的回调 url 吗?如果是这样,我将如何捕获返回的呼叫?调用 sid 是否可用于文本文件中可能的回调 url?

好吧,我一定是错过了什么。我尝试了以下方法:

<Response>
    <Pause length='1'/>
    <Say voice='alice'>$intro</Say>
    <Pause length='1'/>
    <Say voice='alice'>$msg_body</Say>
    <Pause length='1'/>
    <Gather action='absolute html path' numDigits='1'>
        <Say Please respond by selecting 1 for I can come.  Select 2 for I cannot come.</Say>
    </Gather>
</Response>";

我从 Twilio 返回“发生应用程序错误”。如果我删除 Gather 标签中的 Gather 标签和 Say 标签,我会接到一个完美的电话。

如果我留下标签并删除操作和路径,也会发生同样的错误。

您可以收集外拨电话的回复吗?我问是因为所有 twilio 文档都提到呼入电话。

【问题讨论】:

    标签: twilio dtmf


    【解决方案1】:

    这里是 Twilio 开发者宣传员。

    为了从呼叫中捕获 DTMF 音,您可以使用 &lt;Gather&gt; TwiML 动词。这可能会进入包含您在上面代码中指向的&lt;Say&gt; 的文件中。 &lt;Say&gt; can be nested within &lt;Gather&gt; 以便您在用户开始输入时询问用户输入并开始输入。

    TwiML 可能如下所示:

    <Response>
      <Gather action="/gather_result.php" numDigits="1">
        <Say>Welcome to the free beer hotline, dial 1 for free beer, dial 2 for other beverages.</Say>
      </Gather>
    </Response>
    

    然后,当用户拨打号码时(您可以使用numDigits 属性控制多少个号码),Twilio 将向action 属性中的 URL 发出请求。在该请求中将有一个Digits parameter,其中将包含用户按下的数字。调用 SID 也将包含在参数中。

    让我知道这是否有帮助。

    【讨论】:

    • 这是意识流评论吗? :D 你找到 action 属性了吗?就像我在答案中的代码示例一样,它需要一个 URL。
    • 然后发生了什么?如果更简单,您可以更新您的问题。
    • 更新了我的问题。返回键让我进入这些评论区。
    • 认为可能是这种情况 :D 你能检查一下你的Twilio debugger,看看你添加 Gather 时报告的错误是什么吗?
    • 完全没有报错。最近的错误或警告来自昨天。
    【解决方案2】:

    我遇到了类似的问题,即 Gather TwiML 没有从 twilio 发出的调用中捕获用户 dtmf 输入。由于某些原因,它未能捕获我的输入数字。我确实按了 1#,但语音消息一直在播放并重复相同的消息。有时它可以工作并且 twilio 能够获取我输入的数字,但是我尝试了超过 80% 的时间,它未能捕获输入的数字。下面是 node js 中的 TwiML 的样子:

    var promise = new Parse.Promise();
    
    twilioClient.calls.create({
        to: phoneNumber,
        from:'+6598124124',
        url: hosturl + '/gather_user_dial',
        body: callParam,
        statusCallback: hosturl + '/callback_user',
        statusCallbackMethod: 'POST',
        statusCallbackEvent: ["completed", "busy", "no-answer", "canceled", "failed"]
    }).then(function(call) {
        if (res) res.success(call);
        promise.resolve(call);
    }, function(error) {
        console.error('Call failed!  Reason: ' + error.message);
        if (res) res.error(error);
        promise.reject(error);
    });
    
    app.post('/gather_user_dial', (request, response) => {
      const twiml = new VoiceResponse();
    
      const gather = twiml.gather({
        numDigits: 1,
        timeout: 5,
        actionOnEmptyResult: true,
        action: '/gather',
      });
      gather.say('You are receiving a call from company A because you press the emergency button. Press 1 if you are okay or Press 9 if you need help, followed by the pound sign.');
    
      twiml.redirect('/gather_user_dial');
      response.type('text/xml');
      response.send(twiml.toString());
    });
    
    app.post('/gather', (request, response) => {
      const twiml = new VoiceResponse();
      if (request.body.Digits) {
        switch (request.body.Digits) {
          case '1':
            twiml.say('User has been notified!');
            userPressOne(request.body.Called);
            break;
          case '9':
            twiml.say('User has been notified!');
            userPressNine(request.body.Called);
            break;
          default:
            twiml.say("Sorry, I don't understand that choice.").pause();
            twiml.redirect('/gather_user_dial');
            break;
        }
      } else {
          twiml.redirect('/gather_user_dial');
      }
      response.type('text/xml');
      response.send(twiml.toString());
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-20
      • 1970-01-01
      相关资源
      最近更新 更多