Twilio Rejecting Call Using TWIML Webhooks Using PHP

490 views Asked by At

Background: Using webhooks to direct incoming voice call to our application handler which connects the caller to an available reps cell phone.

The first part of the app checks to see if the incoming Caller telephone number is on an internal blacklist (to ignore robo dialers etc) -- if there is a match, our app will reject the call so we do not get billed. This rejection is being done echoing a Reject TWIML verb as follows:

echo '<Response><Reject reason="rejected"/></Response>';
exit;

The code works fine, send the xml response and exits the PHP script, however, the incoming caller doesn't get a "busy" signal or "Not In Service" message -- instead it just hangs in silence.

Additionally, the Twilio webhooks handler keeps firing off calls with the CallStatus = no-answer every approximately 2-seconds until the caller hangs up.

Any idea as to what I am doing wrong?

1

There are 1 answers

0
DanM1966 On

I determined that problem was with the formatting of the xml response being echo out. It turns out that formatting of the XML response needs to preserve format and whitespace, etc of XML (???):

This did not work (twilio will hang in silence until caller hangs up):

echo '<Response><Reject reason="rejected"/></Response>';
exit;

This does work (caller will receive busy signal):

echo '<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Reject reason="busy" />
</Response>';
exit;