Bulvak Bulvak - 7 months ago 66
PHP Question

Twilio Call Screening PHP

I tried to run the Call Screening example. When my other phone number received the call, the error message was read "Sorry an error has occurred, please check the debug link." After this error occurred I did not do anything and the call did not hang up. So I pressed a key on my keypad and it connected the call. The call screening app is suppose to call someone and ask if they want to take the call or not. That feature works but I am not sure why it read the error message. Furthermore, after I hung up on my phone receiving the call, the next number was getting a call which should not happen as the 1st phone number picked up the call.

attempt_call.php

<?php

// Set the numbers to call
$numbers = array("<number to call 1>", "<number to call 2>", "<number to call n>");
$number_index = isset($_REQUEST['number_index']) ? $_REQUEST['number_index'] : "0";
$DialCallStatus = isset($_REQUEST['DialCallStatus']) ? $_REQUEST['DialCallStatus'] : "";

header("content-type: text/xml");

// Check the status of the call and
// that there is a valid number to call

if($DialCallStatus!="completed" && $number_index<count($numbers)){
?>
<Response>
<Dial action="attempt_call.php?number_index=<?php echo $number_index+1 ?>">
<Number url="screen_for_machine.php">
<?php echo $numbers[$number_index] ?>
</Number>
</Dial>
</Response>
<?php
} else {
?>
<Response>
<Hangup/>
</Response>
<?php
}
?>


screen_for_machine.php

<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action="complete_call.xml">
<Say>Press any key to accept this call</Say>
</Gather>
<Hangup/>
</Response>


complete_call.xml

<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Connecting</Say>
</Response>


I am looking into it as we speak. I think the error on their site is that they are calling certain files .xml and using it as .php in their code.

Debug link says:

ERROR: HTTP retrieval failure

Component: TwiML errors
httpResponse: 500
ErrorCode: 11200
url: http://test.com.testExample.com/Call/screen_for_machine.php

The error code 11200 reads:

Error - 11200
HTTP retrieval failure

There was a failure attempting to retrieve the contents of this URL
Possible Causes

Web server returned a 4xx or 5xx HTTP response to Twilio
Misconfigured Web Server
Network disruptions between Twilio and your web server


Possible Solutions

Doublecheck that your TwiML URL does not return a 4xx or 5xx error
Make certain that the URL does not perform a 302 redirect to an invalid URL
Confirm the URL requested is not protected by HTTP Auth
Make sure your webserver allows HTTP POST requests to static resources (if the url referes to .xml or .html files)
Verify your web server is up and responsive
Check to see that the URL host is not a private or local IP address
Verify the ping times and packet loss between your web server and www.twilio.com


My analysis goes that there is something wrong with the Screen php file as it does not even read to me the xml saying press any key to pick up..

The error is fixed...The problem was with the

Answer

There's an error in the example we provide. The <?xml version="1.0" encoding="UTF-8"?> line causes issues with PHP, so it needs to be written out like this:

screen_for_machine.php

<?php header("content-type: text/xml"); 
echo '<?xml version="1.0" encoding="UTF-8"?>'; 
?> 
<Response>
<Gather action="complete_call.xml">
<Say>Press any key to accept this call</Say>
</Gather>
<Hangup/>
</Response>