如何在twilio中获取回调状态
如何在twilio中回调状态,例如在php中如何在twilio中获取回调状态,twilio,Twilio,如何在twilio中回调状态,例如在php中 require __DIR__ . '/vendor/autoload.php'; use Twilio\Rest\Client; // Your Account Sid and Auth Token from twilio.com/user/account $sid = "---------------"; $token = "-----------------; $client = new Client($sid, $token); $cal
require __DIR__ . '/vendor/autoload.php';
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "---------------";
$token = "-----------------;
$client = new Client($sid, $token);
$call = $client->calls->create(
$to, $from,
array(
"url" => "http://demo.twilio.com/docs/voice.xml",//this line complete
"method" => "GET",
"statusCallbackMethod" => "POST",
"statusCallback" => "https://www.myapp.com/events", //in this line no idea
"statusCallbackEvent" => array(
"initiated", "ringing", "answered", "completed"
)
)
);
echo $call->sid;
在本例中,如何在呼叫后获取事件您的代码对于从Twilio注册呼叫状态通知是正确的。对于在
statusCallbackEvent
数组中指定的每个事件,Twilio将向statusCallback
参数中指定的URL发出异步HTTP请求。有关更多详细信息,请参阅文章
因此,现在您需要一个位于以下URL的服务:,用于侦听Twilio发送的通知。在您的情况下,这些将是POST请求,给定您在statusCallbackMethod
参数中指定的方法。您需要告知正在通知哪个事件的参数是CallStatus
。有关更多信息,请参阅文档
我们不使用PHP,但如果您想进行快速测试,只需创建一个脚本并将以下代码粘贴到其中即可查看事件通知:
exports.handler = function(context, event, callback) {
let response = { get_started: true };
console.log(`Call status notified was '${event.CallStatus}'.`);
callback(null, response);
};