Questions about extensions.conf

If I have an extensions.conf file as follows:

exten => _NXXNXXXXXX,1,Set(CALLERID(all)=“Alan” <+13213513261>)
same => n,Dial(PJSIP/+1${EXTEN}@twilio-na-us)
same => n(end),Hangup()

I am not really sure what everything in these lines accomplishes, but would like to learn. I get that the from-internal is the context to setup the extensions and that I route it via Twilio. But the NXXNXXXXXX, from my understanding this line representes the extension number. Does this generalize the extensions, or am I supposed to replace this with my desired extension number?

The -set(CALLERID(all)=“Alan”-. I assume this is where I decide what my outbound callerid will be, and the “Alan” one being the name associated with this. Is this correct?

Thanks in advance.

_ indicates a pattern, that is matched at run time, rather than a literal number. This pattern is short for _[2-9][0-9][0-9][2-9][0-9][0-9][0-9][0-9][0-9][0-9], where [x-y] matches any character between, and including, x and y. This pattern will reflect the structure of North American numbers, without the long distance/carrier prefix.

I believe you can also write it as _NXX-NXX-XXXX as I think hyphens are ignored in patterns.

Extension numbers in Asterisk are things that appear in lines in extensions.conf; they are not numbers written on phones on people’s desks. As such you need an extension number to match every possible callable external number.

You are correct about CALLERID, although that is often set by other means.

(end) is a label, which is unused, as there are no GoTo’s, and the Hangup isn’t strictly necessary, although, with complex uses of patterns for extensions, it may be desirable,to prevent the tail end from a different extension pattern being executed.

Thank you so much for your reply. This made it much easier to understand.

While this forum is not a replacement for things already documented, some things may not be immediately obvious.

Expanding on what david551 posted…

When extension Pattern Matching (the bit that starts with the underscore), n is shorthand for [2 - 9], x = [0-9], and z = [1-9].

There are also ‘Special Dialplan Extensions.’

You CAN include hypen in an extension. Yay, I didn’t know that :slight_smile:

I always end the priorities for an extension with a ‘hangup()’ to avoid subtle bugs and to make my intention obvious.

‘[from-internal]’ starts a new context for extensions. There is no special meaning, it could be named anything that makes sense to you and matches ‘context=xxx’ in pjsip.conf or any flow control statement.

Whitespace is your friend. It makes it much easier to read a dialplan. I like to start the priorities for each extension with a ‘verbose()’ to help with debugging like:

        exten = _nxxnxxxxxx,1,          verbose(1,[${EXTEN}@${CONTEXT})
        same = n,                       set(CALLERID(all)=“Alan” <+13213513261>)
        same = n,                       dial(PJSIP/+1${EXTEN}@twilio-na-us)
        same = n,                       hangup()

        exten = i,1,                    verbose(1,[${EXTEN}@${CONTEXT})
        same = n,                       hangup()

Note that ‘extension@context’ makes it easy to cut and paste into a ‘dialplan show’ command.

And, don’t use noop() when there is the more obvious and featureful verbose() available.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.