Move agents automatically from pause to ready

All installation and configuration problems and questions

Moderators: gerski, enjay, williamconley, Op3r, Staydog, gardo, mflorell, MJCoate, mcargile, Kumba, Michael_N

Move agents automatically from pause to ready

Postby ccabrera » Fri Sep 25, 2015 2:34 pm

Hello,

I´ve found the following settings inside the campaign detail config:

Dead Call Max Seconds:
Dead Call Max Status:
Dispo Call Max Seconds:
Dispo Call Max Status:
Agent Pause Max Seconds:

These allow me to automatically pause or log out agents when then surpass the maximum configurable time. However, the need is that agents who spend too much time on pause/dead be put as READY again automatically.

I understand this can cause calls to DROP if noone is paying attention to the screen, but as many of you know, this is what the client wants.

I was thinking about creating a script which reads the vicidial_live_agents table, checks for the time conditions and if needed, sends an AGENT API request so that agents hang up their calls, dispositions are made and then becore READY again.

Is there an easier way to do this? Maybe a setting I don´t know about?

Regards,
Christian Cabrera
Enlaza Comunicaciones - Vicidial Partner
Mexico City
ccabrera
 
Posts: 153
Joined: Fri Jan 14, 2011 7:53 pm
Location: Mexico City

Re: Move agents automatically from pause to ready

Postby mflorell » Fri Sep 25, 2015 2:49 pm

What you described is probably what you would have to do to make that happen. There is no easier way to have an agent automatically go READY from PAUSE state without the agent clicking to resume or an Agent API command being sent.
mflorell
Site Admin
 
Posts: 18384
Joined: Wed Jun 07, 2006 2:45 pm
Location: Florida

Re: Move agents automatically from pause to ready

Postby ccabrera » Fri Sep 25, 2015 3:09 pm

Thank you Matt. I just wanted to know if there was a config option that would do this, but since there isn´t, I´ll create my own.

Regards,
Christian Cabrera
Enlaza Comunicaciones - Vicidial Partner
Mexico City
ccabrera
 
Posts: 153
Joined: Fri Jan 14, 2011 7:53 pm
Location: Mexico City

Re: Move agents automatically from pause to ready

Postby ccabrera » Fri Sep 25, 2015 6:42 pm

Hello again,

Following the order of ideas of the previous post, I created a PHP script which does the required work. It may need some alterations, but I´m leaving it here so anyone can use it:

Code: Select all
#!/usr/bin/php -q
<?php
/***
 *   The purpose of this script is to force agents to become ready when certain conditions are met (e.g. too much time in PAUSE or DEAD calls)
        Just save it anywhere and run it from command line or crontab.
 
             Author: Christian Cabrera (christian AT enlaza DOT mx)
     Last modify date: 2015-09-25
 */

 
// **************
// Config options
// **************

// API authentication
$vici_api_server    = '127.0.0.1';
$vici_api_user      = 'apiuser';
$vici_api_pass      = 'apipass';
$vici_api_url      = "http://$vici_api_server/agc/api.php?source=api&user=$vici_api_user&pass=$vici_api_pass";

// Database authentication
$db_server         = '127.0.0.1';
$db_dbname         = 'asterisk';
$db_user         = 'cron';
$db_pass         = '1234';


// WHERE conditions. You can add as many as you want to the array and they will be glued together using 'OR'.
// We recommend you enclose each in ( ) to avoid syntax errors
// WARNING: DO NOT LEAVE EMPTY OR YOU MAY HANGUP ALL YOUR CALLS!

// Match agents with more than 30 secons inside an unspecified pause code (e.g. Click pause, leave their seat and don´t select a code)
$where_clauses[]    = "(status = 'PAUSED' AND last_state_change <= ADDDATE(NOW(),INTERVAL -10 SECOND) AND pause_code = '')";
// Match agents inside dead calls who haven´t selected a disposition status for more than 15 seconds
$where_clauses[]   = "(status = 'DEAD' AND last_state_change <= ADDDATE(NOW(),INTERVAL -15 SECOND)) ";


// What to do if conditions are met
$api_disposition_status = 'DISMX';      // Disposition status to set
$api_force_pause_code   = 'BRK';      // What pause code to use when agents do not enter one. Be sure to use a valid pause code.
// Echo everything we do.
$debug            = TRUE;

// Enable test mode. Do not submit any API events. Useful for testing if your queries are OK before going live
$test            = FALSE;



/*   END OF CONFIGURATION.
   DO NOT CHANGE ANYTHING BELOW THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING
*/


// First we check to see which agents are in the need to be logged out
if (!$db = mysql_connect($db_server,$db_user,$db_pass))
   die('Cannot connect to the database: ' . mysql_error());

if (!mysql_select_db($db_dbname))
    die('Unable to select database: ' . mysql_error());
   
$queryBase = "SELECT user,`status`,pause_code,UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(last_state_change) AS last_change_secs FROM vicidial_live_agents WHERE %s";
$query = sprintf($queryBase,implode(' OR ',$where_clauses));
if ($debug)
   echo "Query: $query\n";
$result = mysql_query($query,$db);

if (!$result)
   die("Could not run query ($query) from DB: " . mysql_error());
elseif (mysql_num_rows($result) == 0) {
   echo "No agents found. Exiting.";
   exit;
}

// Here´s the query result
$agents = $rows = array();
while ($row = mysql_fetch_assoc($result))
   $agents[] = $row;
if ($debug) {
   echo sprintf("Found %d agents matching your conditions.\n",count($agents) );
   print_r($agents);
}

// Now we need to logout all agents that are inside the $agents array.
foreach ($agents as $agent) {
   // First we hangup their calls.
   // EXAMPLE: http://server/agc/api.php?source=test&user=6666&pass=1234&agent_user=1000&function=external_hangup&value=1
   $options = array(
      'function' => 'external_hangup',
      'agent_user' => $agent['user'],
      'value' => 1
   );
   api_call($options,$debug);
   
   // Now we dispose them
   // EXAMPLE: http://server/agc/api.php?source=test&user=6666&pass=1234&agent_user=1000&function=external_status&value=A
   $options = array(
      'function' => 'external_status',
      'agent_user' => $agent['user'],
      'value' => $api_disposition_status
   );
   api_call($options,$debug);
   // In case agent left the pause code option window open, then FORCE a pause code
   if (($agent['status'] == 'PAUSED') && ($agent['pause_code'] == '')) {
      $options = array(
         'function' => 'pause_code',
         'agent_user' => $agent['user'],
         'value' => $api_force_pause_code
      );
      api_call($options,$debug);
   }   
   if ($agent['status'] == 'PAUSED') {
      // In case the agent was just paused (meaning: no calls or disposition to do), just resume them
      // EXAMPLE: http://server/agc/api.php?source=test&user=6666&pass=1234&agent_user=1000&function=external_pause&value=RESUME
      $options = array(
         'function' => 'external_pause',
         'agent_user' => $agent['user'],
         'value' => 'RESUME'
      );
      api_call($options,$debug);
   }   
}


/*
   Create an easy way to call the API.
*/   
function api_call($options) {
   global $vici_api_url,$debug,$test;
   $url = $vici_api_url;
   foreach ($options as $key => $value)
      $url .= '&' . $key . '=' . $value;
   if ($debug)
      echo "API URL: " . $url . "\n";
   if (!$test) {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      $response = curl_exec($ch);
   }
   else
      $response = 'Disable test mode to get real results';
   if ($debug)
      echo "Response: " .$response . "\n";
   return $response;
}
?>


There are $debug and $test variables you can set to TRUE in order for the script to be verbose and don´t change anything (e.g. hangup calls) unless you are ready to try it. I´ve tested it in my lab with very good results. Hopefully it helps someone.
Christian Cabrera
Enlaza Comunicaciones - Vicidial Partner
Mexico City
ccabrera
 
Posts: 153
Joined: Fri Jan 14, 2011 7:53 pm
Location: Mexico City

Re: Move agents automatically from pause to ready

Postby mflorell » Fri Sep 25, 2015 6:47 pm

Thanks for posting!

Could you add this to a new Issue Tracker ticket please?
mflorell
Site Admin
 
Posts: 18384
Joined: Wed Jun 07, 2006 2:45 pm
Location: Florida

Re: Move agents automatically from pause to ready

Postby ccabrera » Fri Sep 25, 2015 11:23 pm

Done! Is ID 0000895
Christian Cabrera
Enlaza Comunicaciones - Vicidial Partner
Mexico City
ccabrera
 
Posts: 153
Joined: Fri Jan 14, 2011 7:53 pm
Location: Mexico City

Re: Move agents automatically from pause to ready

Postby mflorell » Sat Sep 26, 2015 6:58 am

Thank you very much!
mflorell
Site Admin
 
Posts: 18384
Joined: Wed Jun 07, 2006 2:45 pm
Location: Florida

Re: Move agents automatically from pause to ready

Postby donX » Tue Mar 06, 2018 8:45 am

Hi Guys,

This is working when I manually run the script.

Question tho, I'm really new to this and I'm sorry.

How do I trigger this script every hangup event?

Please help!

Thanks,
donX
 
Posts: 50
Joined: Tue May 17, 2016 8:38 am

Re: Move agents automatically from pause to ready

Postby gjorge » Tue Sep 28, 2021 11:38 am

Hi!
Cristian Cabrera, have you noticed that vicidial_live_agents table do not register dead status anymore? i was trying to integrate your code but it doestn work for dead status agents. there is other version of the script?
gjorge
 
Posts: 12
Joined: Mon Dec 04, 2017 1:13 pm

Re: Move agents automatically from pause to ready

Postby ccabrera » Fri Jan 07, 2022 3:42 pm

So far, no there isnt't. However, from all the posible status, DEAD is the easiest to solve since you can use the "Dead Call Max Seconds" in Vicidial to force the end of DEAD status. That way, you can just still focus on DISPO and PAUSED.
Christian Cabrera
Enlaza Comunicaciones - Vicidial Partner
Mexico City
ccabrera
 
Posts: 153
Joined: Fri Jan 14, 2011 7:53 pm
Location: Mexico City

Re: Move agents automatically from pause to ready

Postby covarrubiasgg » Tue Oct 11, 2022 4:10 pm

You can modify the agent.php script so when DEADMX is triggered it does not check the agent_pause checkbox.


It is only changing a 1 to a 0 :mrgreen: but cant remember where I saved that code to create a patch :oops:
covarrubiasgg
 
Posts: 420
Joined: Thu Jun 10, 2010 10:20 am
Location: Tijuana, Mexico


Return to Support

Who is online

Users browsing this forum: No registered users and 152 guests