; extensions.conf - the Asterisk dial plan
;
; 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 "dialplan 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 "dialplan save" too
;
writeprotect=no
;
; If autofallthrough is set, then if an extension runs out of
; things to do, it will terminate the call with BUSY, CONGESTION
; or HANGUP depending on Asterisk's best guess. This is the default.
;
; If autofallthrough is not set, then if an extension runs out of
; things to do, Asterisk will wait for a new extension to be dialed
; (this is the original behavior of Asterisk 1.0 and earlier).
;
;
;
clearglobalvars=no
;
;
;

;
[globals]

theAccount=2000
;
; 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)
;   ! - wildcard, causes the matching process to complete as soon as
;       it can unambiguously determine that no other matches are possible
;
; For example, the extension _NXXXXXX would match normal 7 digit dialings,
; while _1NXXNXXXXXX would represent an area code plus phone number
; preceded by a one.
;
; Each step of an extension is ordered by priority, which must always start
; with 1 to be considered a valid extension.  The priority "next" or "n" means
; the previous priority plus one, regardless of whether the previous priority
; was associated with the current extension or not.  The priority "same" or "s"
; means the same as the previously specified priority, again regardless of
; whether the previous entry was for the same extension.  Priorities may be
; immediately followed by a plus sign and another integer to add that amount
; (most useful with 's' or 'n').  Priorities may then also have an alias, or
; label, in parentheses after their name which can be used in goto situations.
;
; Contexts contain several lines, one for each step of each extension.  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.
; Switches may also be included within a context.  The order of matching within
; a context is always exact extensions, pattern match extensions, includes, and
; switches.  Includes are always processed depth-first.  So for example, if you
; would like a switch "A" to match before context "B", simply put switch "A" in
; an included context "C", where "C" is included in your original context
; before "B".
;
;[context]
;exten => someexten,{priority|label{+|-}offset}[(alias)],application(arg1,arg2,...)
;
; Timing list for includes is
;
;   <time range>,<days of week>,<days of month>,<months>[,<timezone>]
;
; Note that ranges may be specified to wrap around the ends.  Also, minutes are
; fine-grained only down to the closest even minute.
;
;include => daytime,9:00-17:00,mon-fri,*,*
;include => weekend,*,sat-sun,*,*
;include => weeknights,17:02-8:58,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.  Please note that ignorepat
; only works with channels which receive dialtone from the PBX, such as DAHDI,
; Phone, and VPB.  Other channels, such as SIP and MGCP, which generate their
; own dialtone and converse with the PBX only after a number is complete, are
; generally unaffected by ignorepat (unless DISA or another method is used to
; generate a dialtone after answering the channel).
;

;
; Sample entries for extensions.conf
;
[macro-dundi-e164]
;
; ARG1 is the extension to Dial
;
; Extension "s" is not a wildcard extension that matches "anything".
; In macros, it is the start extension. In most other cases,
; you have to goto "s" to execute that extension.
;
; Note: In old versions of Asterisk the PBX in some cases defaulted to
; extension "s" when a given extension was wrong (like in AMI originate).
; This is no longer the case.
;
; For wildcard matches, see above - all pattern matches start with
; an underscore.
; pld exten => s,1,Goto(${ARG1},1)
; pld include => dundi-e164-lookup

;
; Here are the entries you need to participate in the IAXTEL
; call routing system.  Most IAXTEL numbers begin with 1-700, but
; there are exceptions.  For more information, and to sign
; up, please go to www.gnophone.com or www.iaxtel.com
;

[macro-phone]
;;exten => s,1,Dial(SIP/${MACRO_EXTEN},25) ;; this is stupid; it assumes channelname==extension_num
exten => s,1,Dial(${ARG1},15)
exten => s,n,Goto(${DIALSTATUS},1)
exten => ANSWER,1,Hangup
exten => CANCEL,1,Hangup
exten => NOANSWER,1,Voicemail(${MACRO_EXTEN}@default,u)
exten => BUSY,1,Voicemail(${MACRO_EXTEN}@default,b)
exten => CONGESTION,1,Voicemail(${MACRO_EXTEN}@default,b)
exten => CHANUNAVAIL,1,Voicemail(${MACRO_EXTEN}@default,u)
exten => a,1,VoicemailMain(${MACRO_EXTEN}@default)

[demo]
;include => stdexten
;
; We start with what to do when a call first comes in.
;
; pld exten => s,1,Wait(1)			; Wait a second, just for fun
; pld exten => s,n,Answer			; Answer the line
; pld exten => s,n,Set(TIMEOUT(digit)=5)	; Set Digit Timeout to 5 seconds
; pld exten => s,n,Set(TIMEOUT(response)=10)	; Set Response Timeout to 10 seconds
; pld exten => s,n(restart),BackGround(demo-congrats)	; Play a congratulatory message
; pld exten => s,n(instruct),BackGround(demo-instruct)	; Play some instructions
; pld exten => s,n,WaitExten			; Wait for an extension to be dialed.

; pld exten => 2,1,BackGround(demo-moreinfo)	; Give some more information.
; pld exten => 2,n,Goto(s,instruct)

; pld exten => 3,1,Set(CHANNEL(language)=fr)		; Set language to french
; pld exten => 3,n,Goto(s,restart)		; Start with the congratulations

; pld exten => 1000,1,Goto(default,s,1)
;
; We also create an example user, 1234, who is on the console and has
; voicemail, etc.
;
; pld exten => 1234,1,Playback(transfer,skip)		; "Please hold while..."
					; (but skip if channel is not up)
; pld exten => 1234,n,Gosub(${EXTEN},stdexten(${GLOBAL(CONSOLE)}))
; pld exten => 1234,n,Goto(default,s,1)		; exited Voicemail

; pld exten => 1235,1,Voicemail(1234,u)		; Right to voicemail

; pld exten => 1236,1,Dial(Console/dsp)		; Ring forever
; pld exten => 1236,n,Voicemail(1234,b)		; Unless busy

;
; # for when they're done with the demo
;
; pld exten => #,1,Playback(demo-thanks)	; "Thanks for trying the demo"
; pld exten => #,n,Hangup			; Hang them up.

;
; A timeout and "invalid extension rule"
;
; pld exten => t,1,Goto(#,1)			; If they take too long, give up
; pld exten => i,1,Playback(invalid)		; "That's not valid, try again"

;
; Create an extension, 500, for dialing the
; Asterisk demo.
;
; pld exten => 500,1,Playback(demo-abouttotry); Let them know what's going on
; pld exten => 500,n,Dial(IAX2/guest@pbx.digium.com/s@default)	; Call the Asterisk demo
; pld exten => 500,n,Playback(demo-nogo)	; Couldn't connect to the demo site
; pld exten => 500,n,Goto(s,6)		; Return to the start over message.

;
; Create an extension, 600, for evaluating echo latency.
;
; pld exten => 600,1,Playback(demo-echotest)	; Let them know what's going on
; pld exten => 600,n,Echo			; Do the echo test
; pld exten => 600,n,Playback(demo-echodone)	; Let them know it's over
; pld exten => 600,n,Goto(s,6)		; Start over

;
;	You can use the Macro Page to intercom a individual user
; pld exten => 76245,1,Macro(page,SIP/Grandstream1)
; or if your peernames are the same as extensions
; pld exten => _7XXX,1,Macro(page,SIP/${EXTEN})
;
;
; System Wide Page at extension 7999
;
; pld exten => 7999,1,Set(TIMEOUT(absolute)=60)
; pld exten => 7999,2,Page(Local/Grandstream1@page&Local/Xlite1@page&Local/1234@page/n,d)

; Give voicemail at extension 8500
;
; pld exten => 8500,1,VoicemailMain
; pld exten => 8500,n,Goto(s,6)
;
; Here's what a phone entry would look like (IXJ for example)
;
;exten => 1265,1,Dial(Phone/phone0,15)
;exten => 1265,n,Goto(s,5)

;
;	The page context calls up the page macro that sets variables needed for auto-answer
;	It is in is own context to make calling it from the Page() application as simple as
;	Local/{peername}@page
;

[menudemo]

exten => start,1,Answer
 same => n,Playback(hello-world)
 same => n,Background(oneortwo)  ;Background is like Playback that can be interrupted by keypresses
 same => n,WaitExten(10)
 same => n,Playback(vm-goodbye)

exten => 1,1,Playback(digits/1)
 same => n,Goto(start,3)

exten => 2,1,Playback(digits/2)
 same => n,Goto(start,3)

exten => 3,1,Playback(twisty-maze)
 same => n,Goto(start,3)

exten => 4,1,Playback(yourcallisimpotent)
 same => n,Goto(start,3)

exten => 5,1,Playback(tt-weasels) ; also weasels-eaten-phonesys.gsm
 same => n,Goto(start,3)

exten => 6,1,Playback(enternumber)
 same => n,Read(theNum)
 same => n,SayDigits(${theNum})
 same => n,Goto(start,3)

exten => 7,1,Playback(you-seem-impatient)
 same => n,Goto(start,3)

exten => 8,1,Playback(zombies)
 same => n,Goto(start,3)

exten => _X,1,Playback(digits/${EXTEN})
 same => n,Playback(wrong)

[dbdemo]

exten => start,1,Answer
 same => n,Background(yourkeyis)
 same => n,SayDigits(${theAccount})
 same => n,Noop(The_account_is${theAccount})
 same => n,Background(onetwothreemagic)    ;; 1 = get value, 2 = set value 
 same => n,WaitExten(10)
 same => n,Playback(vm-goodbye)

exten => 1,1,Playback(digits/1)   ;; set account
 same => n,Background(enterkey)
 same => n,Read(theAccount)
 same => n,Noop(The_account_is${theAccount})
 same => n,Noop(The_value_is:${DB(dbdemo/${theAccount})}:)
 same => n,Background(yourkeyis)
 same => n,SayNumber(${theAccount})
 same => n,GotoIf($[${LEN(${DB(dbdemo/${theAccount})})}=0]?end:speak)
 same => n(speak),Background(yourmagicis)
 same => n,SayDigits(${DB(dbdemo/${theAccount})})
 same => n(end),Goto(start,4)

exten => 2,1,Playback(digits/2)   ;; get magic
 same => n,Background(yourmagicis)
 same => n,SayDigits(${DB(dbdemo/${theAccount})})
; same => n,Read(theValue)
; same => n,Set(DB(dbdemo/${theAccount})=${theValue})
 same => n,Goto(start,1)

exten => 3,1,Playback(digits/3)   ;; set magic
 same => n,Background(entermagic)
 same => n,Read(theMagic)
 same => n,Set(DB(dbdemo/${theAccount})=${theMagic})
 same => n,Goto(start,1)

exten => _X,1,Playback(digits/${EXTEN})
 same => n,Playback(wrong)

[public]
;
; ATTENTION: If your Asterisk is connected to the internet and you do
; not have allowguest=no in sip.conf, everybody out there may use your
; public context without authentication.  In that case you want to
; double check which services you offer to the world.
;
;include => demo

[default]
;
; By default we include the demo.  In a production system, you
; probably don't want to have the demo there.
;
;include => demo

exten => 2000,1,Playback(hello-world)
same =>  n,Hangup

exten => 2001,1,Answer()
same =>  n,Playback(cantdo)
same =>  n,Hangup

exten => 2002,1,Answer()
same =>  n,Playback(yournumber)
;same =>  n,SayDigits("1234")
same =>  n,SayDigits(${CALLERID(num)})   ;; note ${..}
same =>  n,Playback(vm-goodbye)
same =>  n,Hangup

exten => 2003,1,Answer()
same =>  n,Playback(yournumber)
same =>  n,SayDigits(${SIP_HEADER(P-Asserted-Identity)})   ;; note ${..}
same =>  n,Playback(vm-goodbye)
same =>  n,Hangup

exten => 2004,1,Goto(menudemo,start,1)

exten => 2005,1,Goto(dbdemo,start,1)

exten => 2006,1,Answer()
 same => n,Playback(demo-echotest) ; Let them know what's going on
 same => n,Echo                 ; Do the echo test
 same => n,Playback(demo-echodone)      ; Let them know it's over
 same => n,Goto(s,6)            ; Start over

exten => 2007,1,Answer()
 same => n,Voicemail(2007@default,u)


exten => 3031,1,Dial(SIP/cisco55311eline1, 15)    ;;    , rT)
same  => n,Voicemail(3031@default,u)
same  => n,hangup

exten => 3032,1,Dial(SIP/cisco55311eline2, 15)    ;;    , rT)
same  => n,Voicemail(3032@default,u)
same  => n,hangup

exten => 3033,1,Dial(SIP/cisco55311eline3, 15)    ;;    , rT)
same  => n,Voicemail(3033@default,u)
same  => n,hangup

include => outgoing

; cobhill house phone
exten => 9920,1,Macro(phone,SIP/cobhill&SIP/cisco5534e4line3)


[outgoing]

;; do not process any inbound calls here!!

;; #include cobhill.conf

exten => _1NXXXXXXXXX,1,Dial(SIP/${EXTEN}@flowroute)
exten => _NXXXXXXXXX,1,Dial(SIP/1${EXTEN}@flowroute)

;; for Loyola extensions
exten => _5XXXX,1,Dial(SIP/131291${EXTEN}@flowroute)
exten => _8XXXX,1,Dial(SIP/177350${EXTEN}@flowroute)


[inbound]    ;; calls from flowroute to our numbers

; exten => 17734094359,1,Playback(cantdo)
; exten => 17734094359,1,Playback(hello-world)
; exten => 17734094359,1,Dial(SIP/3031)   ;; forward to SIP phone
;exten => 17734094359,1,Dial(3042)
;exten => 17734094359,1,Macro(phone,SIP/cisco5534e4line1)

;; uncomment this to point the number to the conference line
;exten => 17734094359,1,Goto(default,4000,1)

; forward 409-4359 to an extension
;exten => 17734094359,1,Goto(default,3033,1)
exten => 17734094359,1,Goto(default,3031,1)

exten => 18158286071,1,Goto(default,2001,1)

; forward 773-409-4359 to pld
;exten => 17734094359,1,Dial(SIP/18157579920@flowroute)

; cobhill phone

exten => 18158249920,1,Goto(default,9920,1)
exten =>  8158249920,1,Goto(default,9920,1)


; For more information on applications, just type "core show applications" at your
; friendly Asterisk CLI prompt.
;
; "core show application <command>" will show details of how you
; use that particular application in this file, the dial plan.
; "core show functions" will list all dialplan functions
; "core show function <COMMAND>" will show you more information about
; one function. Remember that function names are UPPER CASE.
