gpt4 book ai didi

php - 如何知道 twilio 通话状态(完成与否)

转载 作者:可可西里 更新时间:2023-11-01 13:51:05 26 4
gpt4 key购买 nike

我是 twilio api 的新手。在正在处理的 Web 应用程序中,我必须检查调用是否完成,并且我正在将 wav 文件发送到 twiml。如果完成我必须扣除用户的信用..我正在使用以下代码......

callMeAction

        $AccountSid = "**********************";
$AuthToken = "***************";

/* Your Twilio Number or an Outgoing Caller ID you have previously validated
with Twilio */
$from = '**************';

/* Number you wish to call */
$to = $_POST['contactno'];

/* Directory location for callback.php file (for use in REST URL) */
$url = 'http://'.$_SERVER['HTTP_HOST'].'/public/';

/* Instantiate a new Twilio Rest Client */
$client = new Services_Twilio($AccountSid, $AuthToken);



/* make Twilio REST request to initiate outgoing call */
$call = $client->account->calls->create($from, $to, $url . 'callback.php?number=' . $_POST['contactno'] . '&wav=' . $_POST['wav']);

/* redirect back to the main page with CallSid */
$msg = urlencode("Connecting... " . $call->sid);
//header("Location: index.php?msg=$msg");

$this->view->msg = $msg;

if($call->status == 'COMPLETED'){

/*
* Deduct credit if call completed
*/


$this->view->msg = $msg;
}

回调.php

<?php
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>



<?php if($_REQUEST['wav']){ ?>
<Response>
<Say>A customer at the number <?php echo $_REQUEST['number']?> is calling</Say>
<Dial><?php echo $_REQUEST['number']?></Dial>
<Play><?php echo $_REQUEST['wav'] ;?></Play>
</Response>
<?php } ?>

请帮帮我...提前致谢。 :)

最佳答案

StatusCallback (docs halfway down this page) 设置一个 URL ,并将您的收费逻辑放入该脚本中。

您在创建调用时传递 StatusCallback URL,您应该能够将可选参数数组作为第四个参数传递给:$client->account->calls->create() .

对于来电,URL 是(可选)为每个号码(或应用程序,如果您使用该方法)定义的。

关于php - 如何知道 twilio 通话状态(完成与否),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8397147/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com