2015-10-06 48 views
0

我正在使用Twilio API。我的要求是打电话给客户。 1.客户收到来电后会听到一些短信。短信将如下所示:“按1呼叫客户端按2呼叫帮助热线按3再次收听信息等。” 我可以单独做这件事。我可以接受这是由客户通过按下“收集标签是关键,但我不能做进一步。Twilio调用并因此与客户的响应一起工作

下面是代码

$call = $client->account->calls->create($number, $sender_number, 'http://www.mysiteurl.com/outbound.xml', array(
    "Method" => "GET", 
    "StatusCallback" => "http://www.mysiteurl.com/outbound.xml", 
    "StatusCallbackMethod" => "POST", 
    "StatusCallbackEvent" => array("initiated", "ringing", "answered", "completed"), 
    )); 

在outbound.xml

<=Response=> 
    <=Gather action="http://www.mysiteurl.com/outbound.php" method="GET" timeout="20"=> 
    <=Say=>Press 1 to dial the customer's phone number. Press 2 to dial support hotline. Press 3 to listen the message again.</Say> 
    <=/Gather=> 
<=/Response=> 

在出站.PHP

$AccountSid  = "XXXXX"; 
$AuthToken  = "YYY"; 

$client = new Services_Twilio($AccountSid, $AuthToken); 

$response = $_REQUEST['Digits']; 

if($response == 1) 
{ 
    $call = $client->account->calls->create($number, $sender_number, 'http://www.mysiteurl.com/one.xml', array(
    "Method" => "GET", 
    "StatusCallback" => "http://www.mysiteurl.com/test.php", 
    "StatusCallbackMethod" => "POST", 
    "StatusCallbackEvent" => array("initiated", "ringing", "answered", "completed"), 
    )); 

} 

在one.xml

<=Response=> 
    <=Dial=>+1234567890<=/Dial=> 
    <=Say=>Thank you for calling the customer. Hope you enjoy the call. Goodbye<=/Say=> 
<=/Response=> 

回答

0

Twilio开发者布道者在这里。

这里有几件事。

我的赌注,尽管我不确切地知道,$ _REQUEST ['Digits']将返回一个字符串而不是数字。所以我会改变你的条件来检查$response == "1"

为了将呼叫者拨到另一个号码上,您实际上不需要使用REST API,只需返回拨号所需的TwiML即可。所以,你的outbound.php看起来是这样的:

<?php 
    $AccountSid  = "XXXXX"; 
    $AuthToken  = "YYY"; 

    $client = new Services_Twilio($AccountSid, $AuthToken); 

    $response = $_REQUEST['Digits']; 

    if($response == "1") { 
     header("content-type: text/xml"); 
     echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 
     ?> 
     <Response> 
      <Dial><Number><?php echo $number; ?></Number></Dial> 
     </Response> 
     <?php 
    } 
?> 

这将来电转发到$number

相关问题