1

thanks for taking the time to read my post. I was trying to set up an IVR to test on one of my client accounts, to handle incoming calls outside of business hours etc. I am new to Twilio, and PHP in general.

Here is the XML code, it seems to run properly:

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

So, if you were to call the twilio number which is pointed at this xml file, the voice options play and it seems to work properly. If you were to press an input - you would get an application error. The PHP file that is handle-user-input.php is as follows:

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

I'm not sure if there is an error in my php file, maybe there is. However, I noticed that on my Twilio error log, I found that the request timed out to access the file. In other words, http://example.com/handle-user-input.php gave error 500 when Twilio tried to access it.

Anyway, thanks for taking the time to read my post. If anyone has some insight to my mistake that would be awesome!

Megan Speir
  • 3,683
  • 1
  • 11
  • 25
Erik
  • 11
  • 3

1 Answers1

2

You have double quotes on an echo: echo "Sorry, You dialed an invalid number.";

Updating that to

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

And I get this returned from the php (didn't post digits, etc):

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

If you are new to PHP, look into an IDE that will syntax check, or some sort of a code validation like http://phpcodechecker.com/ for one off checks.

If you have access, you can also turn on error reporting on your PHP server by following something like this: How do I get PHP errors to display?

Community
  • 1
  • 1
Progone
  • 176
  • 5