php - 如何在以下初学者TwiML代码中调试 “Application Error”语音提示?

标签 php error-handling twilio twilio-twiml

我有一个非常基本的应用程序,在该应用程序中,用户受到欢迎,并且可以选择1或2,然后发送给回叫脚本。每当我通过第一个菜单时,它就会给我一个“应用程序遇到错误”消息。

我的脚本如下:

    <?php

    // make an associative array of callers we know, indexed by phone number
    $people = array(
        "+15559990000"=>"A"  );

    // if the caller is known, then greet them by name
    // otherwise, consider them just another caller
    if(!$name = $people[$_REQUEST['From']])
        $name = "caller";

    // now greet the caller
    header("content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>

    <Gather action="process.php" numDigits="1">
        <Say>Hello <?php echo $name ?>. Welcome to Choons by Yo-say.</Say>
        <Say>To continue as <?php echo $name ?>, press 1.</Say>
        <Say>If you are using a different number but would like to access your account, press 2</Say>
    </Gather>
    <!-- If customer doesn't input anything, prompt and try again. -->
    <Say>Sorry, I didn't get your response.</Say>
</Response>

因此process.php脚本如下所示:
<?php
    header('Content-type: text/xml');
    echo '<?xml version="1.0" encoding="UTF-8"?>';

    echo '<Response>';

    # @start snippet
    $user_pushed = (int) $_REQUEST['Digits'];
    # @end snippet

    if ($user_pushed == 1)
    {
        echo '<Say>You pressed 1</Say>';
    }

    if ($user_pushed == 2) 
    {
        echo '<Say>You pressed 2</Say>';
    }
    else {
        // We'll implement the rest of the functionality in the 
        // following sections.
        echo "<Say>Sorry, I can't do that yet.</Say>";
        echo '<Redirect>mine-or-not.php</Redirect>';
    }

    echo '</Response>';
?>

当我拨入模拟账户时,它将成功通过整个第一个脚本。但是在按下“1”或“2”时,它只是说“对不起,应用程序遇到错误。”谁能发现我的错误?

最佳答案

Twilio的传播者在这里。

有许多调试技巧:

  • 检查App Monitor,以查看Twilio在尝试向您的网站发出请求时捕获的内容。通常,这将为您提供足够的信息以找出正在发生的情况。 App Monitor还允许您“重播”单个Webhook请求,这些请求发送与原始Webhook请求相同的参数,以帮助您诊断故障。
  • 尝试在浏览器中加载PHP文件,或使用FiddlerPostman之类的工具来模拟Twilio请求的HTTP请求。这将使您可以执行代码,就像Twilio一样向它们发出HTTP请求,但是您可以看到应用程序发送的响应。

  • 希望能有所帮助。

    关于php - 如何在以下初学者TwiML代码中调试 “Application Error”语音提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28243362/

    相关文章:

    PHPExcel - 如何逐行读取 Excel 工作表

    angular - 如何使用rxjs运算符多次获取最新值

    xamarin.ios - 适用于 Xamarin.iOS 和 Xamarin.Android 的 Twilio 语音包

    php从json向mysql插入数据运行速度太慢

    php - codeigniter db->delete() 总是返回 true 吗?

    objective-c - null,nill是Objective-C中的字符串类型

    ios - 允许 iOS 应用程序用户通过 Twilio 号码、Parse 后端相互调用电话和发短信

    python - Django + Rest 框架 + twilio : Getitng status call back sid

    php - MYSQL 根据其他两个表中的结果总和过滤表

    java - Google App Engine的自定义异常(exception)消息格式-Java