在我的應用程序中,我需要做Twilio控制和取回呼叫。我研究了這個鏈接:https://www.twilio.com/docs/api/rest/change-call-state。Twilio找回呼叫
的JavaScript
function holdCall() { // hold a call
var callSid = connection.parameters.CallSid;
$.ajax({
url: "http://www.domain.com/phone/phone_ajax.php",
type: 'POST',
data: {
callSid: callSid
},
success: function(data) {
console.log(data);
},
error: function() {
},
complete: function() {
}
});
}
AJAX調用會到這個網頁。
phone_ajax.php
require_once ("http://www.domain.com/phone/phone_api/vendor/autoload.php");
use Twilio\Rest\Client;
use Twilio\Jwt\ClientToken;
// initialize
if ($_POST['callSid']) { // hold a call
$client = new Client($twilioAccountSID, $twilioAuthenticationToken);
$calls = $client->calls->read(
array("ParentCallSid" => $_POST['callSid'])
);
// Loop over the list of calls and echo a property for each one
foreach ($calls as $call) {
// This will return child call sid e.g CA9ccxxxxxxxxxx
$twilioCall = $client
->calls($call->sid)
->update(
array(
"url" => "http://demo.twilio.com/docs/voice.xml",
"method" => "POST"
)
);
echo $twilioCall->to;
}
}
我打過電話到我的手機,拿起電話,並點擊按住按鈕。我的瀏覽器中的通話結束了,手機中的通話沒有結束(我可以聽到手機中有音樂)。當我再次點擊撥號盤上的保持按鈕時,應該恢復調用。我怎樣才能做到這一點?
任何人都可以幫助我做到這一點?提前致謝。
@ Philnash ..我可以用JavaScript客戶端做到這一點..我真的需要TwiML來做到這一點嗎? – Jenz
好吧,如果您正在尋找保持音樂和其他功能來暫停某人,那麼是的,因爲Twilio客戶端只能控制通話的一方。您可以[靜音Twilio客戶端](https://www.twilio.com/docs/api/client/connection#mute)結束,這將阻止主叫方使用客戶端聽取該人的聲音,但讓他們保持沉默。 – philnash
@ Philnash ..我可以怎樣稱呼twiML文件? '$ twilioCall = $客戶 \t \t - >呼叫($呼叫 - > SID) \t \t - >更新( \t \t \t陣列( \t \t \t \t 「URL」=> 「redirect_twiml.xml」, \t \t \t \t 「方法」=> 「POST」 \t \t \t) \t \t);'它是這樣嗎? – Jenz