To add to David’s suggestion, you’d need a main queue, and individual queues for each member. When they log in or out, they would need added or removed from both queues.
You already have setinterfacevar=yes (or 1 works too), so now you just need a table to populate.
CREATE TABLE IF NOT EXISTS queue_log
(
queue_clid
varchar(64) NOT NULL,
queue_name
varchar(128) DEFAULT NULL,
queue_start
datetime DEFAULT NULL,
queue_stop
datetime DEFAULT NULL,
queue_stop_type
varchar(1) DEFAULT NULL,
queue_agent_phone
varchar(64) DEFAULT NULL,
KEY queue_clid
(queue_clid
,queue_start
,queue_stop
),
KEY queue_stop_type
(queue_stop_type
),
KEY queue_name
(queue_name
),
KEY queue_agent_phone
(queue_agent_phone
)
) ENGINE=MyISAM
Here’s some dialplan code with pseudo code for the parts you could use…
[queues]
;Queues
exten => s,1,Answer
same => n,Set(queueid=${ARG1})
same => n,Set(currtime=${STRFTIME(${EPOCH},%Y-%m-%d %H:%M:%S)})
;Check for agents logged in to the queue
same => n,Set(acount=${QUEUE_MEMBER(${queueid},count)})
same => n,GoToIf($["${acount}" > “0”]?agentexists)
same => n,Festival(Play closed message)
same => n,GotoIf($["${vmbox}" != “”]?vm)
;;;Do a database lookup to see if you find a call within whatever timeframe
;;;you’re looking for, and get the agent who answered. Change ${ARG1} to that queue.
;;;You may also want to keep a login/logout log of agents, but that’s a separate discussion
same => n(agentexists)…
;;;
same => n,Set(ODBC_WRITESQL()=insert into queue_log (queue_clid,queue_name,queue_start) values(’${CALLERID(num)}’,’${queueid}’,’${currtime}’))
same => n,Queue(${ARG1},queue_log.php)
same => n,Hangup()
same => n(vm),Voicemail(${vmbox}@from-internal-sip,us)
same => n,Hangup()
exten => i,1,Hangup()
exten => t,1,Hangup()
exten => h,1,Set(currtime=${STRFTIME(${EPOCH},%Y-%m-%d %H:%M:%S)})
same => n,Set(ODBC_WRITESQL()=UPDATE queue_log set queue_stop=’${currtime}’,queue_stop_type=‘h’ where queue_clid=’${CALLERID(num)}’ and queue_stop IS NULL)
same => n,Hangup()
And an AGI script to update the agent channel when they answer a call.
/var/lib/asterisk/agi-bin/queue_log.php
#!/usr/bin/php -q
<?php
$agivars = array();
while (!feof(STDIN)) {
$agivar = trim(fgets(STDIN));
if ($agivar === '') {
break;
}
$agivar = explode(':', $agivar);
$agivars[$agivar[0]] = trim($agivar[1]);
}
extract($agivars);
$stdin = fopen('php://stdin', 'r');
$stdout = fopen( 'php://stdout', 'w' );
$currtime = date('Y-m-d H:i:s');
mysql_connect("localhost", "dbusername", "dbpassword");
mysql_select_db("asterisk") or die( "Unable to select database");
$memberinterface = execute_agi("GET VARIABLE MEMBERINTERFACE");
$sql = "UPDATE queue_log set queue_stop = '$currtime', queue_stop_type = 'a', queue_agent_phone='$memberinterface' where queue_clid='$agi_callerid' and queue_stop IS NULL";
mysql_query($sql);
mysql_close();
exit;
function execute_agi($command) {
GLOBAL $stdin, $stdout;
fputs( $stdout, $command . "\n" );
fflush( $stdout );
$resp = trim(fgets( $stdin, 4096 ));
$exp = explode('(', $resp);
$ext = str_replace(')','', $exp[1]);
return $ext;
}
?>
When a caller hits the queue, an entry is added to the queue_log table. When an agent answers, it updates that record with the stop time and agent channel. If that same callerid calls back later in the day, you should be able to query the database to find who answered the call, and which queue they’re logged in to, then send the call to that queue (as long as the agent is still logged in), else, send them to the main queue.
I like the concept, and may introduce it to our helpdesk. The downside is that if you get a lot of repeat calls, and one of your agents gets most of them, the queue could start to stack up while other agents are stilling idle.