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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)