Including contexts within context

Hi,

Let’s say I have a simple dialplan like this one:

[default]
exten => _XXXX,1,NoOp(${CALLERID(all)} is dialing ${EXTEN})
same => n,Gosub(custom-dialout-1,s,1(${EXTEN}))
same => n,Gosub(custom-dialout-2,s,1(${EXTEN}))
same => n,Hangup()

include => to-extensions
include => outbound
include => invalid

[to-extensions]
#tryinclude custom_extensions/*.conf

An example .conf file in custom_extensions would be:

exten => 1000,hint,PJSIP/${EXTEN}&PJSIP/web${EXTEN}
exten => 1000,1,NoOp(${CALLERID(num)} is calling 1000)
same => n,Set(CDR(userfield)=SIPCALLID:${CHANNEL(pjsip,call-id)})
same => n,Dial(PJSIP/${EXTEN}&PJSIP/web${EXTEN},,tTXg)
same => n,Log(NOTICE, ${EXTEN} dial status is ${DIALSTATUS})
same => n(hangup),Hangup()

If I were to dial 1000 would it match the _XXXX pattern in default first or ‘1000’ in to-extensions?

I’m asking because no matter where I place “includes =>” a ‘dialplan show’ will always move them at the end of a context.

eg.:

# asterisk -rx "dialplan show default"
[ Context 'default' created by 'pbx_config' ]
  '_XXXX' =>        1. NoOp(${CALLERID(all)} is dialing ${EXTEN}) [extensions.conf:5]
                    2. Gosub(custom-dialout-1,s,1(${EXTEN})) [extensions.conf:6]
                    3. Gosub(custom-dialout-2,s,1(${EXTEN})) [extensions.conf:7]
                    4. Hangup()                                   [extensions.conf:8]
  Include =>        'to-extensions'                               [pbx_config]
  Include =>        'outbound'                                    [pbx_config]
  Include =>        'invalid'                                     [pbx_config]

I think the order of the includes or patterns is irrelevant, right?
I believe it all boils down to whether a pattern is more specific than another.

However, what would happen if I were to add:

exten => _X.,1,NoOp(catch-all pattern)
same => n,Hangup()

at the very top of the [default] context and I were to dial 1000?
Would it match _X., ‘1000’ or _XXXX?

Vieri

According to
https://wiki.asterisk.org/wiki/display/AST/Include+Statements+Basics
“The order in which Asterisk tries to find a matching extension is always current context first, then all the include statements.”.

That is obviously not what I want here because I need to match all of the patterns within all the “includes” at the same time as the top-level context.

Is there an option to change Asterisk’s behavior or maybe a different approach to include a context before the rest of the dialplan.

eg.:

[default]
include => to-extensions

exten => _XXXX,1,NoOp(${CALLERID(all)} is dialing ${EXTEN})
same => n,Gosub(custom-dialout-1,s,1(${EXTEN}))
same => n,Gosub(custom-dialout-2,s,1(${EXTEN}))
same => n,Hangup()

include => outbound
include => invalid

In this case I want Asterisk to try to match patterns in [to-extensions] FIRST then try to match _XXXX and finally try to match in [outbound] and [invalid].

Is that possible?
How?

Would this be the only way?

[default]
include => to-extensions
include => new-context
include => outbound
include => invalid

[new-context]
exten => _XXXX,1,NoOp(${CALLERID(all)} is dialing ${EXTEN})
same => n,Gosub(custom-dialout-1,s,1(${EXTEN}))
same => n,Gosub(custom-dialout-2,s,1(${EXTEN}))
same => n,Hangup()

That is how it is done, by having a context include others in the order you want.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.