Page when no agents are in queue
First of all, I've been using trixbox CE in a test environment for several weeks now and I feel fairly comfortable with it's ability, but I'm not terribly good at scripting quite yet.
I'm working on building all of our IVRs and queues (ACDs) into the system now and I've run into a snag. One of the features we'd like to include with this system is the ability to have an automated page to a speaker that announces when a call is in a particular queue but no agents are logged in. This feature is available in our existing Dash system (yes, it's quite old) but I can't find any supporting documentation that says it is available with trixbox without any heavy manipulation.
Does anyone have any ideas how this would be possible?
Thanks,
Russell Warren
This is really crude. I was bored and looking for a challenge, so I ripped it together in 15 minutes from code in a couple other of my applications. The gist is it continually asks the manager for the status of queues and the agent members. If a queue has calls in it and no agents logged it, it generates a .call file in /var/spool/asterisk/outgoing that opens an intercom to an extension (defined at the top of the code) and uses Flite to play a message "Queue
Create /var/lib/asterisk/bin/monitor_queues.php:
<?php
// The extension to page
$page_ext = "4002";
require_once "/var/lib/asterisk/agi-bin/phpagi-asmanager.php";
$asm = new AGI_AsteriskManager();
$asm->connect("localhost","admin","amp111");
function auto_dial($channel,$context,$message) {
$call_file = "channel: $channel\n";
if($retries) {
$call_file .= "maxretries: $retries\n";
if($retrytime)
$call_file .= "retrytime: $retrytime\n";
}
$call_file .= "waittime: 30\n".
"application: Flite\n".
"data: $message";
$file = md5(time()).".call";
file_put_contents("/tmp/$file",$call_file);
rename("/tmp/$file","/var/spool/asterisk/outgoing/$file");
}
function asm_event_queues($e, $parameters, $server, $port) {
global $asm;
global $queue_details;
if(sizeof($parameters)) {
if($parameters[Event] = "QueueParams")
$queue_details[] = $parameters;
}
}
function get_queues() {
global $asm;
$asm->add_event_handler("queueparams","asm_event_queues");
$asm->add_event_handler("queuestatuscomplete","asm_event_queues");
$asm->add_event_handler("queuemember","asm_event_queues");
global $queue_details;
while(!$queue_details) {
$asm->QueueStatus();
}
return $queue_details;
}
while(1) {
$queues = get_queues();
$active_queues = array();
for($i = 0; $i < sizeof($queues); $i++) {
if($queues[$i][Calls] > 0) {
$active_queues[$queues[$i][Queue]]['members'] = "inactive";
for($j = 0; $j < sizeof($queues); $j++) {
if($queues[$j][Queue] == $queues[$i][Queue] && $queues[$j][Location]) {
$active_queues[$queues[$j][Queue]]['members'] = "active";
}
}
}
}
while(list($queue_num,$queue) = each($active_queues)) {
if($queue['members'] == "inactive") {
$channel = "Local/*80$page_ext@from-internal";
echo "auto dialed $channel";
auto_dial($channel,"from-internal","Queue $queue_num has a caller without an agent");
}
}
sleep(10);
}
?>
chown asterisk:asterisk /var/lib/asterisk/bin/monitor_queues.php
To run, from the command line: su asterisk -c "php /var/lib/asterisk/bin/monitor_queues.php&"
If you like it, consider contributing to the project that most of the code came from:
http://trixbox.org/forums/vendor-forums-certified/aastra-endpoint...
If you need any further customization, contact me directly to work out a fair deal.
Ethan,
I really appreciate your quick response and effort!
I got this running and it seems to work very well, but it doesn't stop paging after the call drops from the queue (whether the caller hung up or if an agent answered it).
If this further customization requires a bounty, let me know and I'll work something out. You can contact me at rwarren a.t. ibssoftware d.o.t. com.
Thank you,
Russell Warren
Try this:
<?php
// The extension to page
$page_ext = "4002";
require_once "/var/lib/asterisk/agi-bin/phpagi-asmanager.php";
$asm = new AGI_AsteriskManager();
$asm->connect("localhost","admin","amp111");
function auto_dial($channel,$context,$message) {
$call_file = "channel: $channel\n";
if($retries) {
$call_file .= "maxretries: $retries\n";
if($retrytime)
$call_file .= "retrytime: $retrytime\n";
}
$call_file .= "waittime: 30\n".
"application: Flite\n".
"data: $message";
$file = md5(time()).".call";
file_put_contents("/tmp/$file",$call_file);
rename("/tmp/$file","/var/spool/asterisk/outgoing/$file");
}
function asm_event_queues($e, $parameters, $server, $port) {
global $asm;
global $queue_details;
if(sizeof($parameters)) {
if($parameters[Event] = "QueueParams")
$queue_details[] = $parameters;
}
}
function get_queues() {
global $asm;
$asm->add_event_handler("queueparams","asm_event_queues");
$asm->add_event_handler("queuestatuscomplete","asm_event_queues");
$asm->add_event_handler("queuemember","asm_event_queues");
global $queue_details;
while(!$queue_details) {
$asm->QueueStatus();
}
return $queue_details;
}
while(1) {
$queue_details = array();
$queues = get_queues();
$active_queues = array();
for($i = 0; $i < sizeof($queues); $i++) {
if($queues[$i][Calls] > 0) {
$active_queues[$queues[$i][Queue]]['members'] = "inactive";
for($j = 0; $j < sizeof($queues); $j++) {
if($queues[$j][Queue] == $queues[$i][Queue] && $queues[$j][Location]) {
$active_queues[$queues[$j][Queue]]['members'] = "active";
}
}
}
}
while(list($queue_num,$queue) = each($active_queues)) {
if($queue['members'] == "inactive") {
$channel = "Local/*80$page_ext@from-internal";
echo "auto dialed $channel";
auto_dial($channel,"from-internal","Queue $queue_num has a caller without an agent");
}
}
sleep(10);
}
?>


Member Since:
2008-08-11