Twilio取回保留的电话 [英] Twilio retrieve call on hold back

查看:180
本文介绍了Twilio取回保留的电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我需要执行Twilio控制并检索回来的电话。我研究并获得了这个链接: https://www.twilio.com /文档/ API / REST /更改呼叫状态

In my application, I need to do Twilio holding and retrieving back a call. I researched and got this 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调用将转到此页面。

The ajax call will go to this page.

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

我试着打电话给我的手机,拿起了呼叫并单击保持按钮。我的浏览器中的通话已经结束,手机中的通话没有结束(我可以听到手机中的音乐)。当我再次单击拨号盘中的保留按钮时,应该检索该呼叫。我怎样才能做到这一点?

I tried calling to my mobile phone, picked up the call and clicked Hold button. The call in my browser got ended and the call in my phone didn't ended up (I can hear hold music in my phone). When I again click on the Hold button in the dialpas, the call should be retrieved back. How can I achieve this?

任何人都可以帮我这样做吗?在此先感谢。

Can anyone help me to do this? Thanks in advance.

推荐答案

Twilio开发者传播者在这里。

Twilio developer evangelist here.

这里的问题是当你更新第一个电话重定向到保持音乐时断开另一个电话并结束它。

The problem here is that when you update the first call to redirect to the hold music that disconnects the other call and ends it.

这可能是因为你的 TwiML <拨打> ,首先连接两个电话。您可以通过在使用之后添加更多TwiML来保持呼叫。操作属性

This is likely because your 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:

If instead, your Twilio Client leg of the call had the following TwiML:

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

端点 /持有如下所示:

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

然后您的电话将不会结束。它会无休止地说你有一个呼叫者被搁置。你可以实现这个,但你喜欢。

Then your call won't end. It will instead endlessly say "You have a caller on hold". You could implement this however you like though.

现在,而不是将另一端的调用者运送到 http://demo.twilio.com/docs/voice.xml 你应该将它们放入队列中等待检索。因此,您需要另一个端点,例如 / place-on-hold ,您可以在按下保持按钮时更新呼叫。这需要TwiML:

Now, instead of shipping the caller on the other end off to "http://demo.twilio.com/docs/voice.xml" you should place them in a queue to wait to be retrieved. So, you'd need another endpoint at say /place-on-hold which you would update the call to when the hold button is pressed. That would need the TwiML:

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

如果您使用的是管理员的ID,那么如果您有多个用户Twilio Client拨号器然后他们每个都有自己的保持队列。

If you use the ID of the admin who put the user on call then if you have multiple users of the Twilio Client dialler then they will each have their own holding queue.

最后,你需要重新连接呼叫者。为此,您需要再次使用REST API将管理员重定向到其持有模式,并将其重定向到某些TwiML上,该TwiML将拨打他们的保留队列,这将重新连接呼叫者。 TwiML看起来像:

Finally, you need to Reconnect the callers. For this you need to redirect your admin out of their holding pattern using the REST API again and onto some TwiML that will dial their hold queue which will reconnect the callers. The TwiML would look like:

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

这将使呼叫者出局并重新连接。请注意,我们还包含action属性,以便用户可以再次处于暂停状态。

This will dequeue the caller on hold and reconnect. Note we also include the action attribute so that the user can be placed on hold again.

请告诉我这是否有帮助。

Let me know if this helps at all.

这篇关于Twilio取回保留的电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆