[globals] tandmxkey= tandmxhostid= ;Replace Below with Audio Locations! dialtone=custom/signal/dialtone busy=custom/signal/busy reorder=custom/signal/reorder ccad=custom/signal/ccad acbn=custom/signal/acbn nnis=custom/nnis [local] exten => 2311111,1,GoSub(dt,s,1) same => n,Hangup exten => _X!,1,GoSub(dialnum,${EXTEN},1) same => n,Hangup ;======================; ; Subroutines! ; ;======================; [dialnum] exten => _X!,1,Progress same => n,Dial(SIP/${EXTEN},,rg) ; Dial(SIP/${ARG1},,m(ringback)g) same => n,GotoIf($["${DIALSTATUS}"="CHANUNAVAIL"]?nnis,1) same => n,GotoIf($["${DIALSTATUS}"="BUSY"]?busy,1) same => n,GotoIf($["${DIALSTATUS}"="CONGESTION"]?reorder,1) same => n,GotoIf($["${DIALSTATUS}"="NOANSWER"]?reorder,1) same => n,Return() exten => busy,1,GoSub(busy,s,1) same => n,Return() exten => reorder,1,GoSub(reorder,s,1) same => n,Return() exten => ccad,1,GoSub(ccad,s,1) same => n,Return() exten => acbn,1,GoSub(acbn,s,1) same => n,Return() exten => nnis,1,GoSub(nnis,s,1) same => n,Return() [dt] exten => s,1,Answer() same => n,Read(digits,${dialtone},7,,,3) same => n,GotoIf($["${LEN(${digits})}" != "0"]?route:reorder) same => n(route),GoTo(find-route,${digits},1) same => n(reorder),GoSub(reorder,s,1) same => n,Return [find-route] exten => _X!,1,Set(number=${EXTEN}) same => n,Set(lookup=${SHELL(curl "http://api.tandmx.net/api/v1/?auth=${tandmxkey}&number=${number}&ani=${CALLERID(num)}&host=${tandmxhostid}")}) same => n,GotoIf($["${lookup}"=="local"]?local:long) same => n(local),Goto(local,${number},1) same => n(long),Dial(${lookup}) same => n,Hangup [from-internal] exten => 6,1,GoSub(dt,s,1) same => n,Hangup exten => _X!,1,GoTo(find-route,${EXTEN},1) [nnis] exten => s,1,Progress() same => n(a),Playback(${nnis},noanswer) same => n,Goto(a) same => n,Hangup [acbn] exten => s,1,Progress() same => n(a),Playback(${acbn},noanswer) same => n,Goto(a) same => n,Hangup [ccad] exten => s,1,Progress() same => n(a),Playback(${ccad},noanswer) same => n,Goto(a) same => n,Hangup [reorder] exten => s,1,Playback(${reorder},noanswer) ;same => n,GoTo(1) same => n,Return() [busy] exten => s,1,Playback(${busy},noanswer) ;same => n,GoTo(1) same => n,Return()