;
; Static extension configuration file, used by
; the pbx_config module. This is where you configure all your 
; inbound and outbound calls in Asterisk. 
; 
; This configuration file is reloaded 
; - With the "extensions reload" command in the CLI
; - With the "reload" command (that reloads everything) in the CLI

;
; The "General" category is for certain variables.  
;
[general]
;
; If static is set to no, or omitted, then the pbx_config will rewrite
; this file when extensions are modified.  Remember that all comments
; made in the file will be lost when that happens. 
;
; XXX Not yet implemented XXX
;
static=yes
;
; if static=yes and writeprotect=no, you can save dialplan by
; CLI command 'save dialplan' too
;
writeprotect=no

; You can include other config files, use the #include command (without the ';')
; Note that this is different from the "include" command that includes contexts within 
; other contexts. The #include command works in all asterisk configuration files.
;#include "filename.conf"

; The "Globals" category contains global variables that can be referenced
; in the dialplan with ${VARIABLE} or ${ENV(VARIABLE)} for Environmental variable
; ${${VARIABLE}} or ${text${VARIABLE}} or any hybrid
;
[globals]
CONSOLE=Console/dsp				; Console interface for demo
;CONSOLE=Zap/1
;CONSOLE=Phone/phone0
IAXINFO=guest					; IAXtel username/password
;IAXINFO=myuser:mypass
TRUNK=Zap/g2					; Trunk interface
;
; Note the 'g2' in the TRUNK variable above. It specifies which group (defined
; in zapata.conf) to dial, i.e. group 2, and how to choose a channel to use in
; the specified group. The four possible options are:
;
; g: select the lowest-numbered non-busy Zap channel (aka. ascending sequential hunt group).
; G: select the highest-numbered non-busy Zap channel (aka. descending sequential hunt group).
; r: use a round-robin search, starting at the next highest channel than last time (aka. ascending rotary hunt group).
; R: use a round-robin search, starting at the next lowest channel than last time (aka. descending rotary hunt group).
;
TRUNKMSD=1					; MSD digits to strip (usually 1 or 0)
;TRUNK=IAX2/user:pass@provider

;
; Any category other than "General" and "Globals" represent 
; extension contexts, which are collections of extensions.  
;
; Extension names may be numbers, letters, or combinations
; thereof. If an extension name is prefixed by a '_'
; character, it is interpreted as a pattern rather than a
; literal.  In patterns, some characters have special meanings:
;
;   X - any digit from 0-9
;   Z - any digit from 1-9
;   N - any digit from 2-9
;   [1235-9] - any digit in the brackets (in this example, 1,2,3,5,6,7,8,9)
;   . - wildcard, matches anything remaining (e.g. _9011. matches 
;	anything starting with 9011 excluding 9011 itself)
;
; For example the extension _NXXXXXX would match normal 7 digit dialings, 
; while _1NXXNXXXXXX would represent an area code plus phone number
; preceeded by a one.
;
; Each step of an extension is ordered by priority, which must
; always start with 1 to be considered a valid extension.
;
; Contexts contain several lines, one for each step of each
; extension, which can take one of two forms as listed below,
; with the first form being preferred.  One may include another
; context in the current one as well, optionally with a
; date and time.  Included contexts are included in the order
; they are listed.
;
;[context]
;exten => someexten,priority,application(arg1,arg2,...)
;exten => someexten,priority,application,arg1|arg2...
;
; Timing list for includes is 
;
;   <time range>|<days of week>|<days of month>|<months>
;
;include => daytime|9:00-17:00|mon-fri|*|*
;
; ignorepat can be used to instruct drivers to not cancel dialtone upon
; receipt of a particular pattern.  The most commonly used example is
; of course '9' like this:
;
;ignorepat => 9
;
; so that dialtone remains even after dialing a 9.
;

;

[macro-stdexten]
;
; Standard extension macro:
;   ${ARG1} - Extension  (we could have used ${MACRO_EXTEN} here as well
;   ${ARG2} - Device(s) to ring
;   ${ARG3} - mailbox
;   ${ARG4} - context for extension
;
exten => s,1,DBget(temp=CFIM/${ARG1})
exten=s,2,Dial(Local/${temp}@${ARG4}/n,30,Ttr)   ;if redirect entry found 
exten=s,3,Dial(${ARG2},20,Ttr) ; 20sec timeout, no redirect entry found
;exten=s,4,Dial(Local/${ARG3}@${ARG4},20,Ttr) ; Mailbox when busy

 ; No CFIM key
exten=s,102,Goto(s,3)

; *********************************************************************
; All mailbox redirects taken out as calls to queues go to mailbox
; if someone isn't reachable
; *********************************************************************
 ; redirect, extension busy
;exten=s,103,Dial(Local/${ARG3}@${ARG4},20,Ttr) ; Mailbox when busy

 ; no redirect, standard extension busy
;exten=s,104,Dial(Local/${ARG3}@${ARG4},20,Ttr) ; Mailbox when busy


[merus-customers]
exten => 2000,1,Dial(SIP/01614473224@sipgate-uk,60,tr) ;Craig
exten => 2001,1,Dial(SIP/07702684341@sipgate-uk,60,tr) ;Craig Mobile
exten => 2010,1,Dial(SIP/01614473225@sipgate-uk,60,tr) ;Dave
exten => 2020,1,Dial(SIP/01614473221@sipgate-uk,60,tr) ;Jo
exten => 2030,1,Dial(SIP/01614473299@sipgate-uk,60,tr) ;Nigel
exten => 2100,1,Dial(SIP/02074651080@sipgate-uk,60,tr) ;Immy
exten => 2110,1,Dial(SIP/02074651045@sipgate-uk,60,tr) ;Theo
exten => 2200,1,Dial(SIP/01666575589@sipgate-uk,60,tr) ;Allan
exten => 2201,1,Dial(SIP/07876354706@sipgate-uk,60,tr) ;Allan Mobile
exten => 2210,1,Dial(SIP/01666575588@sipgate-uk,60,tr) ;Charlotte
exten => 2300,1,Dial(SIP/01614472519@sipgate-uk,60,tr) ;Alison Office
exten => 2301,1,Dial(SIP/07711936538@sipgate-uk,60,tr) ;Alison Mobile
exten => 2310,1,Dial(SIP/01614472027@sipgate-uk,60,tr) ;Derrick Office
exten => 2311,1,Dial(SIP/07799837837@sipgate-uk,60,tr) ;Derrick Mobile

[christian-family]
exten => 4000,1,Dial(SIP/01453767419@sipgate-uk,60,tr) ;Tal Home
exten => 4001,1,Dial(SIP/07811071262@sipgate-uk,60,tr) ;Tal Handy
exten => 4010,1,Dial(SIP/07219414279@sipgate-de,60,tr) ;Eltern Zuhause
exten => 4011,1,Dial(SIP/01601950137@sipgate-de,60,tr) ;Eltern Handy
exten => 4020,1,Dial(SIP/07219779661@sipgate-de,60,tr) ;Stefan SIP
exten => 4021,1,Dial(SIP/01776841696@sipgate-de,60,tr) ;Stefan Handy
exten => 4022,1,Dial(SIP/07219672353@sipgate-de,60,tr) ;Stefan Buero
exten => 4030,1,Dial(SIP/03082007190@sipgate-de,60,tr) ;Gerhard Zuhause
exten => 4040,1,Dial(SIP/05118039320@sipgate-de,60,tr) ;Dirk Zuhause
exten => 4041,1,Dial(SIP/01725153861@sipgate-de,60,tr) ;Dirk Handy


[merus-internal]
include => parkedcalls
include => merus-external

; sip addresses, e.g. christian@sip.merus.co.uk
exten => christian,1,Goto(merus-christian,s,1)
exten => claire,1,Goto(merus-claire,s,1)
exten => james,1,Goto(merus-james,s,1)
exten => john,1,Goto(merus-john,s,1)
exten => jonathan,1,Goto(merus-jonathan,s,1)
exten => matthew,1,Goto(merus-matthew,s,1)
exten => rachel,1,Goto(merus-rachel,s,1)
exten => merus,1,Goto(merus-menu,s,1)
exten => staff,1,Goto(merus-staffcallin,s,1)

; Christian SIP phones - both phones ring at the same time
exten => 1000,1,Macro(stdexten,1000,SIP/christian&SIP/christian3,1009,merus-internal)

; Christian mobile
exten => 1001,1,Dial(SIP/08450204215@sipgate-uk,60,Ttr)
exten => 1001,2,Hangup()

;Christian home
exten => 1002,1,Dial(SIP/01453767419@sipgate-uk,60,Ttr)
exten => 1002,2,Hangup()

; Tal's SIP phone
exten => 1003,1,Macro(stdexten,10,SIP/christian2,19,tal-internal)
exten => 1003,2,Hangup()

; Christian voicemail
exten => 1009,1,Voicemail(u1000)
exten => 1009,101,Voicemail(b1000)

;Claire SIP
exten => 1010,1,Macro(stdexten,1010,SIP/claire,1019,merus-internal)

; Claire mobile
exten => 1011,1,Dial(SIP/07870728299@sipgate-uk,60,Ttr) 
exten => 1011,2,Hangup()

; Claire home
exten => 1012,1,Dial(SIP/01454250774@sipgate-uk,30,Ttr) 
exten => 1012,2,Hangup()

; Claire voicemail
exten => 1019,1,Voicemail(u1010)
exten => 1019,101,Voicemail(b1010)

;James SIP
exten => 1020,1,Macro(stdexten,1020,SIP/james,1029,merus-internal)

; James mobile
exten => 1021,1,Dial(SIP/07812210258@sipgate-uk,60,Ttr) 
exten => 1021,2,Hangup()

; James home
exten => 1022,1,Dial(SIP/01179090229@sipgate-uk,30,Ttr) 
exten => 1022,2,Hangup()


; James voicemail
exten => 1029,1,Voicemail(u1020)
exten => 1029,101,Voicemail(b1020)

;John SIP
exten => 1030,1,Macro(stdexten,1030,SIP/john,1039,merus-internal)

; John mobile
exten => 1031,1,Dial(SIP/07980145162@sipgate-uk,60,Ttr) 
exten => 1031,2,Hangup()

; John home
exten => 1032,1,Dial(SIP/01225428045@sipgate-uk,30,Ttr) 
exten => 1032,2,Hangup()

; John voicemail
exten => 1039,1,Voicemail(u1030)
exten => 1039,101,Voicemail(b1030)

;Jonathan SIP
exten => 1040,1,Macro(stdexten,1040,SIP/jonathan,1049,merus-internal)

; Jonathan mobile
exten => 1041,1,Dial(SIP/07752488900@sipgate-uk,60,Ttr) 
exten => 1041,2,Hangup()

; Jonathan home
exten => 1042,1,Dial(SIP/01214434737@sipgate-uk,30,Ttr) 
exten => 1042,2,Hangup()

; Jonathan voicemail
exten => 1049,1,Voicemail(u1040)
exten => 1049,101,Voicemail(b1040)

;Matthew SIP
exten => 1050,1,Macro(stdexten,1050,SIP/matt,1059,merus-internal)

; Matthew mobile
exten => 1051,1,Dial(SIP/07966760499@sipgate-uk,60,Ttr) 
exten => 1051,2,Hangup()

; Matthew home
exten => 1052,1,Dial(SIP/01454853739@sipgate-uk,30,Ttr) 
exten => 1052,2,Hangup()

; Matthew voicemail
exten => 1059,1,Voicemail(u1050)
exten => 1059,101,Voicemail(b1050)

;Rachel SIP
exten => 1060,1,Macro(stdexten,1060,SIP/rachel,1069,merus-internal)

; Rachel mobile
exten => 1061,1,Dial(SIP/07981022460@sipgate-uk,60,Ttr) 
exten => 1061,2,Hangup()

; Rachel home
exten => 1062,1,Dial(SIP/01179425082@sipgate-uk,30,Ttr) 
exten => 1062,2,Hangup()

; Rachel voicemail
exten => 1069,1,Voicemail(u1060)
exten => 1069,101,Voicemail(b1060)

; call Support Queue
exten => 1098,1,Goto(merus-support,s,1)

; call Reception Queue
exten => 1099,1,Goto(merus-reception,s,1)



[external-de]
; Germany through sipgate.de
exten => _0049.,1,Dial(SIP/0${EXTEN:4}@sipgate-de,90,Ttr) 
exten => _0049.,2,Hangup()
exten => _0049.,103,NoOp()
exten => _0049.,104,Playtones(congestion)
exten => _0049.,105,Congestion()

[external-international]
exten => _00.,1,Dial(SIP/${EXTEN:0}@sipgate-de,90,Ttr) 
exten => _00.,2,Hangup()
exten => _00.,103,NoOp()
exten => _00.,104,Playtones(congestion)
exten => _00.,105,Congestion()


[merus-external]
include => external-de
include => external-international

; UK 0... through sipgate.co.uk
exten => _0Z.,1,Dial(SIP/${EXTEN:0}@sipgate-uk,180,Ttr) 
exten => _0Z.,2,Hangup()
exten => _0Z.,103,NoOp()
exten => _0Z.,104,Playtones(congestion)
exten => _0Z.,105,Congestion()

; 09 numbers - fuck off!
exten => _09.,1,Playback(invalid)

exten => t,1,Hangup

[merus-staffcallin]
; this is the context for our 0800 916 8564 number
exten => s/07866496106,1,Goto(merus-internal-christian,s,1)
exten => s/447866496106,1,Goto(merus-internal-christian,s,1)
exten => s/07765618960,1,Goto(merus-internal-christian,s,1)
exten => s/01453767419,1,Goto(merus-internal-christian,s,1)
exten => s/07870728299,1,Goto(merus-internal-claire,s,1)
exten => s/01454250774,1,Goto(merus-internal-claire,s,1)
exten => s/07812210258,1,Goto(merus-internal-james,s,1)
exten => s/01179090229,1,Goto(merus-internal-james,s,1)
exten => s/07980145162,1,Goto(merus-internal-john,s,1)
exten => s/01225428045,1,Goto(merus-internal-john,s,1)
exten => s/07752488900,1,Goto(merus-internal-jonathan,s,1)
exten => s/01214434737,1,Goto(merus-internal-jonathan,s,1)
exten => s/07966760499,1,Goto(merus-internal-matt,s,1)
exten => s/01454853739,1,Goto(merus-internal-matt,s,1)
exten => s/07981022460,1,Goto(merus-internal-rachel,s,1)
exten => s/01779425082,1,Goto(merus-internal-rachel,s,1)
exten => s,1,Authenticate(/etc/asterisk/passwords|a)
exten => s,2,SetCallerID("0800Dial" <${ACCOUNTCODE:4}>)
exten => s,3,Goto(merus-staff,s,1)

[merus-menu]
include => merus-daytime|7:30-21:00|mon-fri|*|*
include => merus-nighttime|21:00-7:30|mon-fri|*|*
include => merus-weekend|00:00-23:59|sat-sun|*|*


[merus-daytime]
exten => s,1,Answer ; Answer the line
exten => s,2,Goto(merus-reception,s,1)
exten => s,3,Hangup()

[merus-daytime-menu]
exten => s,1,Answer ; Answer the line
exten => s,2,DigitTimeout,2
exten => s,3,ResponseTimeout,10 ; Set Response Timeout to 10 seconds
exten => s,4,BackGround(merus-welcome) ; Play main menu.
exten => 1,1,Goto(merus-support,s,1)
exten => 2,1,Goto(merus-staffmenu,s,1)
exten => 3,1,Goto(merus-reception,s,1)
exten => i,1,Playback(invalid)
; on timeout, go to merus-reception
exten => t,1,Goto(merus-reception,s,1)

[merus-nighttime]
exten => s,1,Answer ; Answer the line
exten => s,2,BackGround(merus-nighttime) ; Play nighttime announcement.
exten => 1,1,Goto(merus-christian,s,1)
exten => i,1,Playback(invalid)
exten => t,1,Hangup()

[merus-weekend]
exten => s,1,Answer ; Answer the line
exten => s,2,BackGround(merus-weekend) ; Play nighttime announcement.
exten => 1,1,Goto(merus-christian,s,1)
exten => i,1,Playback(invalid)
exten => t,1,Hangup()

[merus-staffmenu]
exten => s,1,BackGround(merus-staffmenu) 
exten => 1,1,Goto(merus-christian,s,1)
exten => 2,1,Goto(merus-claire,s,1)
exten => 3,1,Goto(merus-james,s,1)
exten => 4,1,Goto(merus-john,s,1)
exten => 5,1,Goto(merus-jonathan,s,1)
exten => 6,1,Goto(merus-matthew,s,1)
exten => 7,1,Goto(merus-rachel,s,1)
exten => i,1,Playback(invalid)
exten => t,1,Goto(merus-daytime,s,1)

[merus-christian]
; this entry will allow christian to make calls via our PABX when he is
; over in Germany using his mobile dialing the Berlin number
exten => s/447866496106,1,Goto(merus-internal-christian,s,1)
exten => s,1,Dial(Local/1000@merus-internal,40,Ttr)
exten => s,2,Hangup

[merus-claire]
exten => s,1,Dial(Local/1010@merus-internal,40,Ttr)
exten => s,2,Hangup

[merus-james]
exten => s,1,Dial(Local/1020@merus-internal,40,Ttr)
exten => s,2,Hangup

[merus-john]
exten => s,1,Dial(Local/1030@merus-internal,40,Ttr)
exten => s,2,Hangup

[merus-jonathan]
exten => s,1,Dial(Local/1040@merus-internal,40,Ttr)
exten => s,2,Hangup

[merus-matthew]
exten => s,1,Dial(Local/1050@merus-internal,40,Ttr)
exten => s,2,Hangup

[merus-rachel]
exten => s,1,Dial(Local/1060@merus-internal,40,Ttr)
exten => s,2,Hangup

[merus-support]
exten => s,1,Playback(merus-support) 
exten => s,2,SetVar(QUEUE_PRIO=10)
exten => s,3,SetCIDName(Support ${CALLERIDNAME})
exten => s,4,Queue(support,Ttr)
exten => s,5,Hangup

[merus-reception]
exten => s,1,SetVar(QUEUE_PRIO=10)
exten => s,2,SetCIDName(Reception ${CALLERIDNAME})
exten => s,3,Queue(reception,Ttr)
exten => s,4,Hangup


[incoming]
include => parkedcalls

;sipgate-uk calls to 01453 808000
exten => 9991283,1,SetCIDName(Merus ${CALLERIDNAME})
exten => 9991283,2,Goto(merus-menu,s,1)
;sipgate-uk calls to 0207 100 1344
exten => 1001344,1,SetCIDName(London ${CALLERIDNAME})
exten => 1001344,2,Goto(merus-staffcallin,s,1)
;sipgate-uk calls to 01453 808230
exten => 3808230,1,SetCIDName(Tal ${CALLERIDNAME})
exten => 3808230,2,Goto(tal-incoming,s,1)
;sipgate-de calls go do internal 1000
exten => 6260978,1,SetCIDName(Berlin ${CALLERIDNAME})
exten => 6260978,2,Goto(merus-christian,s,1)
 
[default]
; we need this so that agent log in works
include => merus-internal
include => other

[merus-sipphone]
; internal context for Merus SIP phones
include => parkedcalls
include => merus-internal
include => merus-customers
include => christian-family
include => merus-external
include => other
; if you dial 9275 from your internal phone, you end up in the customer
; facing menu (for testing)
exten => 9275,1,Goto(merus-menu,s,1)

[other]
; register call forwarding with 99 + new destination
exten => _99X.,1,DBput(CFIM/${CALLERIDNUM}=${EXTEN:2})
exten => _99X.,2,Playback(merus-callforward)
exten => _99X.,3,SayDigits(${EXTEN:2})
exten => _99X.,4,Hangup

; de-register call forwarding
exten => 99,1,DBdel(CFIM/${CALLERIDNUM})
exten => 99,2,Playback(merus-noforward)
exten => 99,3,Hangup

; used to record prompts
exten => 205,1,Wait(1)
exten => 205,2,Record(/tmp/asterisk-recording:gsm)
exten => 205,3,Wait(1)
exten => 205,4,Playback(/tmp/asterisk-recording)
exten => 205,5,Wait(1)
exten => 205,6,Hangup 

; Agent Callback Login
exten => 700,1,AgentCallbackLogin(${CALLERIDNUM}|${CALLERIDNUM})

; Agent Callback log off
exten => 701,1,Dial(Local/702/n,,D(#))

; don't dial that directly, only needed to make the logout work
exten => 702,1,AgentCallbackLogin(${CALLERIDNUM}|'#')
exten => 702,2,Hangup 

exten => 703,1,AgentCallbackLogin()
exten => 703,2,Hangup


exten => 8500,1,VoicemailMain
;exten => 8500,2,Hangup
;
; Or a conference room (you'll need to edit meetme.conf to enable this room)
; (This won't work without a dummy zaptel device :-( )
;
; app_conference
;exten => 8000,1,Conference(Merus1/S/1)
;
;exten => 8600,1,MeetMe(1234)
;
; Create an extension, 600, for evaulating echo latency.
;
exten => 600,1,Playback(demo-echotest)	; Let them know what's going on
exten => 600,2,Echo			; Do the echo test
exten => 600,3,Playback(demo-echodone)	; Let them know it's over
exten => 600,4,Goto(s,6)		; Start over


[merus-internal-christian]
exten => s,1,SetCallerID("Christian" <1000>)
exten => s,2,Goto(merus-staff,s,1)

[merus-internal-claire]
exten => s,1,SetCallerID("Claire" <1010>)
exten => s,2,Goto(merus-staff,s,1)

[merus-internal-james]
exten => s,1,SetCallerID("James" <1020>)
exten => s,2,Goto(merus-staff,s,1)

[merus-internal-john]
exten => s,1,SetCallerID("John" <1030>)
exten => s,2,Goto(merus-staff,s,1)

[merus-internal-jonathan]
exten => s,1,SetCallerID("Jonathan" <1040>)
exten => s,2,Goto(merus-staff,s,1)

[merus-internal-matt]
exten => s,1,SetCallerID("Matt" <1050>)
exten => s,2,Goto(merus-staff,s,1)

[merus-internal-rachel]
exten => s,1,SetCallerID("Rachel" <1060>)
exten => s,2,Goto(merus-staff,s,1)


[merus-staff]
; this context is used if an outside caller enters the pin number
; (staff working away from SIP phone can get into the internal context
; of the PABX this way) or calls from his mobile
include => merus-internal
include => merus-customers
include => christian-family
include => merus-external
include => other
include => parkedcalls

exten => s,1,BackGround(merus-staff-internal)
exten => s,2,ResponseTimeout,20 ; Set Response Timeout to 10 seconds
exten => i,1,Playback(invalid)
exten => t,1,Hangup()

;------------------------------------------------------------------------
; Config for Tal's phone here
;------------------------------------------------------------------------

[tal-sipphone]
; context for SIP phone christian2 from sip.conf
include => parkedcalls
include => other
include => tal-outgoing
include => tal-internal

[tal-internal]
exten => 10,1,Macro(stdexten,10,SIP/christian2,19,tal-internal)
exten => 10,2,Hangup()

exten => 11,1,Dial(SIP/07811071262@sipgate-tal,90,Ttr)
exten => 11,2,Hangup()

exten => 12,1,Macro(stdexten,1000,SIP/christian&SIP/christian3,1009,merus-internal)
exten => 12,2,Hangup()

exten => 19,1,Voicemail(u10)
exten => 19,101,Voicemail(b10)

[tal-outgoing]
include => parkedcalls
include => external-de
include => external-international

exten => _0Z.,1,Dial(SIP/${EXTEN:0}@sipgate-tal,90,Ttr) 
exten => _0Z.,2,Hangup()

[tal-incoming]
include => tal-internal
include => tal-outgoing
include => tal-sipphone
include => parkedcalls
exten => s,1,Dial(Local/10@tal-internal,60,Ttr)
exten => s,2,Hangup

