Twilio IVR用户输入处理问题

时间:2016-07-06 17:33:16

标签: php twilio

感谢您花时间阅读我的帖子。我试图设置一个IVR来测试我的一个客户帐户,处理工作时间以外的来电等。我是Twilio和PHP的新手。

这是XML代码,似乎运行正常:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Gather action="handle-user-input.php" numDigits="1">
    <Say voice="woman">Welcome to COMPANY.</Say>
    <Say voice="woman">In order to further assist you. Please listen to the following:</Say>
    <Say voice="woman">For an option, please press 1.</Say>
    <Say voice="woman">For a different option, please press 2.</Say>
    <Say voice="woman">To speak with another person, please press 3.</Say>
    <Say voice="woman">For all other inquiries, please press 4.</Say>
  </Gather>
  <!-- If they didnt put an input say this then retry -->
  <Say voice="woman">Sorry, I didn't get your response.</Say>
  <Redirect>http://www.exampleforstackoverflow.com/handle-incoming-call.xml</Redirect>
</Response>

因此,如果您要调用指向此xml文件的twilio数字,则会播放语音选项并且它似乎正常工作。如果您要按输入 - 您将收到应用程序错误。 handle-user-input.php的PHP文件如下:

<?php
  $dayofweek=date('D');
  $hour=date('H');

  if(($dayofweek!='Sat')&&($dayofweek!='Sun')){
    if(($hour>17)&&($hour<23)){

    //ok time to call

      $ok='1';
    }
  }

  header('Content-type: text/xml');
  echo '<?xml version="1.0" encoding="UTF-8"?>';
  echo '<Response>';
  $user_pushed = (int) $_REQUEST['Digits'];
  if ($user_pushed == 1) {
    echo '<Say voice="woman">Connecting you to, sales.</Say>';
    if($ok!='1'){
      echo '<Redirect>http://twimlets.com/voicemail?Email=info@example.com&Message=http://www.example.com/ftZLg.mp3</Redirect>';
    } else {
        echo '<Dial>+12345678901</Dial>';
    }
  } else if ($user_pushed == 2) {
      echo '<Say voice="woman">Connecting you to some person.</Say>';
      if($ok!='1') {
        echo '<Redirect>http://twimlets.com/voicemail?Email=info@example.com&Message=http://www.example.com/ftZLg.mp3</Redirect>';
      } else {
          echo '<Dial>+12345678901</Dial>';
      }
  } else if ($user_pushed == 3) {
      echo '<Say voice="woman">Connecting you to a person.</Say>';
      if($ok!='1') {
        echo '<Redirect>http://twimlets.com/voicemail?Email=info@example.com&Message=http://www.example.com/ftZLg.mp3</Redirect>';
        } else {
            echo '<Dial>+12345678901</Dial>';
        }
  } else if ($user_pushed == 4) {
      echo '<Say voice="woman">Connecting you to, operator.</Say>';
      if($ok!='1') {
        echo '<Redirect>http://twimlets.com/voicemail?Email=info@example.com&Message=http://www.example.com/ftZLg.mp3</Redirect>';
      } else {
          echo '<Dial>+12345678901</Dial>';
      }
    } else {
        echo "<Say voice="woman">Sorry, You dialed an invalid number.</Say>";
        echo '<Redirect>http://www.exampleforstackoverflow.com/handle-incoming-call.xml</Redirect>';

    }
  echo '</Response>';
?>

我不确定我的php文件中是否有错误,也许有。但是,我注意到在我的Twilio错误日志中,我发现请求超时访问该文件。换句话说,当Twilio试图访问它时,http://example.com/handle-user-input.php给出了错误500.

无论如何,感谢您花时间阅读我的帖子。如果有人对我的错误有所了解,那就太棒了!

1 个答案:

答案 0 :(得分:2)

你有一个echo的双引号: echo“抱歉,您拨打了无效号码。”;

将其更新为

echo '<Say voice="woman">Sorry, You dialed an invalid number.</Say>';

我从php返回这个(没有发布数字等):

<?xml version="1.0" encoding="UTF-8"?> <Response> <Say voice="woman">Sorry, You dialed an invalid number.</Say> <Redirect>http://www.exampleforstackoverflow.com/handle-incoming-call.xml</Redirect> </Response>

如果您不熟悉PHP,请查看将进行语法检查的IDE或某种代码验证(如http://phpcodechecker.com/)进行一次性检查。

如果您有权访问,您还可以通过以下方式打开PHP服务器上的错误报告: How do I get PHP errors to display?