Categories
Knowledge Base Technical

Asternic Stats and recording outgoing calls.

Asternic stats has the ability to record your outgoing calls in the stats database so they can be accessed from stats package.

But a customer noted two problems with this, firstly they wanted to set a different Music on Hold for outgoing calls and secondly “no answer” calls where the agent hungup before the callee answered.

Firstly we will deal with the Music on hold, Changing the MoH class caused calls not to be recorded in the database correctly. Code below is the reason for this as it causes the dial string to have 2 macros called, This is not possible.

extension_additional.conf:-
exten => s,n,ExecIf($["${MOHCLASS}"!="default" & "${MOHCLASS}"!="" & "${FORCE_CONFIRM}"="" ]?Set(DIAL_TRUNK_OPTIONS=M(setmusic^${MOHCLASS})${DIAL_TRUNK_OPTIONS}))

extensions_custom_asternic_outbound_freepbx.conf:-
exten => _X.,n,Dial(${QDIALER_CHANNEL},300,gM(queuedial-answer^${UNIQUEID}^${GM}^${QDIALER_QUEUE}^${QDIALER_AGENT}^${ST}^${AMPUSER})${DIAL_TRUNK_OPTIONS})

The fix is very simple for this one and required just 2 changes. one line added to set MoH in the dialplan and another to use Trunk_options and not the the one created in extensions_additional.conf

exten => _X.,n,Set(CHANNEL(musicclass)=${MOHCLASS}) ; Added to set the Music on hold class for the outgoing call Fixes bug in normal code
exten => _X.,n,Dial(${QDIALER_CHANNEL},300,gM(queuedial-answer^${UNIQUEID}^${GM}^${QDIALER_QUEUE}^${QDIALER_AGENT}^${ST}^${AMPUSER})${TRUNK_OPTIONS}) ;Was ${DIAL_TRUNK_OPTIONS} changed to set the Music on hold class for the outgoing call Fixes bug in normal code

The second problem is also fairly straight forward but took a bit of creative thinking, The problem was when an agent hung up on an outbound call the dialstatus returned to the dialplan was “CANCEL” and this is not reported upon by the asternic stats package. SO as the call is for all intents abandoned we added a line that if the dialstatus was “CANCEL” we would change it to “ABANDON”.

exten => h,n,Set(DIALSTATUS=${IF($["${DIALSTATUS}"="CANCEL"]?ABANDON:${DIALSTATUS})}) ;Added By Ian Plain to fix cancelled calls not showing in Asternic stats

This is a simple fix and now means calls are recorded as ABANDONED and with the time the Agent waited before hanging up.

Below is our version of the file extensions_custom_asternic_outbound_freepbx.conf with all the changes.

[macro-dialout-trunk-predial-hook]
exten => s,1,Noop(Test Track Outbound)
exten => s,n,Noop(Trunk is ${OUT_${DIAL_TRUNK}})
exten => s,n,Noop(Dialout number is ${OUTNUM})
exten => s,n,Noop(Dial options are ${DIAL_TRUNK_OPTIONS})
exten => s,n,Set(QDIALER_TRUNK_OPTIONS=${DIAL_TRUNK_OPTIONS})
exten => s,n,Set(QDIALER_AGENT=${DB(AMPUSER/${AMPUSER}/cidname)})
exten => s,n,GotoIf($["${QDIALER_AGENT}" != ""]?nextcheck)
exten => s,n,Noop(NO AMPUSER, exit normally with no tracking outbound)
exten => s,n,MacroExit()
exten => s,n(nextcheck),GotoIf($["${CDR(accountcode)}" != ""]?bypass)
exten => s,n,Noop(NO ACCOUNTCODE, exit normally with no tracking outbound)
exten => s,n,MacroExit()
exten => s,n(bypass),Set(PREDIAL_HOOK_RET=BYPASS)
exten => s,n,Goto(queuedial,${OUTNUM},1)
exten => s,n,MacroExit()
;; Dialplan for storing OUTBOUND campaing in queue_log
;; Goto(queuedial,YYYXXXXXXXX,1) where YYY is the queue-campaign code
;; and XXXXXXXX is the number to dial.
;; The queuedial context has the outobound trunk hardcoded
[queuedial]
; this piece of dialplan is just a calling hook into the [qlog-queuedial] context that actually does the
; outbound dialing - replace as needed - just fill in the same variables.
exten => X.,1,Set(QDIALER_QUEUE=${CDR(accountcode)}) ;exten => _X.,n,Set(QDIALER_AGENT=Agent/${AMPUSER}) exten => _X.,n,Set(QDIALER_AGENT=${DB(AMPUSER/${AMPUSER}/cidname)}) ; custom trunk check exten => _X.,n,Set(custom=${CUT(OUT${DIAL_TRUNK},:,1)})
exten => X.,n,GotoIf($["${custom}" = "AMP"]?customtrunk) ; it is normal trunk, not custom exten => _X.,n,Set(QDIALER_CHANNEL=${OUT${DIAL_TRUNK}}/${EXTEN})
exten => X.,n,GotoIf($["${OUT${DIAL_TRUNK}SUFFIX}" == ""]?continuequeuedial) exten => _X.,n,Set(QDIALER_CHANNEL=${OUT${DIAL_TRUNK}}/${EXTEN}${OUT_${DIAL_TRUNK}SUFFIX}) exten => _X.,n,Goto(continuequeuedial) ; it is a custom trunk exten => _X.,n(customtrunk),Set(pre_num=${CUT(OUT${DIAL_TRUNK},$,1)})
exten => X.,n,Set(the_num=${CUT(OUT${DIAL_TRUNK},$,2)})
exten => X.,n,Set(post_num=${CUT(OUT${DIAL_TRUNK},$,3)})
exten => _X.,n,GotoIf($["${the_num}" = "OUTNUM"]?outnum:skipoutnum)
exten => _X.,n(outnum),Set(the_num=${OUTNUM})
exten => _X.,n(skipoutnum),Set(QDIALER_CHANNEL=${pre_num:4}${the_num}${post_num})
exten => _X.,n(continuequeuedial),Noop(Qdialer channel = ${QDIALER_CHANNEL})
exten => _X.,n,Set(QueueName=${QDIALER_QUEUE})
exten => _X.,n,Goto(qlog-queuedial,${EXTEN},1)
[qlog-queuedial]
; We use a global variable to pass values back from the answer-detect macro.
; STATUS = U unanswered
; = A answered (plus CAUSECOMPLETE=C when callee hung up)
; The 'g' dial parameter must be used in order to track callee disconnecting.
; Note that we'll be using the 'h' hook in any case to do the logging when channels go down.
;
exten => X.,1,NoOp(Outbound call -> A:${QDIALER_AGENT} N:${EXTEN} Q:${QDIALER_QUEUE} Ch:${QDIALER_CHANNEL} Dialoptions:${TRUNK_OPTIONS}) exten => _X.,n,Set(ST=${EPOCH}) ;exten => _X.,n,Set(GM=${QDIALER_AGENT}) exten => _X.,n,Set(GM=${REPLACE(QDIALER_AGENT, ,)})
exten => _X.,n,Set(GLOBAL(${GM})=U)
exten => _X.,n,Set(GLOBAL(${GM}ans)=0)
exten => _X.,n,Macro(queuelog,${ST},${UNIQUEID},${QDIALER_QUEUE},${QDIALER_AGENT},ENTERQUEUE,-,${EXTEN})
exten => _X.,n,Set(CHANNEL(musicclass)=${MOHCLASS}) ; Added to set the Music on hold class for the outgoing call Fixes bug in normal code
exten => _X.,n,Dial(${QDIALER_CHANNEL},300,gM(queuedial-answer^${UNIQUEID}^${GM}^${QDIALER_QUEUE}^${QDIALER_AGENT}^${ST}^${AMPUSER})${TRUNK_OPTIONS}) ;Was ${DIAL_TRUNK_OPTIONS} changed to set the Music on hold class for the outgoing call Fixes bug in normal code
exten => _X.,n,Set(CAUSECOMPLETE=${IF($["${DIALSTATUS}" = "ANSWER"]?C)})
; Trapping call termination here
exten => h,1,NoOp( "Call exiting: status ${GLOBAL(${GM})} answered at: ${GLOBAL(${GM}ans)} DS: ${DIALSTATUS}" )
exten => h,n,Set(DB(LASTDIAL/${QDIALER_AGENT})=${EPOCH})
exten => h,n,Goto(case-${GLOBAL(${GM})})
exten => h,n,Hangup()
; Call unanswered
exten => h,n(case-U),Set(WT=$[${EPOCH} - ${ST}])
exten => h,n,Noop(unanswered ${DIALSTATUS})) ;Added By Ian Plain to fix cancelled calls not showing in Asternic stats
exten => h,n,Set(DIALSTATUS=${IF($["${DIALSTATUS}"="CANCEL"]?ABANDON:${DIALSTATUS})}) ;Added By Ian Plain to fix cancelled calls not showing in Asternic stats
exten => h,n,Macro(queuelog,${EPOCH},${UNIQUEID},${QDIALER_QUEUE},${QDIALER_AGENT},${DIALSTATUS},1,1,${WT})
exten => h,n,UserEvent(AgentComplete,Queue: ${QDIALER_QUEUE},TalkTime: 0,Channel: ${CHANNEL})
exten => h,n,Hangup()
; call answered: agent/callee hung
exten => h,n(case-A),Set(COMPLETE=${IF($["${CAUSECOMPLETE}" = "C"]?COMPLETECALLER:COMPLETEAGENT)})
exten => h,n,Noop(answered ${DIALSTATUS})) ;Added By Ian Plain to fix cancelled calls not showing in Asternic stats
exten => h,n,Set(WT=$[${GLOBAL(${GM}ans)} - ${ST}])
exten => h,n,Set(CT=$[${EPOCH} - ${GLOBAL(${GM}ans)}])
exten => h,n,Macro(queuelog,${EPOCH},${UNIQUEID},${QDIALER_QUEUE},${QDIALER_AGENT},${COMPLETE},${WT},${CT})
exten => h,n,UserEvent(AgentComplete,Queue: ${QDIALER_QUEUE},TalkTime: ${CT},Channel: ${CHANNEL})
exten => h,n,Hangup()
[macro-queuedial-answer]
; Expecting $ARG1: uniqueid of the caller channel
; $ARG2: global variable to store the answer results
; $ARG3: queue name
; $ARG4: agent name
; $ARG5: enterqueue
;
exten => s,1,NoOp("Macro: queuedial-answer UID:${ARG1} GR:${ARG2} Q:${ARG3} A:${ARG4} E:${ARG5}")
exten => s,n,Set(QDIALER_QUEUE=${ARG3})
exten => s,n,Set(QDIALER_QUEUE=${REPLACE(QDIALER_QUEUE, ,_)})
exten => s,n,GotoIf($["${CUT(DB(AMPUSER/${ARG6}/recording),=,3)}" = "Always"]?mixmonitor)
exten => s,n,GotoIf($["${DB(AMPUSER/${ARG6}/recording/out/external)}" = "always"]?mixmonitor)
exten => s,n,Goto(continue)
exten => s,n(mixmonitor),MixMonitor(${MIXMON_DIR}${YEAR}/${MONTH}/${DAY}/out-${QDIALER_QUEUE}-${ARG1}.wav,b,/usr/local/parselog/update_mix_mixmonitor.pl ${ARG1} ${MIXMON_DIR}${YEAR}/${MONTH}/${DAY}/out-${QDIALER_QUEUE}-${ARG1}.wav)
exten => s,n,Set(AUDIOHOOK_INHERIT(MixMonitor)=yes)
exten => s,n(continue),Set(NOW=${EPOCH})
exten => s,n,Set(WD=$[${NOW} - ${ARG5}])
exten => s,n,Macro(queuelog,${NOW},${ARG1},${ARG3},${ARG4},CONNECT,${WD})
exten => s,n,Set(GLOBAL(${ARG2})=A)
exten => s,n,Set(GLOBAL(${ARG2}ans)=${NOW})
exten => s,n,NoOp("Macro queuedial-answer terminating" )
[macro-queuelog]
; The advantage of using this macro is that you can choose whether to use the Shell version
; (where you have complete control of what gets written) or the Application version (where you
; do not need a shellout, so it's way faster).
;
; Expecting $ARG1: Timestamp
; $ARG2: Call-id
; $ARG3: Queue
; $ARG4: Agent
; $ARG5: Verb
; $ARG6: Param1
; $ARG7: Param2
; $ARG8: Param3
;
;exten => s,1,System( echo "${ARG1},${ARG2},${ARG3,${ARG4},${ARG5},${ARG6},${ARG7},${ARG8}" >> /var/log/asterisk/queue_log )
exten => s,1,QueueLog(${ARG3},${ARG2},${ARG4},${ARG5},${ARG6}|${ARG7}|${ARG8})