Skip to content

Instantly share code, notes, and snippets.

@MefhigosetH
Created December 20, 2012 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MefhigosetH/4348203 to your computer and use it in GitHub Desktop.
Save MefhigosetH/4348203 to your computer and use it in GitHub Desktop.
function queues_get_config($engine) in /var/www/html/admin/modules/queues/functions.inc.php @ Elastix 1.6
/* Generates dialplan for "queues" components (extensions & inbound routing)
We call this with retrieve_conf
*/
function queues_get_config($engine) {
global $ext; // is this the best way to pass this?
global $queues_conf;
switch($engine) {
case "asterisk":
if (isset($queues_conf) && is_a($queues_conf, "queues_conf")) {
$queues_conf->addQueuesGeneral('persistentmembers','yes');
}
/* queue extensions */
$ext->addInclude('from-internal-additional','ext-queues');
$qlist = queues_list(true);
if (is_array($qlist)) {
foreach($qlist as $item) {
$exten = $item[0];
$q = queues_get($exten);
$grppre = (isset($q['prefix'])?$q['prefix']:'');
$alertinfo = (isset($q['alertinfo'])?$q['alertinfo']:'');
// Not sure why someone would ever have a ; in the regex, but since Asterisk has problems with them
// it would need to be escaped
//
$qregex = (isset($q['qregex'])?$q['qregex']:'');
str_replace(';','\;',$qregex);
$ext->add('ext-queues', $exten, '', new ext_macro('user-callerid'));
$ext->add('ext-queues', $exten, '', new ext_answer(''));
// block voicemail until phone is answered at which point a macro should be called on the answering
// line to clear this flag so that subsequent transfers can occur.
//
if ($q['queuewait']) {
$ext->add('ext-queues', $exten, '', new ext_execif('$["${QUEUEWAIT}" = ""]', 'Set', '__QUEUEWAIT=${EPOCH}'));
}
$ext->add('ext-queues', $exten, '', new ext_setvar('__BLKVM_OVERRIDE', 'BLKVM/${EXTEN}/${CHANNEL}'));
$ext->add('ext-queues', $exten, '', new ext_setvar('__BLKVM_BASE', '${EXTEN}'));
$ext->add('ext-queues', $exten, '', new ext_setvar('DB(${BLKVM_OVERRIDE})', 'TRUE'));
$ext->add('ext-queues', $exten, '', new ext_execif('$["${REGEX("(M[(]auto-blkvm[)])" ${DIAL_OPTIONS})}" != "1"]', 'Set', '_DIAL_OPTIONS=${DIAL_OPTIONS}M(auto-blkvm)'));
// Inform all the children NOT to send calls to destinations or voicemail
//
$ext->add('ext-queues', $exten, '', new ext_setvar('__NODEST', '${EXTEN}'));
// deal with group CID prefix
// Use the same variable as ringgroups/followme so that we can manage chaines of calls
// but strip only if you plan on setting a new one
//
if ($grppre != '') {
$ext->add('ext-queues', $exten, '', new ext_gotoif('$["foo${RGPREFIX}" = "foo"]', 'REPCID'));
$ext->add('ext-queues', $exten, '', new ext_gotoif('$["${RGPREFIX}" != "${CALLERID(name):0:${LEN(${RGPREFIX})}}"]', 'REPCID'));
$ext->add('ext-queues', $exten, '', new ext_noop('Current RGPREFIX is ${RGPREFIX}....stripping from Caller ID'));
$ext->add('ext-queues', $exten, '', new ext_setvar('CALLERID(name)', '${CALLERID(name):${LEN(${RGPREFIX})}}'));
$ext->add('ext-queues', $exten, '', new ext_setvar('_RGPREFIX', ''));
$ext->add('ext-queues', $exten, 'REPCID', new ext_noop('CALLERID(name) is ${CALLERID(name)}'));
$ext->add('ext-queues', $exten, '', new ext_setvar('_RGPREFIX', $grppre));
$ext->add('ext-queues', $exten, '', new ext_setvar('CALLERID(name)','${RGPREFIX}${CALLERID(name)}'));
}
// Set Alert_Info
if ($alertinfo != '') {
$ext->add('ext-queues', $exten, '', new ext_setvar('__ALERT_INFO', str_replace(';', '\;', $alertinfo)));
}
$ext->add('ext-queues', $exten, '', new ext_setvar('MONITOR_FILENAME','/var/spool/asterisk/monitor/q${EXTEN}-${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}-${UNIQUEID}'));
$joinannounce_id = (isset($q['joinannounce_id'])?$q['joinannounce_id']:'');
if($joinannounce_id) {
$joinannounce = recordings_get_file($joinannounce_id);
$ext->add('ext-queues', $exten, '', new ext_playback($joinannounce));
}
$options = 't';
if ($q['rtone'] == 1) {
$options .= 'r';
}
if ($q['retry'] == 'none'){
$options .= 'n';
}
if (isset($q['music'])) {
$ext->add('ext-queues', $exten, '', new ext_setvar('__MOHCLASS', $q['music']));
}
// Set CWIGNORE if enabled so that busy agents don't have another line key ringing and
// stalling the ACD.
if ($q['cwignore']) {
$ext->add('ext-queues', $exten, '', new ext_setvar('__CWIGNORE', 'TRUE'));
}
$agentannounce_id = (isset($q['agentannounce_id'])?$q['agentannounce_id']:'');
if ($agentannounce_id) {
$agentannounce = recordings_get_file($agentannounce_id);
} else {
$agentannounce = '';
}
$ext->add('ext-queues', $exten, '', new ext_queue($exten,$options,'',$agentannounce,$q['maxwait']));
$ext->add('ext-queues', $exten, '', new ext_dbdel('${BLKVM_OVERRIDE}'));
// If we are here, disable the NODEST as we want things to resume as normal
//
$ext->add('ext-queues', $exten, '', new ext_setvar('__NODEST', ''));
if ($q['cwignore']) {
$ext->add('ext-queues', $exten, '', new ext_setvar('__CWIGNORE', ''));
}
// destination field in 'incoming' database is backwards from what ext_goto expects
$goto_context = strtok($q['goto'],',');
$goto_exten = strtok(',');
$goto_pri = strtok(',');
$ext->add('ext-queues', $exten, '', new ext_goto($goto_pri,$goto_exten,$goto_context));
//dynamic agent login/logout
if (trim($qregex) != '') {
$ext->add('ext-queues', $exten."*", '', new ext_setvar('QREGEX', $qregex));
}
$ext->add('ext-queues', $exten."*", '', new ext_macro('agent-add',$exten.",".$q['password']));
$ext->add('ext-queues', $exten."**", '', new ext_macro('agent-del',$exten.",".$exten));
}
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment