douyao6842 2016-02-10 02:58
浏览 40
已采纳

Twilio传出呼叫ID

Please i need some help.

I have been reading about this API Twilio , because a have to solve some code that I didn't do.

And it is working on a page in PHP, to make calls to customers. There is a process that runs every often and check the log or cvs and inserts a record in the database with info Twilio.

Ideally, if at the end of the outgoing call, it could be know the unique ID of the call and save it along with some comments.

How can I take the parameters of the client-side call ? or there is other way? (duration, Sid, to, etc)

I already read this, but I don't get it

Thanks!!

https://www.twilio.com/docs/api/rest/making-calls

https://www.twilio.com/docs/api/rest/call

<?php 
require_once('Services/Twilio.php'); // Loads the library
$API_VERSION = '2010-04-01';
$accountSid = 'AC7d3444f83611xxxxxxxxxxxxxxxx';
$authToken  = 'd72d5f036e96abexxxxxxxxxxxxxx';

$capability = new Services_Twilio_Capability($accountSid, $authToken);
$capability->allowClientOutgoing('AP29cb5d9e0dcxxxxxxxxxxxxxxxxxx');
$capability->allowClientIncoming('name');
$token = $capability->generateToken();
//error_log("token is $token");
?>

<script type="text/javascript">     
      Twilio.Device.setup("<?php echo $token; ?>");     
      function call() {         
      params = {"PhoneNumber": $("#number_no").val(), "callerid": $("#callerid").val(), "agent_id": $("#agent_id").val(), "lead_id": $("#lead_id").val()};
      Twilio.Device.connect(params);
      }     
      function hangup() {           
        Twilio.Device.disconnectAll();
        //Twilio.Device.disconnect();
      }       
  </script>

This code is called when you update something

<script>
$(document).ready(function() {

    $('.call_status').change(function()
    {
        var status = $(this).val();
        var rec_val = $(this).parent().find('.rec_val').val();
        var pledge_amt = $('#pledge_amt'+rec_val).val();
        hangup();
    $.ajax({
    url: '<?php echo site_url('agent/agent_status/'); ?>',
    type: 'post',
    data: {'rec_val': rec_val, 'status': status, 'pledge_amt': pledge_amt},
    success:function(resp)
    {
        if(resp)
        {
            window.location.href="<?php echo site_url('agent/call_leads/'); ?>";
            //$('.msg').html("Status Updated Successfully!").fadeOut(5000);

        } else 
            {
             alert('Please check your selected data');
            }
    },
    error:function(resp)
    {
        alert(resp);
    }
    });

    });
    jQuery('.status_update').fadeOut(5000);
});
</script>
  • 写回答

1条回答 默认 最新

  • doucuoyan0426 2016-02-10 14:15
    关注

    Twilio developer evangelist here.

    When you create the call, you get a connection object. The connection object contains all the parameters that you have read about in the REST API documentation regarding making calls. You can get the Call SID (it's unique ID) this way. In the code below, I use the connection object created when placing the call to log out the parameters of the call:

    <script type="text/javascript">     
          Twilio.Device.setup("<?php echo $token; ?>");     
          function call() {         
              params = {"PhoneNumber": $("#number_no").val(), "callerid": $("#callerid").val(), "agent_id": $("#agent_id").val(), "lead_id": $("#lead_id").val()};
              var connection = Twilio.Device.connect(params);
              console.log(connection.parameters);
          }     
      </script>
    

    Let me know if this helps!

    Edit:

    To use this connection in the hangup function you need to save the connection object outside of the scope of the call function. You could do that by defining the currentConnection as a variable outside of the two functions and then setting and using it when the actions take place. See the updated code below (check out the comments for more info):

    <script type="text/javascript">     
          Twilio.Device.setup("<?php echo $token; ?>");
          // define currentConnection here, but don't set it to anything.
          var currentConnection = null;
    
          function call() {         
              params = {"PhoneNumber": $("#number_no").val(), "callerid": $("#callerid").val(), "agent_id": $("#agent_id").val(), "lead_id": $("#lead_id").val()};
              // create and set the currentConnection
              currentConnection = Twilio.Device.connect(params);
              console.log(currentConnection.parameters);
          }
    
          function hangup() {
            console.log("Do stuff with parameters");
            console.log(currentConnection.parameters)
            Twilio.Device.disconnectAll();
    
            // reset currentConnection until the next call is made
            currentConnection = null;
          } 
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料