Asterisk 1.4.22 / Freepbx 2.5 - Create custom contexts and extensions
Why create a different context other than the default?
Contexts allow us to partition peers and extensions, creating
dial policies for individials or groups.
For example, in a corporate office, you may want regular
employees to only reach HR department extensions, while
HR personnel are allowed to reach everyone (billing deparment,
regular employees..etc)
Freepbx's default context used by internal extensions are
"from-internal" and "from-internal-custom". The latter
is used to include custom contexts. This means that any user
under the "from-internal" context can reach our custom context
but not the other way around.
; Here's our example
; sip_additional.conf ----------------------------
; All extensions were added using freepbx's gui.
; This makes configuration, enabling features easier (Recording, VM..etc)
; Take note that we applied the appropriate contexts for each.
[1001]
;regular employee
type=friend
secret=ext1001
qualify=yes
port=5060
nat=yes
mailbox=1001@device
host=dynamic
dtmfmode=rfc2833
dial=SIP/1001
context=from-internal-employee
canreinvite=no
callerid=device <1001>
call-limit=50
[2001]
;HR
type=friend
secret=ext2001
qualify=yes
port=5060
nat=yes
mailbox=2001@device
host=dynamic
dtmfmode=rfc2833
dial=SIP/2001
context=from-internal
canreinvite=no
callerid=device <2001>
call-limit=50
[3001]
;billing department
type=friend
secret=ext3001
qualify=yes
port=5060
nat=yes
mailbox=3001@device
host=dynamic
dtmfmode=rfc2833
dial=SIP/3001
context=from-internal
canreinvite=no
callerid=device <3001>
call-limit=50
;extensions_custom.conf ----------------------------
[from-internal-custom]
;enables call transfer to PSTN using the sip client's features
;not the freepbx internal transfer function
include => from-internal-employee-pstn
;for regular employees, create main and sub context:
;put local extension routes under their main context
;place outbound PSTN routes under their main context's subcontext
[from-internal-employee]
;regular employee extensions
include => from-internal-employee-pstn
exten => _100X,1,Macro(user-callerid)
exten => _100X,n,Macro(record-enable,${AMPUSER},OUT,)
exten => _100X,n,Dial(Local/${EXTEN}@from-internal/n)
exten => _100X,n,Hangup
[from-internal-employee-pstn]
;regular employee pstn routes
exten => _1XXXXXXXXXX,1,Macro(user-callerid)
exten => _1XXXXXXXXXX,n,Macro(record-enable,${AMPUSER},OUT,)
exten => _1XXXXXXXXXX,n,Dial(SIP/pstn-gw/${EXTEN})
exten => _1XXXXXXXXXX,n,Hangup
;The macros used here are internal to freepbx and should be
;used to provide known system features to these custom routes
;(call recording, caller id passing, voicemail..etc
;
;Macro(record-enable,${AMPUSER},OUT,)
;Macro(user-callerid)
;Dial(Local/${EXTEN}@from-internal/n)
;Since HR needs both access to regular employees and billing,
;we only need to create HR extensions in freepbx with a
;default context.
Asterisk 1.4.22 / Freepbx 2.5 - Create custom contexts and extensions
Why create a different context other than the default?
Contexts allow us to partition peers and extensions, creating
dial policies for individials or groups.
For example, in a corporate office, you may want regular
employees to only reach HR department extensions, while
HR personnel are allowed to reach everyone (billing deparment,
regular employees..etc)
Freepbx's default context used by internal extensions are
"from-internal" and "from-internal-custom". The latter
is used to include custom contexts. This means that any user
under the "from-internal" context can reach our custom context
but not the other way around.
; Here's our example
; sip_additional.conf ----------------------------
; All extensions were added using freepbx's gui.
; This makes configuration, enabling features easier (Recording, VM..etc)
; Take note that we applied the appropriate contexts for each.
[1001]
;regular employee
type=friend
secret=ext1001
qualify=yes
port=5060
nat=yes
mailbox=1001@device
host=dynamic
dtmfmode=rfc2833
dial=SIP/1001
context=from-internal-employee
canreinvite=no
callerid=device <1001>
call-limit=50
[2001]
;HR
type=friend
secret=ext2001
qualify=yes
port=5060
nat=yes
mailbox=2001@device
host=dynamic
dtmfmode=rfc2833
dial=SIP/2001
context=from-internal
canreinvite=no
callerid=device <2001>
call-limit=50
[3001]
;billing department
type=friend
secret=ext3001
qualify=yes
port=5060
nat=yes
mailbox=3001@device
host=dynamic
dtmfmode=rfc2833
dial=SIP/3001
context=from-internal
canreinvite=no
callerid=device <3001>
call-limit=50
;extensions_custom.conf ----------------------------
[from-internal-custom]
;enables call transfer to PSTN using the sip client's features
;not the freepbx internal transfer function
include => from-internal-employee-pstn
;for regular employees, create main and sub context:
;put local extension routes under their main context
;place outbound PSTN routes under their main context's subcontext
[from-internal-employee]
;regular employee extensions
include => from-internal-employee-pstn
exten => _100X,1,Macro(user-callerid)
exten => _100X,n,Macro(record-enable,${AMPUSER},OUT,)
exten => _100X,n,Dial(Local/${EXTEN}@from-internal/n)
exten => _100X,n,Hangup
[from-internal-employee-pstn]
;regular employee pstn routes
exten => _1XXXXXXXXXX,1,Macro(user-callerid)
exten => _1XXXXXXXXXX,n,Macro(record-enable,${AMPUSER},OUT,)
exten => _1XXXXXXXXXX,n,Dial(SIP/pstn-gw/${EXTEN})
exten => _1XXXXXXXXXX,n,Hangup
;The macros used here are internal to freepbx and should be
;used to provide known system features to these custom routes
;(call recording, caller id passing, voicemail..etc
;
;Macro(record-enable,${AMPUSER},OUT,)
;Macro(user-callerid)
;Dial(Local/${EXTEN}@from-internal/n)
;Since HR needs both access to regular employees and billing,
;we only need to create HR extensions in freepbx with a
;default context.