2

I have a very basic application where a user is greeted and has the option to select 1 or 2 and be sent to a call back script. It's giving me an "Application has encountered an error" message whenever I pass the first menu.

My script is as follows:

    <?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>

So the process.php script looks like this:

<?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>';
?>

When I dial into my demo account it goes through the whole first script successfully. But on pressing '1' or '2' it just says "Sorry the application has encountered an error." Can anyone spot my mistake?

Razib
  • 10,965
  • 11
  • 53
  • 80
Tendi
  • 1,343
  • 2
  • 10
  • 11
  • I think that part is right though, because when i put my name and number in the array, it does call me by name. – Tendi Jan 30 '15 at 19:43
  • So the scripts are from the Twilio Demo Apps and beginner guides. Both scripts are slightly altered versions of: https://www.twilio.com/docs/quickstart/php/twiml/greet-caller-by-name and https://www.twilio.com/docs/howto/ivrs-the-basics – Tendi Jan 30 '15 at 19:50

1 Answers1

0

Twilio evangelist here.

There are number of debugging tips:

  1. Check the App Monitor to see what Twilio is capturing when it tries to make requests to your website. Frequently this will give you enough info to figure out whats happening. App Monitor also lets you "replay" individual webhook requests sending the same parameters as the original to help you diagnose failures.

  2. Try loading your PHP files in a browser or use a tool like Fiddler or Postman to simulate the HTTP requests Twilio requests. This will let you exercise your code, making HTTP requests to them just like Twilio does, but you can see the response sent by your app.

Hope that helps.

Devin Rader
  • 10,260
  • 1
  • 20
  • 32