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?
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.
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.
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!