如何在以下初学者TwiML代码中调试“应用程序错误”语音提示?

时间:2015-01-30 19:38:09

标签: php error-handling 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>';
?>

当我拨入我的模拟账户时,它会成功完成整个第一个脚本。但在按下&#39; 1&#39;或者&#39; 2&#39;它只是说&#34;抱歉应用程序遇到了错误。&#34;谁能发现我的错误?

1 个答案:

答案 0 :(得分:0)

Twilio福音传教士在这里。

有许多调试技巧:

  1. 检查App Monitor以查看Twilio在尝试向您的网站发出请求时捕获的内容。通常这会给你足够的信息来弄清楚发生了什么。 App Monitor还允许您“重放”发送与原始参数相同的参数的各个webhook请求,以帮助您诊断故障。

  2. 尝试在浏览器中加载PHP文件或使用FiddlerPostman等工具来模拟Twilio请求的HTTP请求。这可以让你锻炼你的代码,像Twilio一样向他们发出HTTP请求,但是你可以看到你的应用发送的响应。

  3. 希望有所帮助。