[cce]


;================ Outgoing calls to CUSP ===================
exten => _8XXXXXXXXXX,1,NoOp()
        same => n,Set(CALLERID(num)=87654321)
        same => n,Set(CALLERID(name)=87654321)
        same => n,Set(AGC(rx)=32768)
        same => n,Set(AGC(tx)=32768)
        same => n,Set(DENOISE(rx)=on)
        same => n,Set(DENOISE(tx)=on)
        same => n,Verbose(1, Outgoing Caller ID: ${CALLERID(all)})
;        same => n,Dial(PJSIP/${EXTEN}@cusp,32)
        same => n,Dial(PJSIP/${EXTEN}@cusp,32)
        same => n,Hangup()



;================ Outgoing calls test NR===================
exten => _9998XXXXXXXXXX,1,NoOp()
        same => n,Set(CALLERID(num)=87654321)
        same => n,Set(CALLERID(name)=87654321)
       ; same => n,Set(AGC(rx)=32768)
       ; same => n,Set(AGC(tx)=32768)
       ; same => n,Set(DENOISE(rx)=on)
       ; same => n,Set(DENOISE(tx)=on)
        same => n,Verbose(1, Outgoing Caller ID: ${CALLERID(all)})
        same => n,Dial(PJSIP/${EXTEN}@cusp,32)
        same => n,Hangup()



;================ Start AGI Scripts ===================

exten => 80054558,1,Agi(agi://10.1.120.111:4573/hello.agi)

exten => 80054555,1,Agi(agi://10.1.120.169:4573/hello.agi)

exten => 80054556,1,Agi(agi://10.14.74.162:4573/hello.agi)

exten => 80054557,1,Agi(agi://sbcapp1lt3.hq.bc:4573/hello.agi)







;================ Hangup processing ===================

exten => h,1,NoOp()
exten => h,n,Verbose(1, !!!!!!!!!!!!! RECOG_STATUS: ${RECOG_STATUS})
exten => h,n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_KEYS()})
; start loop
exten => h,n(hu_begin),noop()
  
; check exit condition (no more array to check)
exten => h,n,GotoIf($[${LEN(${HANGUPCAUSE_STRING})} = 0]?hu_exit)
  
; pull the next item
exten => h,n,Set(ARRAY(item)=${HANGUPCAUSE_STRING})
exten => h,n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_STRING:${LEN(${item})}})
 
; display the channel ID and cause code
exten => h,n,noop(got channel ID ${item} with pvt cause ${HANGUPCAUSE(${item},tech)} ${HANGUPCAUSE(${item},ast)} )
exten => h,n,noop(${HANGUPCAUSE_KEYS()})
exten => h,n,Set(REL=${HANGUPCAUSE(${HANGUPCAUSE_KEYS()},tech)});
exten => h,n,Set(sip=${CUT(REL, ,2)})

; set call result by sip and 1850 cause
exten => h,n,Set(callresult=${ODBC_CALLRESULT_IMAO(${sip},${HANGUPCAUSE})})
exten => h,n,Set(callresult=${IF($[${LEN(${callresult})} = 0]?333:${callresult})})

; insert call_detail in IMAO database
exten => h,n,NoOp(PROGRESSTIME_MS = ${PROGRESSTIME_MS}, RINGTIME_MS = ${RINGTIME_MS}, ANSWEREDTIME_MS = ${ANSWEREDTIME_MS}, DIALEDTIME_MS = ${DIALEDTIME_MS})

exten => h,n,NoOp(${CDR(uniqueid)},${CDR(clid)},${CDR(src)},${CDR(dst)},${CDR(dcontext)},${CDR(channel)},${CDR(dstchannel)},${CDR(start)},${CDR(end)},${CDR(duration)},${CDR(billsec)},${CDR(disposition)},${DIALSTATUS},${REL},${HANGUPCAUSE},${CDR(accountcode)},${callresult},${contractId},${companyId},${callId},${phoneNumber},${treeName},${PROGRESSTIME_MS},${RINGTIME_MS},${ANSWEREDTIME_MS},${DIALEDTIME_MS})

exten => h,n,Set(ODBC_INSERT_IMAO(${CDR(uniqueid)},${CDR(clid)},${CDR(src)},${CDR(dst)},${CDR(dcontext)},${CDR(channel)},${CDR(dstchannel)},${CDR(start)},${CDR(end)},${CDR(duration)},${CDR(billsec)},${CDR(disposition)},${DIALSTATUS},${REL},${HANGUPCAUSE},${CDR(accountcode)},${callresult},${contractId},${companyId},${callId},${phoneNumber},${treeName},${PROGRESSTIME_MS},${RINGTIME_MS},${ANSWEREDTIME_MS},${DIALEDTIME_MS})=)

  
; check exit condition (no more array to check)
exten => h,n,gotoif($[${LEN(${HANGUPCAUSE_STRING})} = 0]?hu_exit)
  
; we still have entries to process, so strip the leading comma
exten => h,n,set(HANGUPCAUSE_STRING=${HANGUPCAUSE_STRING:1})
; go back to the beginning of the loop
exten => h,n,goto(hu_begin)
exten => h,n(hu_exit),noop(All HANGUPCAUSE entries processed)




;===========Test=============

exten => 20000,1,Answer()
exten => 20000,n,MRCPSynth("Hello")
exten => 20000,n,Hangup()


[test]

;================ Outgoing calls to CUSP ===================
exten => _8XXXXXXXXXX,1,NoOp()
        same => n,Set(CALLERID(num)=87654321)
        same => n,Set(CALLERID(name)=87654321)
        same => n,Set(AGC(rx)=32768)
        same => n,Set(AGC(tx)=32768)
        same => n,Set(DENOISE(rx)=on)
        same => n,Set(DENOISE(tx)=on)
        same => n,Verbose(1, Outgoing Caller ID: ${CALLERID(all)})
        same => n,Dial(PJSIP/${EXTEN}@cusp,32)
;        same => n,Dial(PJSIP/999${EXTEN}@cusp,32)
        same => n,Hangup()



;================ Outgoing calls test NR===================
exten => _9998XXXXXXXXXX,1,NoOp()
        same => n,Set(CALLERID(num)=87654321)
        same => n,Set(CALLERID(name)=87654321)
        same => n,Set(AGC(rx)=32768)
        same => n,Set(AGC(tx)=32768)
        same => n,Set(DENOISE(rx)=on)
        same => n,Set(DENOISE(tx)=on)
        same => n,Verbose(1, Outgoing Caller ID: ${CALLERID(all)})
        same => n,Dial(PJSIP/${EXTEN}@cusp,32)
        same => n,Hangup()



[gsr]

exten => gsr,1,Answer

exten => gsr,2,MRCPRecog("builtin:speech/transcribe",spl=ru-RU&p=gsr)

exten => gsr,3,NoOp($RECOG_RESULT)




[ysr]

exten => ysr,1,Answer

exten => ysr,2,MRCPRecog("builtin:speech/transcribe",p=unimrcp11)

exten => ysr,3,NoOp($RECOG_RESULT)
