Php Twilio电话,并根据客户的反应进行相应的工作

Php Twilio电话,并根据客户的反应进行相应的工作,php,xml,twilio,Php,Xml,Twilio,我正在使用TwilioAPI。我的要求是打电话给客户。 1.客户接到电话后会听到一些短信。文字信息如下:“按1呼叫客户端,按2呼叫帮助热线,按3再次收听信息等”。 我可以分开做。我可以通过“收集标签”接收客户按下的键,但我不能再进一步了 下面是代码 $call = $client->account->calls->create($number, $sender_number, 'http://www.mysiteurl.com/outbound.xml', array(

我正在使用TwilioAPI。我的要求是打电话给客户。 1.客户接到电话后会听到一些短信。文字信息如下:“按1呼叫客户端,按2呼叫帮助热线,按3再次收听信息等”。 我可以分开做。我可以通过“收集标签”接收客户按下的键,但我不能再进一步了

下面是代码

$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=>
在one.xml中

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

+1234567890
谢谢您打电话给客户。希望您喜欢这个电话。再见

这里是Twilio开发者福音传道者

这里有几件事

我打赌,$\u 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

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