[qmqueue]
exten => _X!,1,Set(LAJDAK_START=${EPOCH})
exten => _X!,n,Set(__REAL_EXTEN=${EXTEN}) ;; search
exten => _X!,n,Set(__DIRECTION=in) ;; search
exten => _X!,n,Set(__BACKUP_REAL_EXTEN=${REAL_EXTEN}) ; kvuli transfer a ZOMBIE channel
exten => _X!,n,Set(CDR(real_exten)=${REAL_EXTEN}) ;; search
exten => _X!,n,Set(CDR(id_call)=${ID_CALL}) ;; search
exten => _X!,n,Set(CDR(from_did)=${FROM_DID}) ;; search
exten => _X!,n,Set(CDR(direction)=${DIRECTION}) ;; searchs
exten => _X!,n,Set(__TRANSFER_ID_CALL=${ID_CALL})
exten => _X!,n,Macro(record-enable,${EXTEN},IN)
exten => _X!,n,Set(CHANNEL(language)=cz)
exten => _X!,n,ExecIf($[ "${CC_TYPE}" != "dialer" ]?AGI(${FASTAGI_PREFIX_URL}qmagent_opener_agi.php,ringing)) ;; QMAgent Otvirak - pokud je to dialer, tak toto AGI nevolame
exten => _X!,n,AGI(${FASTAGI_PREFIX_URL}cc/qmqueue_start.php)
exten => _X!,n,GotoIf($[ $[ "${ACTIVATED_PAUSE}" != "" ] | $[ ${EXTENSION_STATE(${EXTEN}@daktela-groups)} != NOT_INUSE ] ]?busy)
exten => _X!,n,System( echo "${EPOCH}|${ID_CALL}|${QUEUE_NUMBER}|Local/${REAL_EXTEN}@qmqueue/n|RINGING" >> /var/log/asterisk/queue_log )
exten => _X!,n,GoSub(customcontext--4,${REAL_EXTEN},1) ;; API callback
exten => _X!,n,ExecIf($[ "${CC_TYPE}" = "click2call" ]?AGI(${FASTAGI_PREFIX_URL}cc/click2call_set_user.php)) ; Click2Call
exten => _X!,n,ExecIf($[ "${CC_TYPE}" = "dialer" ]?AGI(${FASTAGI_PREFIX_URL}cc/dialer_change_action.php,3)) ; hovor je smerovan na operatora, jeste neni zodpovezen
exten => _X!,n,ExecIf($[ ${EXTENSION_STATE(${EXTEN}@daktela-groups)} = NOT_INUSE ]?Dial(Local/${EXTEN}@daktela-groups,,${QMQUEUE_DIALOPTIONS}tM(qmagent-answer-inbound)L(${CALL_TIMEOUT})))
exten => _X!,n,Set(RINGING_TIME=$[${EPOCH} - ${LAJDAK_START}])
exten => _X!,n,NoOp(DIALSTATUS = ${DIALSTATUS})
exten => _X!,n,GotoIf($["${DIALSTATUS}" = ""]?busy)
exten => _X!,n,GotoIf($["${DIALSTATUS}" != "ANSWER"]?hangup) ; Otvirak / WrapPause nastavime opravdu jen pri ANSWER
exten => _X!,n,NoCDR()
exten => _X!,n,GotoIF($["${DIALSTATUS}" = "ANSWER"]?answer:hangup) ; Otvirak / WrapPause nastavime opravdu jen pri ANSWER
exten => _X!,n(answer),Macro(daktelawrap,${REAL_EXTEN},Local/${REAL_EXTEN}@qmqueue/n,${QUEUE_NUMBER},${WRAPUPTIME},${UNIQUEID},${WRAP_NAME})
exten => _X!,n,AGI(${FASTAGI_PREFIX_URL}qmagent_opener_agi.php,hangup) ;; QMAgent Otvirak
exten => _X!,n,Hangup
exten => _X!,n(hangup),AGI(${FASTAGI_PREFIX_URL}qmagent_opener_agi.php,hangup) ;; QMAgent Otvirak
exten => _X!,n,Hangup
exten => _X!,n(busy),NoCDR() ; Agent neni volny
exten => _X!,n,Set(AGENTBUSY=|1)
exten => _X!,n,Busy(1)
exten => _X!,n,Hangup

exten => h,1,Set(REAL_EXTEN=${BACKUP_REAL_EXTEN}) ; kvuli transfer a ZOMBIE channel
exten => h,n,Set(SAVEEXTEN=${REAL_EXTEN})
exten => h,n,Set(QUEUENUMBER=${QUEUE_NUMBER})
exten => h,n,GotoIf($[ "${CHANNEL:0:10}" = "Transfered" ]?transfer) ;; Prepojeni pres Asteriska
exten => h,n,GotoIf($["${SIPREFERREDBYHDR}" != ""]?transfer:notransfer) ;; Prepojeni pres telefon Well
exten => h,n(transfer),System( echo "${EPOCH}|${TRANSFER_ID_CALL}|${QUEUE_NUMBER}|Local/${REAL_EXTEN}@qmqueue/n|TRANSFER|${DIALEDPEERNUMBER}" >> /var/log/asterisk/queue_log )
exten => h,n(notransfer),GotoIF($["${DIALSTATUS}" = "ANSWER"]?answerh:cancelh) ; WrapPause nastavime opravdu jen pri ANSWER
exten => h,n(answerh),Macro(daktelawrap,${REAL_EXTEN},Local/${REAL_EXTEN}@qmqueue/n,${QUEUE_NUMBER},${WRAPUPTIME},${ID_CALL},${WRAP_NAME})
exten => h,n,ExecIf($[ "${CC_TYPE}" = "click2call" ]?Macro(cc-click2call-hangup)) ; Click2Call
exten => h,n,ExecIf($[ "${CC_TYPE}" = "dialer" ]?Macro(cc-dialer-hangup)) ; Dialer
exten => h,n,Goto(hanguph)
exten => h,n(cancelh),System( echo "${EPOCH}|${ID_CALL}|${QUEUE_NUMBER}|Local/${REAL_EXTEN}@qmqueue|RINGNOANSWER|$[(${EPOCH} - ${LAJDAK_START}) * 1000]${AGENTBUSY}" >> /var/log/asterisk/queue_log )
exten => h,n,GotoIF($["${DIALSTATUS}" = "CONGESTION" | "${DIALSTATUS}" = "BUSY"]?dndwrap:regular) ; Pokud nekdo vymackne hovor nebo ma DND, tak ho dame na wrap, at se dokola nevola
exten => h,n(dndwrap),NoOp(Linka ${REAL_EXTEN} ma zapnute DND) ; 5s hardcoded
exten => h,n(regular),GotoIf($["${QUEUE_AUTO_PAUSE}" = "0"]?hanguph)
exten => h,n,GotoIf($["${DIALSTATUS}" = "BUSY" | "${DIALSTATUS}" = "CONGESTION"]?lajdak)
exten => h,n,GotoIf($["${DIALSTATUS}" != "CANCEL"]?hanguph)
exten => h,n,GotoIf($[(${EPOCH} - ${LAJDAK_START}) < ${QUEUE_AUTO_PAUSE_TIMEOUT}]?hanguph)
exten => h,n(lajdak),AGI(webagent.php,pause_agent,${REAL_EXTEN},,${LAJDAK_PAUSE_REASON})  ; Predame klapku, kde sedi agent a zapauzujeme ho LAJDAKEM
exten => h,n(hanguph),Macro(hangupcall)
exten => h,n(exith),AGI(${FASTAGI_PREFIX_URL}qmagent_opener_agi.php,hangup) ;; QMAgent Otvirak
exten => h,n,Noop(Kontrola, zda existuje odchozi hovor, odkud byl tento qmqueue hovor prepojen)
exten => h,n,ExecIf($[ "${CC_TYPE}" != "dialer" ]?AGI(${FASTAGI_PREFIX_URL}cc/transfer_find.php)) ; dohledame zda uzivatel ma nejaky transferovany hovor
exten => h,n,ExecIf($[ "${CC_TYPE}" != "dialer" ]?AGI(${FASTAGI_PREFIX_URL}cc/transfer_outcall.php)) ; V TRANSFERED_CC_ID_CALL je pole CC_ID_CALL odchozich hovoru



; Zodpovezeny hovor na prichodu
[macro-qmagent-answer-inbound]
exten => s,1,ExecIf($[ "${CC_TYPE}" != "dialer" ]?AGI(${FASTAGI_PREFIX_URL}qmagent_opener_agi.php,answer)) ;; QMAgent Otvirak - pokud je to dialer, tak toto AGI nevolame
exten => s,n,ExecIf($[ "${CC_TYPE}" = "dialer" ]?AGI(${FASTAGI_PREFIX_URL}cc/dialer_set_user.php)) ; Dialer
exten => s,n,GotoIf($[ "${CC_TYPE}" != "dialer" ]?end)
exten => s,n,GotoIf($[ "${CC_LEG}" = "" ]?end)
exten => s,n,GotoIf($[ "${DB_EXISTS(CC_${CC_ID_CALL}/TYPE)}" != "1" ]?end)
exten => s,n,Set(DB(CC_${CC_ID_CALL}/SECOND_ANSWERED)=Y)
exten => s,n,System( echo "${EPOCH}|${DB(CC_${CC_ID_CALL}/ID_CALL)}|${DB(CC_${CC_ID_CALL}/QUEUE_NAME)}|${DB(CC_${CC_ID_CALL}/USER_NAME)}|CONNECT" >> /var/log/asterisk/queue_log )
exten => s,n,ExecIf($[ "${DB(CC_${CC_ID_CALL}/CONTACT)}" != "" ]?AGI(${FASTAGI_PREFIX_URL}cc/contact_change_action.php,3))
exten => s,n,AGI(${FASTAGI_PREFIX_URL}cc/dialer_change_action.php,4) ; hovor je zodpovezen operatorem a mluvi se zakaznikem
exten => s,n,MacroExit()
exten => s,n(end),Noop(Neni to CC hovor - dialer)

