================extensions.conf================
#include exts/internal
#include exts/outgoing
#include exts/incoming
#include exts/features
================outgoing=======================
[general-out]
include => unauthenticated
exten => _833NXXXXXX,1,Dial(PJSIP/*1${EXTEN}@sipbroker-out,,r))
exten => _844NXXXXXX,1,Dial(PJSIP/*1${EXTEN}@sipbroker-out,,r))
exten => _855NXXXXXX,1,Dial(PJSIP/*1${EXTEN}@sipbroker-out,,r))
exten => _866NXXXXXX,1,Dial(PJSIP/*1${EXTEN}@sipbroker-out,,r))
exten => _877NXXXXXX,1,Dial(PJSIP/*1${EXTEN}@sipbroker-out,,r))
exten => _888NXXXXXX,1,Dial(PJSIP/*1${EXTEN}@sipbroker-out,,r))
exten => _1800NXXXXXX,1,Dial(PJSIP/*${EXTEN}@sipbroker-out,,r))
exten => _1833NXXXXXX,1,Dial(PJSIP/*${EXTEN}@sipbroker-out,,r))
exten => _1844NXXXXXX,1,Dial(PJSIP/*${EXTEN}@sipbroker-out,,r))
exten => _1855NXXXXXX,1,Dial(PJSIP/*${EXTEN}@sipbroker-out,,r))
exten => _1866NXXXXXX,1,Dial(PJSIP/*${EXTEN}@sipbroker-out,,r))
exten => _1877NXXXXXX,1,Dial(PJSIP/*${EXTEN}@sipbroker-out,,r))
exten => _1888NXXXXXX,1,Dial(PJSIP/*${EXTEN}@sipbroker-out,,r))
exten => _X.,1,GotoIf($["${SIPDOMAIN}" = "mydomain.com"]?numeric)
 same => n,GotoIf($["${SIPDOMAIN}" = "dznet-pbx.mydomain.com"]?numeric)
 same => n,GotoIf($["${SIPDOMAIN}" != "mydomain.com"]?uri)
 same => n(numeric),Gosub(dialprovider,s,1(${EXTEN}))
 same => n(uri),Gosub(uridial,s,1(${EXTEN},${SIPDOMAIN}))
exten => _+X.,1,Gosub(dialsipbroker,s,1(${EXTEN:0}))
exten => _*X.,1,Gosub(dialsipbroker,s,1(${EXTEN:0})) ; SIP-Code dialing

[uri]
exten => _[a-z].,1,Gosub(uridial,s,1(${EXTEN},${SIPDOMAIN}))
exten => _[A-Z].,1,Gosub(uridial,s,1(${EXTEN},${SIPDOMAIN}))

[dialprovider]
exten => s,1,NoOp( printing full callerid -- ${CALLERID(all)})
exten => s,n,NoOp( printing the sip domain -- ${SIPDOMAIN})
exten => s,n,Set(CALLERID(all)=<+1${CALLERID(num)}>) ; Set outbound CallerID
exten => s,n,NoOp( printing the extension -- ${ARG1})
exten => s,n,Dial(PJSIP/+${IF($[${ARG1:0:1} = 1]?${ARG1}:1${ARG1})}@sipbroker-out)
exten => s,n,NoOp( Dial Status: ${DIALSTATUS})
exten => s,n,Goto(s-${DIALSTATUS},1)
exten => s-NOANSWER,1,Hangup
exten => s-CONGESTION,1,Congestion
exten => s-CANCEL,1,Hangup
exten => s-BUSY,1,Busy
exten => s-CHANUNAVAIL,1,Dial(PJSIP/${ARG1}@${CALLERID(num):2},,r) ; If failed then Dial provider
 same => n,Hangup

[dialsipbroker]
exten => s,1,NoOp(${CALLERID(num)})
exten => s,n,Set(CALLERID(all)=<+1${CALLERID(num)}>) ; Set outbound CallerID
exten => s,n,Dial(PJSIP/${ARG1}@sipbroker-out) ; Call SIP Broker for ENUM lookup
exten => s,n,Hangup

[uridial]
exten => s,1,ExecIf($["${DB(${CALLERID(number)}/user_sipname)}" != ""]?Set(CALLERID(number)=${DB(${CALLERID(number)}/user_sipname)}@mydomain.com))
exten => s,n,NoOp(Calling SIP URI ${ARG1}@${ARG2})
exten => s,n,NoOp(--- From: ${CALLERID(all)} ---)
exten => s,n,Dial(PJSIP/anonymous/sip:${ARG1}@${ARG2},120,tr)
exten => s,n,Congestion()