How to make internal calls ring differently from external ones

I was actually on the right track, but not doing it in the right place. The trick is to put the following code in /etc/asterisk/extensions_override_freepbx.conf :

[from-internal]
include => set-alert-if-local

[from-internal-original]
include => from-internal-xfer
include => bad-number

[set-alert-if-local]
exten => 234,1,GotoIf($["${CALLERID(num)}" > "999"]?notfromlocal)
exten => 234,n,GotoIf($["${CALLERID(num)}" < "100"]?notfromlocal)
exten => 234,n,Set(__ALERT_INFO=Bellcore-r3)
exten => 234,n(notfromlocal),Goto(from-internal-original,${EXTEN},1)
;The following three lines must not be changed!
exten => _.,1,Goto(from-internal-original,${EXTEN},1)
exten => s,1,Goto(from-internal-original,s,1)
exten => h,1,Macro(hangupcall)

The real action is in the four lines following the [set-alert-if-local] context tag, which can be duplicated as often as necessary for the number of extensions you have and the different ring patterns. Specifically:

All four lines must begin with either exten => extension, or exten => _pattern, — this defines which extension or group of extensions the rule is to apply to. Don’t forget the leading underscore if using a pattern.

The first two lines define the upper and lower boundaries of what is considered a local extension - in this case, anything above 999 or below 100 would not be considered local. Therefore, you can set the distinctive ring to occur only if the call is from a particular group of extensions (a subset of your local extensions) or even compress this down to a single line and do an exact match on a particular calling extension (e.g. the boss!).

The third line sets the Alert Info string, and must be the correct string for the endpoint. You could have multiple rules to have different distinctive rings for different individual calling extensions, or groups of extensions.

The fourth line after the [set-alert-if-local] context tag should be included verbatim, except of course that if you have multiple rule sets then each one must have a unique label here (and that label must also be changed to match in the first two lines after the [set-alert-if-local] tag). So, if I had multiple rules here, instead of using notfromlocal I might use notfromlocal234, so I could keep my labels straight when reading down the list (also that would be easier to auto-generate if anyone ever writes a module to do this).

All the other lines should probably be left unchanged, although I have a feeling that someone will say I should not use the _. pattern in the catch-all line that follows the comment. I was basically following the lead of whoever wrote the [from-sip-external] context in extensions.conf (see the comment in that section of code).

One caveat, I haven’t upgraded to 2.6 yet so if you have, be sure to check /etc/asterisk/extensions.conf and make sure that the [from-internal] context hasn’t changed - that’s what I copied verbatim to the [from-internal-original] context here, so if that changes in extensions.conf then it must be changed here in extensions_override_freepbx.conf as well.

I’ll probably copy this information to a How-To in a day or two, but wanted to post it here first so that you guys could critique it and tell me if I’m doing anything I shouldn’t here. And no, I an not real crazy about putting the [from-internal] context in extensions_override_freepbx.conf, but everything I tried in extensions_custom.conf had unwanted side effects. When I get around to doing the How-To I’ll definitely mention mickecarlsson’s technique first, since that will be easier in many situations (especially where are your endpoints use the same Alert Info strings).