Toll Free Pattern Matching

Home » Asterisk Users » Toll Free Pattern Matching
Asterisk Users 3 Comments

I have this in my config:

exten => _800XXXXXXX,1,Verbose(0,${CHANNEL(peername)} Calling ${EXTEN})
same => n,Dial(SIP/tollfree/1${EXTEN})
exten => _1800XXXXXXX,1,Verbose(0,${CHANNEL(peername)} Calling ${EXTEN})
same => n,Dial(SIP/tollfree/${EXTEN})
exten => _NXXNXXXXXX,1,Verbose(0,${CHANNEL(peername)} Calling ${EXTEN})
same => n,Dial(SIP/trunk/1${EXTEN})
exten => _1NXXNXXXXXX,1,Verbose(0,${CHANNEL(peername)} Calling ${EXTEN})
same => n,Dial(SIP/trunk/${EXTEN})

I came across http://stackoverflow.com/questions/7235291/asterisk-priorities-that-have-a-possibility-of-matching which seems to imply that the above won’t work and that all the calls would go to the trunk. However, this is working as expected for me. Did the behaviour change in the last four years or could I run into problems with this setup? Perhaps I am misunderstanding the poster’s issue.

3 thoughts on - Toll Free Pattern Matching

  • Dialplan will stay on the current series of extensions until it runs out. If there isn’t an explicit hangup to stop execution it will look for the next priority match. You can easily test this yourself by creating some test dialplan to match your situation.

    Given the below dialplan:

    exten = _800XXXXXX,1,NoOp(Start of 800 series)
    same = n,NoOp(Next in 800 series)

    exten = _NXXNXXXX,1,NoOp(Generic series)
    same = n,NoOp(next in generic series)
    same = n,NoOp(third in generic series)

    If you have an 800 number starting in dialplan then these are the priorities executed:
    1, Start of 800 series
    2, Next in 800 series Since we have run out of the 800 series Asterisk looks for a priority 3
    that matches the extension and finds priority 3 of the generic series.
    3, third in generic series There is no priority 4 so the call is hung up.

    Richard

    [1]
    https://wiki.asterisk.org/wiki/display/AST/Contexts%2C+Extensions%2C+and+Priorities
    [2] https://wiki.asterisk.org/wiki/display/AST/Pattern+Matching

  • So glad I asked. I see now that it only worked because of the accident that the specific 800 extension and the generic one just happened to have the same number of priorities. I have added explicit hangups.

    Thanks.

  • Don’t forget to handle the other special extension cases
    <https://wiki.asterisk.org/wiki/display/AST/Special+Dialplan+Extensions> in a [context]. What I find is a good practice is to write a root “catch-all”
    (template), then I tag that onto any new [context](template).

    [Special-Extensions]
    exten -> a,1,NoOp(Where a call jumps when the caller requests the assistant)
    exten -> e,1,NoOp(Catchall where a call jumps with an exception on the call)
    exten -> h,1,NoOp(Where a call jump with a hang up)
    exten -> i,1,NoOp(Where a call jumps if an invalid extension is entered)
    exten -> o,1,NoOp(Where a call jumps when a caller requests an operator)
    exten -> s,1,NoOp(Where a call jumps to when a new call starts in a context if no extension is specified)
    exten -> t,1,NoOp(Where a call jumps if the user did not enter a response to Background or WaitExten)
    exten -> T,1,NoOp(Where a call jumps when it exceeds the absolute TIMEOUT
    value for a call).

    [your-new-context](Special-Extensions)

    -T