The Hitchhiker's Guide to Asterisk | ||
---|---|---|
<<< Previous | Creating Dialplans | Next >>> |
[Explain the ${EXTEN} variable, along with the ${EXTEN:i:j} syntax] [Example of a simple "outbound" context]
In extensions.conf we are not limited simply to numbers. We are able to match patterns of numbers to control our call flow. To do this we start an extension "number" with an underscore symbol (_). Asterisk recognizes certain characters to interpret special meaning when doing a pattern match. These characters include:
X - matches any digit from 0-0 |
Z - matches any digit from 1-9 |
N - matches any digit from 2-9 |
[1237-9] - matches any digit or letter in the brackets (ex. 1,2,3,7,8,9) |
. - wildcard match which matches one or more characters |
When creating your patterns take note that the order in which you add them to your extensions.conf is not necessarily the order in which they are executed. Asterisk will sort your extensions in numerical order followed by alphabetical order. Lets use an example to show how this works.
[sort-order] exten => _1NXX.,1,Dial(SIP/${EXTEN}) exten => _1800.,1,Dial(SIP/${EXTEN}) exten => _.,1,Dial(SIP/${EXTEN}) exten => t,1,Hangup |
We can check the order in which Asterisk sorted this example by doing a show dialplan sort-order.
*CLI> show dialplan sort-order [ Context 'sort-order' created by 'pbx_config' ] '_.' => 1. Dial(SIP/${EXTEN}) [pbx_config] '_1800.' => 1. Dial(SIP/${EXTEN}) [pbx_config] '_1NXX.' => 1. Dial(SIP/${EXTEN}) [pbx_config] 't' => 1. Hangup() [pbx_config] |
As we can see the order is different than that which we placed in our extensions.conf. To control the order in which Asterisk will sort the pattern matching we have to use includes. When using an include the extension entries within the context are sorted first followed by the included extensions. The includes are then tested in the order which you add them to the context.
The following example shows how we can move the wildcard pattern (_.) to the end of the sort order.
[sort-order] include => sort-order-wildcard exten => _1NXX.,1,Dial(SIP/${EXTEN}) exten => _1800.,1,Dial(SIP/${EXTEN}) exten => t,1,Hangup [sort-order-wildcard] exten => _.,1,Dial(SIP/${EXTEN}) |
*CLI> show dialplan sort-order [ Context 'sort-order' created by 'pbx_config' ] '_1800.' => 1. Dial(SIP/${EXTEN}) [pbx_config] '_1NXX.' => 1. Dial(SIP/${EXTEN}) [pbx_config] 't' => 1. Hangup() [pbx_config] Include => 'sort-order-wildcard' [pbx_config] |
[How to do it] [Order of includes count! Explain why...] [Time-sensitive includes] [OK, now let's "include" the "outbound" context inside of the "internal" context]
's' - start |
'i' - invalid |
't' - timeout |
'h' - hangup |
'T' - Absolute Timeout |
The start extension is for most calls that are initiated with no other known information.
Hangup is where calls will go to when hangup is detected, or where you can send calls that you want to hangup on.
![]() | There are currently some problems to be aware of when using the 'h' extension. Specifically, the variables about the call are lost as the information is destroyed with the channel. |
Timeout is for when a user is presented with a menu and they do not respond. In the timeout extension you will want to decide if you wish to repeat your menu, or just send the call to a hangup so as to free up the line.
Invalid is for when Asterisk has determined that the input from the call is not valid for the current context. You may wish to play a prompt explaining the extension was invalid, and then send the call back to the extension that contains the menu prompts.
Absolute Timeout is a used when a call is being terminated for exceeding an Absolute Timeout variable set. Be aware of the case difference from the normal timeout. This can be used to warn a user that they exceeded some allowable limit. Or it could be used to request someone to try calling back later if they waited in a queue too long. Essentially it should notify the caller that they are being disconnected so as not to leave them with the impression they had been cut off unintentially.
<<< Previous | Home | Next >>> |
Macros | Up | Advanced Dial Plan Concepts |