Twilio 在暂停时检索呼叫

Twilio retrieve call on hold back

在我的应用程序中,我需要执行 Twilio 保持和取回呼叫。我研究并得到了这个link:https://www.twilio.com/docs/api/rest/change-call-state

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;
    }
} 

我尝试拨打我的手机 phone,接听电话并点击保持按钮。我浏览器中的通话已结束,而我 phone 中的通话未结束(我可以在 phone 中听到等待音乐)。当我再次单击拨号盘中的保留按钮时,应该会恢复呼叫。我怎样才能做到这一点?

谁能帮我做这个?提前致谢。

这里是 Twilio 开发人员布道者。

这里的问题是,当您更新第一个呼叫以重定向到保持音乐时,会断开另一个呼叫并结束它。

这可能是因为您的 TwiML ends after the <Dial> that connected the two calls in the first place. You can keep a call going by either adding more TwiML after the or using the action attribute.

如果相反,您的 Twilio 客户端调用部分具有以下 TwiML:

<Response>
  <Dial action="/holding">NUMBER_TO_DIAL</Dial>
</Response>

端点 /holding 看起来像:

<Response>
  <Say>You have a caller on hold.</Say>
  <Redirect>/holding</Redirect>
</Response>

那么你的通话不会结束。相反,它会没完没了地说 "You have a caller on hold"。不过,您可以根据自己的喜好实施。

现在,不是将呼叫者在另一端发送到“http://demo.twilio.com/docs/voice.xml" you should place them in a queue 以等待检索。因此,您需要在 /place-on-hold 处更新另一个端点按下保持按钮时调用。这需要 TwiML:

<Response>
  <Enqueue waitUrl="SOME_HOLD_MUSIC">ADMIN_ID</Enqueue>
</Response>

如果您使用让用户待命的管理员的 ID,那么如果您有多个 Twilio 客户端拨号器用户,那么他们每个人都会有自己的等待队列。

最后,您需要重新连接来电者。为此,您需要再次使用 REST API 将您的管理员从他们的保持模式中重定向到某些将 dial their hold queue 重新连接呼叫者的 TwiML 上。 TwiML 看起来像:

<Response>
  <Dial action="/holding">
    <Queue>ADMIN_ID</Queue>
  </Dial>
</Response>

这将使保持的呼叫者出队并重新连接。请注意,我们还包括 action 属性,以便可以再次将用户置于保持状态。

如果这有帮助,请告诉我。