Saturday, February 11, 2012

Asterisk Dialplan - Pattern Matching

Pattern Matching syntax
When using pattern matching, certain letters and symbols represent what we are trying to match. Patterns always start with an underscore(_). This tells Asterisk that we're matching on a pattern, and not on an explicit extension nam.
X: matches any single digit from 0 to 9.
Z: matches any single digit from 1 to 9.
N: matches any single digit from 2 to 9.
[15-7]: Matches a single digit from the range of digits specified. In this case, the pattern matches a singel 1, 5,6,7.
. : wild card match; matches one or more characters, no matter what they are.
! : wild card match; matches zero or more characters, no matter what they are.

Using the ${EXTEN} channel variable
exten => _XXX, 1, SayDigits(${EXTEN})

To manipulate the ${EXTEN} by stripping a certain number of digits off the front of the extension. use the syntax ${EXTEN:x}, where x is where you want the returned string to start, from left to right. For example, if the value of EXTEN is 9123456, ${EXTEN:1} equals 123456.

The ${EXTEN} variable has the syntax ${EXTEN:x:y}, where x is the starting position, and y is the number of digits to return.
Example: 94169671111
${EXTEN:1:3} would contain 416.
${EXTEN:4:7} would contain 9671111
${EXTEN:-4:4} would start four digits from the end, and return four digits, giving 1111.

Enabling Outbound Dialing
The first thing we'll do is add a variable to the [globals] context to define which channel will be used for outbound calls:
[globals]
JOHN=Zap/1
JANE=SIP/Jane
OUBOUNDTRUNK=Zap/4
Next, add contexts to dialplan for outbound dialing.
The reason for adding contexts is to regulate and control which callers have permission to make outbound calls, and which type of outboud calls they are allowed to make.
[outbound-local]
exten => _9NXXXXXX,1,Dial(${OUTBOUNDTRUNK}/${EXTEN:1})
exten => _9NXXXXXX,n,Congestion()
exten => _9NXXXXXX,n,Hangup()

exten => 911,1,Dial(${OUTBOUNDTRUNK}/911)
exten => 9911,1,Dial(${OUTBOUNDTRUNK}/911)

Includes:
The include statement takes the following form, where context is the name of the remote context we want to include in the current context:
include => context

No comments:

Post a Comment