Skip to content

Asterisk Dialplan

Global variables

; Used in record calls
[globals]
PATH_RECORDS=/var/records

Procedures for record calls

;
[sub-definevar]
exten => s,1,Noop()
 same => n,ExecIf($[!${LEN(${CALLTYPE})}]?Set(CALLTYPE=unknown))
 same => n,Set(CALLERNUM=${CALLERID(num)})
 same => n,Set(RECFILE=${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}-${CALLTYPE}-${CALLERNUM}-${CALLTO})
 same => n,Set(FULLRECFILE=${PATH_RECORDS}/${STRFTIME(${EPOCH},,%G/%m/%d)}/${RECFILE})
 same => n,Set(CDR(recordfilename)=${FULLRECFILE}.mp3)
 same => n,Return

[sub-mixmonitor]
; ${ARG1} - callee, ${EXTEN}
exten => s,1,Noop()
 same => n,Set(CALLTO=${ARG1})
 same => n,Gosub(sub-definevar,s,1)
 same => n,MixMonitor(${FULLRECFILE}.wav,W(1),lame -b 16 ${FULLRECFILE}.wav ${FULLRECFILE}.mp3 && rm ${FULLRECFILE}.wav && chmod -R 644 ${FULLRECFILE}.mp3)
 same => n,Return

; Dial ...
exten => _ХXX.,1,Noop()
 same => n,Set(CALLTYPE=out)
 same => n,Gosub(sub-mixmonitor,s,1,(${EXTEN}) )
 same => n,Dial(SIP/sipprovider/${EXTEN},180,Ttj)

Send DTMF command

The door was opened from an analog phone by dialing #*9. 1504 - the number of the analog PBX connected via the FXO gateway to Asterisk.

; Open door
exten => _999,1,Noop()
 same => n,Dial(SIP/1504,5,D(#*9))

Incoming N for 1 number, we analyze SIP_HEADER(TO)

; The operator sends 1 Extension, when calling 3 numbers.
; according to their instructions it looks like this:
; In sip: context=income-datagroup-wrapper
; Original incoming SIP_HEADER(TO) = ''
[income-datagroup-wrapper]
exten => _X.,1,Set(NUM=${SIP_HEADER(TO):5})
 same => n,Set(NUM=${CUT(NUM,@,1)})
 same => n,Goto(income-datagroup,${NUM},1)

[income-datagroup]
exten => 0441112233,1,Noop()
 same => n,Gosub(sub-incoming-office,${EXTEN},1)

exten => 0441113344,1,Noop()
 same => n,Gosub(sub-incoming-callcenter,${EXTEN},1)

exten => 0441114455,1,Noop()
 same => n,Gosub(sub-incoming-servicecenter,${EXTEN},1)

This same operator did not set CALLERID(num) until the value fromuser was removed from the sip parameters.

Trim number with 13 digits

; Only for prefix +38
; +380501113344 -> 0501113344
[sub-callernum13to10]
exten => _X.,1,ExecIf($[ $[${LEN(CALLERID(num))}=13] & $["${CALLERID(num):0:3}"="+38"] ]?Set(CALLERID(num)=${CALLERID(num):3}) )
 same => n,Return