Skip to content

Instantly share code, notes, and snippets.

@bfrigon
Last active March 15, 2017 06:25
Show Gist options
  • Save bfrigon/cffc38501182c789eb698f38e78cedfe to your computer and use it in GitHub Desktop.
Save bfrigon/cffc38501182c789eb698f38e78cedfe to your computer and use it in GitHub Desktop.
Asterisk call treatment using a database
[context-incoming]
exten => s, 1, NoOp()
;**** Check if a call treatment exists for the caller ****
same => n, Set(action=${TOLOWER(${ODBC_CALL_TREATMENT(${ARG1},${CALLERID(name)},${CALLERID(num)})})})
;**** Jump to label normal if none is found ****
same => n, GotoIf(${ISNULL(${action})}?normal)
;**** Jump to the propriate call treatment action, or treatment-invalid if not found ****
same => n, GotoIf(${DIALPLAN_EXISTS(context-incoming,treatment-${action})}?treatment-${action},1:treatment-invalid,1)
;**** Normal call processing ****
same => n(normal), NoOp()
;--------------------------------------------
; call treatment : busy
;--------------------------------------------
exten => treatment-busy, 1, Verbose(0, Call treatment (busy) : ${CALLERID(num)})
same => n, Answer()
same => n, PlayTones(busy)
same => n, Wait(3600)
same => n, Hangup()
same => n, Return()
;---------------------------------------------
; Call treatment : Quiet
;---------------------------------------------
exten => treatment-quiet, 1, Verbose(0,Call treatment (quiet) : ${CALLERID(num)})
same => n, Answer()
same => n, PlayTones(ring)
same => n, Wait(3600)
same => n, Hangup()
same => n, Return()
;---------------------------------------------
; Call treatment : Torture menu (english)
;---------------------------------------------
exten => treatment-torture-en, 1, Verbose(0,Call treatment (torture-en) : ${CALLERID(num)})
same => n, Answer(500)
same => n, Wait(1)
same => n, Set(CHANNEL(language)=en)
same => n(torture-en-loop), NoOp()
same => n, Playback(custom/torture-menu-part1)
same => n, PlayTones(ring)
same => n, Wait(2)
same => n, Playback(custom/torture-menu-part2)
same => n, Goto(torture-en-loop)
;---------------------------------------------
; Invalid call treatment
;---------------------------------------------
exten => treatment-invalid, 1, Log(WARNING, Invalid call treatment for ${CALLERID(num)} : ${action})
same => n, goto(s,normal)
[CALL_TREATMENT]
dsn=asterisk
readsql=SELECT action FROM call_treatment WHERE (extension='${SQL_ESC(${ARG1})}' or extension='') AND ('${SQL_ESC(${ARG2})}' RLIK E caller_name OR caller_name='') AND ('${SQL_ESC(${ARG3})}' RLIKE caller_num AND NOT caller_num='') ORDER BY extension DESC, caller_num DESC LIMIT 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment