[Asterisk-Users] Simplifying from-did context

Leif Madsen asterisk.leif.madsen at gmail.com
Mon Aug 8 11:26:44 MST 2005


On 8/8/05, Scott Miller <scoscmil at imap.iu.edu> wrote:
> I am looking for a way to simplify my 'from-did' context.  All of my
> extensions are 5 digit extensions, which represent the last 5 digits of an
> assigned phone number.  Do I have to insert an entry for each of the
> extensions I have or is there an easier way?
> 
> Here's an example of what I have right now....
> There are 4 entries for each phone, one if the trunk only hands 5 digits
> (its an internal call) and the full 10 digit if it's an outside call.  Any
> ideas would be appreciated.
> 
> 
> [ext-did]
> exten => 18122786191,1,SetVar(FROM_DID=18122786191)     ;
> exten => 18122786191,2,Goto(ext-local,86191,1)  ;
> exten => 86191,1,SetVar(FROM_DID=86191) ;
> exten => 86191,2,Goto(ext-local,86191,1)        ;

This is a perfect example of the power of pattern matching and the use
of the ${EXTEN} variable. You could modify your dialplan to use these
as so:

[ext-did]
exten => _181227XXXXX,1,Goto(ext-local,${EXTEN:6},1)   ; removes first
6 digits from extension
exten => _XXXXX,1,Goto(ext-local,${EXTEN},1)

You can also use the Set() application to set the variable if you are
actually using the FROM_DID variable in your ext-local context as
well.

X - matches 0-9
N - matches 2-9
Z - matches 1-9

Pattern matches are required to start with an underscore _ or they
will be interpreted literally.

-- 
Leif Madsen - http://www.leifmadsen.com
Astricon 2005, Anaheim, CA, October 12-14
http://www.astricon.net

Copy of the upcoming book, Asterisk: The Future of Telephony
by O'Reilly Media to the first 500 Astricon tutorial registrants!



More information about the asterisk-users mailing list