简体   繁体   中英

Twilio help get callerId to display To in php

I am trying to get the callerid to display To in the xml for the caller id as you can see. How can i do that? What am I doing wrong? I cant seem to get everything right. I need some help I am not that good at coding and I have looked up on the internet how to get most of the stuff but im not able to get my code working. Thanks in advance!

<?xml version='1.0' encoding='UTF-8'?> <TwilioResponse><Call><To>+12017447179</To><ToFormatted>(201) 744-7179</ToFormatted><From>+16463621515</From><FromFormatted>(646) 362-1515</FromFormatted><PhoneNumberSid/><Status>queued</Status><StartTime/><EndTime/><Duration/><Price/><PriceUnit>USD</PriceUnit><Direction>outbound-api</Direction><AnsweredBy/><ApiVersion>2010-04-01</ApiVersion><Annotation/><ForwardedFrom/><GroupSid/><CallerName/></Call></TwilioResponse>


http://gordonbusiness.com/vb_menu.xml


<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action="="/forward_call.php" numDigits="1">
<Play loop="2">https://gordonbusiness.com/studentloan.mp3</Play>
</Gather>
<Say>Sorry, I didn't get your response.</Say>
<Redirect>vb_menu.xml</Redirect>
</Response>

http://gordonbusiness.com/forward_call.php -

Response sent to 2nd URL:
1   $user_pushed = (int) $_REQUEST['Digits'];


<?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
$string_data = "<TwilioResponse>";
$xml = simplexml_load_string($string_data);
$phonenumber == (string) $xml->To;
if ($user_pushed == 1)
{
echo '<Dial callerId=$phonenumber>
<Number>+18552426127</Number>
</Dial>';
}
else if ($user_pushed == 9)
{
echo '<Hangup />';
}

Twilio developer evangelist here.

I think you have most of this right, the bit that is missing is getting the number that was dialled as the caller ID.

You seem to be building the To number out of some anonymous XML structure that you create. You can get the To number from the request parameters. Much like you got the Digits parameter.

So, instead of

$string_data = "<TwilioResponse>";
$xml = simplexml_load_string($string_data);
$phonenumber == (string) $xml->To;

You could just set $phonenumber like:

$phonenumber = $_REQUEST["To"];

Let me know if this helps at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM