Twilio通过客户

时间:2015-10-06 15:25:37

标签: php xml twilio

我正在使用Twilio API。我的要求是打电话给顾客。 1.客户接到电话后会听到一些短信。短信将是这样的"按1呼叫客户端按2呼叫帮助热线按3再次收听消息等等#34;。 我可以单独做这个。我可以通过" Gather标签接收客户按下的那个键。但我不能做得更远。

以下是代码

$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=>

在outbound.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=>

1 个答案:

答案 0 :(得分:0)

Twilio开发者传道者在这里。

这里有几件事。

我的赌注,虽然我不确切地知道,$ _REQUEST [&#39; Digits&#39;]将返回一个字符串而不是一个数字。所以我会更改条件以检查set fp [open output.txt a] puts $fp "${Var1} ${Var2} ${var3}" close $fp

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

$response == "1"

这会将来电者转发到<?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 } ?>