douyao6842
douyao6842
2016-02-10 02:58
浏览 39

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
    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>
    
    点赞 评论

相关推荐