Php 当代理连接到客户端时,从Twilio获取调用参数,如CallSid

Php 当代理连接到客户端时,从Twilio获取调用参数,如CallSid,php,angularjs,twilio,Php,Angularjs,Twilio,在我的应用程序中使用PHP和angular/javascript:我的工作流的设置方式是代理自动连接到一个名为“支持”的队列。当客户端调用时,它们将连接到支持队列中的第一个代理。当代理连接到客户端时,如何获取调用参数(如CallSid) 这是前端代码: $(document).ready(function(){ Twilio.Device.setup("<?php echo $twilioObj->token->generateToken();?>

在我的应用程序中使用PHP和angular/javascript:我的工作流的设置方式是代理自动连接到一个名为“支持”的队列。当客户端调用时,它们将连接到支持队列中的第一个代理。当代理连接到客户端时,如何获取调用参数(如CallSid)

这是前端代码:

$(document).ready(function(){
            Twilio.Device.setup("<?php echo $twilioObj->token->generateToken();?>");
            var connection=null;
            Twilio.Device.ready(function (device) {
                $('#status').text('Ready to start call');
            });
            Twilio.Device.incoming(function (conn) {
                if (confirm('Accept incoming call from ' + conn.parameters.From + '?')){
                    connection=conn;
                    conn.accept();
                }
            });
            Twilio.Device.offline(function (device) {
                $('#status').text('Offline');
            });
            Twilio.Device.error(function (error) {
                $('#status').text(error.message);
            });
            Twilio.Device.connect(function (conn) {
                $('#status').text("Successfully established call");
                toggleCallStatus();
                console.log(conn.parameters.CallSid);
            });
            Twilio.Device.disconnect(function (conn) {
                $('#status').text("Call ended");
                toggleCallStatus();
            });
            function toggleCallStatus(){
                $('#call').toggle();
                $('#hangup').toggle();
                $('#dialpad').toggle();
            }
            $.each(['0','1','2','3','4','5','6','7','8','9','star','pound'], function(index, value) { 
                $('#button' + value).click(function(){ 
                    if(connection) {
                        if (value=='star')
                            connection.sendDigits('*')
                            else if (value=='pound')
                                connection.sendDigits('#')
                                else
                                    connection.sendDigits(value)
                                    return false;
                    }
                });
            });
        });
        function call() {
            // get the phone number to connect the call to
            var value=$.trim($("#tocall").val());
            if( value== false){
                params = {"tocall": "queue"};
                Twilio.Device.connect(params);
            }else{
                params = {"tocall": $("#tocall").val()};
                Twilio.Device.connect(params);
            }

        }
        function hangup() {
            Twilio.Device.disconnectAll();
        }
        function transfer() {
        }
        function sms() {
            params = {'tosms': $('#tosms').val(), 'sms': $('input[name=smsRadio]:checked', '#smsRadios').val()};
            $.post( "twilioApps/sms", params );
        }
        function conference() {
            // get the phone number to connect the call to
            params = {"toconference": $("#toconference").val()};
        }
$(文档).ready(函数(){
Twilio.Device.setup(“”);
var连接=null;
Twilio.设备准备就绪(功能(设备){
$(“#状态”).text('Ready to start call');
});
Twilio.设备输入(功能(连接){
如果(确认('接受来自'+conn.parameters.from+'的来电?')){
连接=连接;
康涅狄格州接受;
}
});
Twilio.Device.offline(功能(设备){
$('#status')。文本('Offline');
});
Twilio.Device.error(函数(错误){
$('#status').text(error.message);
});
Twilio.设备连接(功能(连接){
$(“#状态”).text(“成功建立呼叫”);
切换CallStatus();
console.log(conn.parameters.CallSid);
});
斜纹装置断开(功能(连接){
$(“#状态”).text(“通话结束”);
切换CallStatus();
});
函数toggleCallStatus(){
$(“#调用”).toggle();
$(“#挂起”).toggle();
$(“#拨号板”).toggle();
}
$。每个(['0'、'1'、'2'、'3'、'4'、'5'、'6'、'7'、'8'、'9'、'star'、'pound']),函数(索引、值){
$('#按钮'+值)。单击(函数(){
如果(连接){
如果(值=='star')
connection.sendDigits(“*”)
如果为else(值='pound')
connection.sendDigits(“#”)
其他的
连接。发送数字(值)
返回false;
}
});
});
});
函数调用(){
//获取要将呼叫连接到的电话号码
var值=$.trim($(“#tocall”).val();
如果(值==false){
params={“tocall”:“queue”};
Twilio.Device.connect(参数);
}否则{
params={“tocall”:$(“#tocall”).val();
Twilio.Device.connect(参数);
}
}
函数挂起(){
Twilio.Device.disconnectAll();
}
函数转移(){
}
函数sms(){
参数={'tosms':$('#tosms').val(),'sms':$('input[name=smsRadio]:checked','#smsRadios').val();
$.post(“twilioApps/sms”,参数);
}
功能会议(){
//获取要将呼叫连接到的电话号码
params={“toconference”:$(“#toconference”).val();
}
下面是Twilio点击拨号的URL:

$twilioObj = new twilioPlugin;
        header('Content-type: text/xml');
        $mongo = new MongoClient();
        $dbsave= $mongo->selectDB('agentPortal')->selectCollection('test');
        foreach($_REQUEST as $a=>$b){
            $datas = array( $a => $b);
        }
        $dbsave->insert($_GET);

        //$dbsave->save($datas);
        // get the phone number from the page request parameters, if given
        if($_REQUEST['tocall'] == 'queue'){
    ?>
    <Response>
        <Dial action="http://example.com/angular2/twilioApps/callend">
            <Queue>
                support
            </Queue>
        </Dial>
    </Response>
    <?php
        }else{
            if(isset($_REQUEST['tocall'])) {
                $twilioObj->number = htmlspecialchars($_REQUEST['tocall']);
            }
            // wrap the phone number or client name in the appropriate TwiML verb
            // by checking if the number given has only digits and format symbols
            if (preg_match("/^[\d\+\-\(\) ]+$/", $twilioObj->number)) {
                $numberOrClient = "<Number>" . $twilioObj->number . "</Number>";
    ?>
    <Response>
        <Dial callerId="<?php echo $twilioObj->callerId; ?>" action="http://example.com/angular2/twilioApps/callend">
            <?php echo $numberOrClient; ?>
        </Dial>
    </Response>
    <?php
            } else {
                //$numberOrClient = "<Client>" . $twilioObj->clientName . "</Client>";
                //}
                /*
    */
    ?>
    <Response>
        <Enqueue>support</Enqueue>
    </Response>
    <?php
            }
        }
$twilioObj=新的twilioPlugin;
标题('Content-type:text/xml');
$mongo=新的MongoClient();
$dbsave=$mongo->selectDB('agentPortal')->selectCollection('test');
foreach($\请求为$a=>$b){
$datas=array($a=>$b);
}
$dbsave->insert($\u GET);
//$dbsave->save($datas);
//从页面请求参数中获取电话号码(如果给定)
如果($_请求['tocall']=='queue'){
?>
支持

你能分享一下你迄今为止实现这一点的代码吗,这样我们就可以用一种有用的方式回答了?谢谢!@philnash,谢谢你的见解。很抱歉回复太慢。你想在这里的应用程序中从哪里获得CallSid?