text stringlengths 0 152 |
|---|
exten => example,1,Set(__MyVariable=thisValue) |
100 |
| |
Chapter 6: Dialplan Basics |
When you wish to read the value of the channel variable, you do not use the |
underscore(s): |
exten => example,1,Verbose(1,Value of MyVariable is: ${MyVariable}) |
Pattern Matching |
If we want to be able to allow people to dial through Asterisk and have Asterisk con‐ |
nect them to outside resources, we need a way to match on any possible phone num‐ |
ber that the caller might dial. For situations like this, Asterisk offers pattern matching. |
Pattern matching allows you to create one extension in your dialplan that matches |
many different numbers. This is enormously useful. |
Pattern-matching syntax |
When we are 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 name. |
If you forget the underscore at the beginning of your pattern, |
Asterisk will think it’s just a named extension and won’t do any pat‐ |
tern matching. This is one of the most common mistakes people |
make when starting to learn Asterisk. |
After the underscore, you can use one or more of the following characters: |
X |
Z |
N |
Matches any single digit from 0 to 9. |
Matches any single digit from 1 to 9. |
Matches any single digit from 2 to 9. |
Another common mistake is to try to use the letters X, Z, and N |
literally in a pattern match; to do that, wrap them in square |
brackets (case-insensitive), such as _ale[X][Z]a[N]der. |
[15-7] |
Matches a single character from the range of digits specified. In this case, the pat‐ |
tern matches a single 1, as well as any number in the range 5, 6, 7. |
Building an Interactive Dialplan |
| |
101 |
. (period) |
Wildcard match; matches one or more characters, no matter what they are. |
If you’re not careful, wildcard matches can make your |
dialplans do things you’re not expecting (like matching built- |
in extensions such as i or h). You should use the wildcard |
match in a pattern only after you’ve matched as many other |
digits as possible. For example, the following pattern match |
should probably never be used: |
_. |
In fact, Asterisk will warn you if you try to use it. Instead, if |
you really need a catchall pattern match, use this one to match |
all strings that start with a digit followed by one or more char‐ |
acters (see ! if you want to be able to match on zero or more |
characters): |
_X. |
Or this one, to match any alphanumeric string: |
_[0-9a-zA-Z]. |
! (bang) |
Wildcard match; matches zero or more characters, no matter what they are. |
To use pattern matching in your dialplan, simply put the pattern in the place of the |
extension name (or number): |
exten => _4XX,1,Noop(User Dialed ${EXTEN}) |
same => n,Answer() |
same => n,SayDigits(${EXTEN}) |
same => n,Hangup() |
In this example, the pattern matches any three-digit extension from 400 through |
499.18 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.