Asterisk Dialplan Questions

asterisk
dialplan
Tags: #<Tag:0x00007f702a2c5a28> #<Tag:0x00007f702a2c53e8>

(Radio Jed) #1

Hi I had a few basic questions about the asterisk dial plan that I could not find in the wiki.

What does the “=>” operator do?
Is it equivalent to = in other languages?

In this code example

exten => 6001,1,NoOp(call for Alice)
same => n,Dial(PJSIP/6001)
same => n,GotoIf($[ "${DIALSTATUS}" != "ANSWER" ]?Dial(PJSIP/1111111@provider),1)
same => n,Hangup

Why do all lines start with n?
I understand it matches any number from 2-9 but why not number the lines 2,3,4, exc.?
If n is any value between 2-9 why doesn’t hangup randomly play after 1?


(Lorne Gaetz) #2

There are three separate ways of writing your referenced dialplan which will behave identically, the other two are:

exten => 6001,1,NoOp(call for Alice)
exten => 6001,2,Dial(PJSIP/6001)
exten => 6001,3,GotoIf($[ "${DIALSTATUS}" != "ANSWER" ]?Dial(PJSIP/1111111@provider),1)
exten => 6001,4,Hangup

exten => 6001,1,NoOp(call for Alice)
exten => 6001,n,Dial(PJSIP/6001)
exten => 6001,n,GotoIf($[ "${DIALSTATUS}" != "ANSWER" ]?Dial(PJSIP/1111111@provider),1)
exten => 6001,n,Hangup

The exten => portion of each line is the setup for writing dialplan which by modern standards appears to be needlessly repetitive, presumably why the same shorthand evolved at some point in the past. The first characters after the => before the comma are the extension. If thinking about this in terms of voice telephony, it’s the number the caller dials, but there is no restriction that the extension be numeric, it’s acceptable for the extension to be any string. The next character(s) after the extension is the priority, the sequence which the dialplan lines are executed. You can number the lines manually or, as is much more convenient for editing after the fact, you can substitute an n character so that lines are executed in the order they are written.


(Ricardo) #3

“same “ is a way to avoid having to repeat the extension name/number and “n” is next priority.

The letter n stands for next , and when Asterisk sees priority n it replaces it in memory with the previous priority number plus one.


(Lorne Gaetz) #4

You are confusing the priority shorthand lower case n with the extension wildcard uppercase N. For voice telephony, it is necessary to be able to define an extension that does wild card matching, so a line that looks like this:

exten => _1NXXNXXXXXX,1,NoOp(call for Alice)

The extension starts with an underscore telling asterisk that the characters that follow are not literal, they are for matching dialed digits. The first character must be one, the following character can be any digit between 2-9, and the X’s are any digit. The entire string is the very familiar pattern match for the NANP 1+10 digit phone number format.


(Radio Jed) #5

The only thing I could find in the wiki about n was the wildcard match. That’s what made me so confused about the whole thing. I read the code where n was a random number between 2 and 9.
Thanks so much!