查找断开连接时的通话费用? * Twilio API *

时间:2015-12-22 04:41:03

标签: twilio

有没有办法在使用twilio API的电话会议结束时花费在twilio电话上花费的金额?

1 个答案:

答案 0 :(得分:3)

您可以在通话结束时执行脚本。您可以在此脚本中找到该调用的成本。

  • 如果您使用的是REST API,请指定StatusCallback URL,该脚本将在通话结束时执行。 (有关详细信息,请参阅here
  • 如果您使用Dial TwiML拨打电话,请指定action参数。 (有关详细信息,请参阅here

现在在此网址中,您将获得已拨电话的Sid作为参数。使用此调用sid,您可以发出REST API请求以获取该特定调用的详细信息。

<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library
$sid = "{{ACC SID}}"; 
$token = "{{ auth_token }}"; 
$client = new Services_Twilio($sid, $token);

$call_sid = $_REQUEST['DialCallSid']; //if you are using dial
//*************** OR *************
$call_sid = $_REQUEST['CallSid']; //if you are using REST API

//Get the details of the call using rest API from the call_sid
$call = $client->account->calls->get($call_sid);

$price = $call->Price; //get the cost of the call
$price_usit = $call->PriceUnit; // get the currency in cost is charged

?>

请注意,twilio可能需要一些时间来填充这些值。因此,如果您没有获得正确的值,请在请求呼叫资源之前尝试休眠。

相关问题