Ok, here's my reimplementation of queueDial.agi in AEL:
macro qmoutqdial( clid, dialstring, queue, agent )
{
start_dial_time = ${EPOCH};
QueueLog(${queue}|${UNIQUEID}|NONE|ENTERQUEUE||${clid});
Dial(${dialstring},,gtWM(queuelog_connect_event^${queue}^${UNIQUEID}^${agent}^${start_dial_time}));
end_dial_time = ${EPOCH};
verb = COMPLETECALLER;
Hangup;
catch h {
if( ${ISNULL(${end_dial_time})} ) {
end_dial_time = ${EPOCH};
}
switch(${DIALSTATUS}) {
case BUSY:
case NOANSWER:
case CHANUNAVAIL:
case CONGESTION:
case CANCEL:
wait_time = ${end_dial_time} - ${start_dial_time};
verb = ABANDON;
QueueLog(${queue}|${UNIQUEID}|NONE|ABANDON|1|1|${wait_time});
break;
case ANSWER:
wait_time = ${end_dial_time} - ${start_dial_time} - ${ANSWEREDTIME};
if( ${ISNULL(${verb})} ) {
verb = COMPLETEAGENT;
}
QueueLog(${queue}|${UNIQUEID}|${agent}|${verb}|${wait_time}|${ANSWEREDTIME});
break;
default:
NoOp(don't know how to handle ${DIALSTATUS});
break;
}
}
}
macro queuelog_connect_event( queue, uniqueid, agent, start_dial_time )
{
wait_time = ${EPOCH} - ${start_dial_time};
QueueLog(${queue}|${uniqueid}|${agent}|CONNECT|${wait_time});
}
I have tested this with three types of calls typically made via the AGI script:
- agent hangs up before call connects
- call connects and agent hangs up
- call connects and caller hangs up
and it seems to work.
For those of you running 1.2 without the AEL2 patch, this is what it compiles to in extensions.conf format. This is the functional equivalent, but as it's the deparsed output from what the above AEL compiles to, it's not meant to be pretty:
[macro-qmoutqdial]
exten => s,1,Set(clid=${ARG1})
exten => s,2,Set(dialstring=${ARG2})
exten => s,3,Set(queue=${ARG3})
exten => s,4,Set(agent=${ARG4})
exten => s,5,Set(start_dial_time=$[${EPOCH}])
exten => s,6,QueueLog(${queue}|${UNIQUEID}|NONE|ENTERQUEUE||${clid})
exten => s,7,Dial(${dialstring}||gtWM(queuelog_connect_event^${queue}^${UNIQUEID}^${agent}^${start_dial_time}))
exten => s,8,Set(end_dial_time=$[${EPOCH}])
exten => s,9,Set(verb=$[COMPLETECALLER])
exten => s,10,Hangup()
exten => h,1,GotoIf($[${ISNULL(${end_dial_time})} ]?2:3)
exten => h,2,Set(end_dial_time=$[${EPOCH}])
exten => h,3,NoOp(Finish if-catch-h-1-2)
exten => h,4,Goto(sw-3-${DIALSTATUS}|10)
exten => h,5,NoOp(Finish switch-catch-h-1-3)
exten => _sw-3-.,10,NoOp(don't know how to handle ${DIALSTATUS})
exten => _sw-3-.,11,Goto(h|5)
exten => sw-3-ANSWER,10,Set(wait_time=$[${end_dial_time} - ${start_dial_time} - ${ANSWEREDTIME}])
exten => sw-3-ANSWER,11,GotoIf($[${ISNULL(${verb})} ]?12:13)
exten => sw-3-ANSWER,12,Set(verb=$[COMPLETEAGENT])
exten => sw-3-ANSWER,13,NoOp(Finish if-sw-catch-h-1-ANSWER-3-4)
exten => sw-3-ANSWER,14,QueueLog(${queue}|${UNIQUEID}|${agent}|${verb}|${wait_time}|${ANSWEREDTIME})
exten => sw-3-ANSWER,15,Goto(h|5)
exten => sw-3-CANCEL,10,Set(wait_time=$[${end_dial_time} - ${start_dial_time}])
exten => sw-3-CANCEL,11,Set(verb=$[ABANDON])
exten => sw-3-CANCEL,12,QueueLog(${queue}|${UNIQUEID}|NONE|ABANDON|1|1|${wait_time})
exten => sw-3-CANCEL,13,Goto(h|5)
exten => sw-3-CONGESTION,10,Goto(sw-3-CANCEL|10)
exten => sw-3-CHANUNAVAIL,10,Goto(sw-3-CONGESTION|10)
exten => sw-3-NOANSWER,10,Goto(sw-3-CHANUNAVAIL|10)
exten => sw-3-BUSY,10,Goto(sw-3-NOANSWER|10)
[macro-queuelog_connect_event]
exten => s,1,Set(queue=${ARG1})
exten => s,2,Set(uniqueid=${ARG2})
exten => s,3,Set(agent=${ARG3})
exten => s,4,Set(start_dial_time=${ARG4})
exten => s,5,Set(wait_time=$[${EPOCH} - ${start_dial_time}])
exten => s,6,QueueLog(${queue}|${uniqueid}|${agent}|CONNECT|${wait_time})
I hope others find this useful and that it maybe makes it into QM as an alternative to queueDial.agi. I must admit that I was never a fan of forking a process for every outbound call.
Regards