[SOLVED] Use from-internal-custom or dialplan hook

[split from unrelated thread - mod]

@lgaetz Thanks again for such a quick response.

I have struggled to understand when to use the [from-internal-custom] in the past. I had read your other post (Hooking for Fun and Income) several times and just read it again.

Based on what was just confirmed, I am not sure how to handle the below situation… Maybe it should be a separate question post?

The below solution has seemingly been working fine for quite a while, but now you have me thinking that maybe it’s causing the dialing to bypass our default [from-local] context all together when 6 or 7 digit numbers are dialed.

Background… each of our phone systems uses 3 digit extensions and 4 digit groups. However, we have a network of phone systems that all route through a central “hub”. Each phone system is assigned a unique 3 digit number that is essentially it’s “locator”. When a 6 or 7 digit number is dialed, the custom context appends the correct local “locator” before sending the call to the IAX2 trunk. This ensures that if someone calls back the number on the caller ID, they will call back the correct extension.

[extension_custom.conf]

; Add "Phone System Locator" code to front of extension when another 6 digit
; extension has been dialed. 
; This will make "call backs" work correctly when calling from Office to Office
; This has been Set for vPBX-XXX-01 which is: 100

[from-internal-custom]

; Dialed 6 digits (Company Extension - Site Prefix + Destination Extension)
exten => _XXXXXX,1,GotoIf($[${LEN(${CALLERID(num)})} = 3]?setcid:end)
exten => _XXXXXX,n(setcid),NoOp(CUSTOM "from-internal-custom" in /etc/asterisk/extension_custom.conf_)
exten => _XXXXXX,n,NoOp(CUSTOM: 6 digit extension dialed. Changing Caller ID for ${CALLERID(all)} to 100${CALLERID(number)})
exten => _XXXXXX,n,Set(CALLERID(number)=100${CALLERID(number)})
exten => _XXXXXX,n,NoOp(CUSTOM: Caller ID changed to ${CALLERID(all)})
exten => _XXXXXXX,(end)n,NoOp()


; Dialed 7 Digits (Company Groups, Queues etc - Site Prefix + Group/Queue etc Number)
exten => _XXXXXXX,1,GotoIf($[${LEN(${CALLERID(num)})} = 3]?setcid:end)
exten => _XXXXXXX,n(setcid),NoOp(CUSTOM "from-internal-custom" in /etc/asterisk/extension_custom.conf_)
exten => _XXXXXXX,n,NoOp(CUSTOM: 7 digit extension dialed. Changing Caller ID for ${CALLERID(all)} to 100${CALLERID(number)})
exten => _XXXXXXX,n,Set(CALLERID(number)=100${CALLERID(number)})
exten => _XXXXXXX,n,NoOp(CUSTOM: Caller ID changed to ${CALLERID(all)})
exten => _XXXXXXX,(end)n,NoOp()
1 Like

I believe this could be better done with the internal dialplan hooks. Once you identify the proper channel variable for the dial string, you can gosubif based on that and change the CID. Here is a basic framework I start with:

[macro-dialout-one-predial-hook]
exten => s,1,GoSubIf( ...
exten => s,n,MacroExit

[macro-dialout-dundi-predial-hook]
exten => s,1,GoSubIf( ...
exten => s,n,MacroExit

[macro-dial-ringall-predial-hook]
exten => s,1,GoSubIf( ...
exten => s,n,MacroExit

[macro-dial-hunt-predial-hook]
exten => s,1,GoSubIf( ...
exten => s,n,MacroExit
1 Like

@lgaetz Thank you again for a great response!

Is this a good way to do what we are trying to do?

[extension_custom.conf]

; Add "Phone System Locator" code to front of extension when another 6/7 digit extension has been dialed. 
; This will make "call backs" work correctly when calling from Office to Office
; NOTE: PBXLocator Variable specified in "globals_custom.conf"

[macro-dialout-trunk-predial-hook]
; Go Sub if internal extension (3 digit) dialed 6 or 7 digit number
exten => s,1,GoSubIf($[ $[ $[${LEN(${CALLERID(dnid)})} = 6] | $[${LEN(${CALLERID(dnid)})} = 7] ] & $[${LEN(${CALLERID(num)})} = 3] ]?AddLocator,1)
exten => s,n,MacroExit

; Dialed 6 or 7 digits (Company Extension - Site Prefix + Destination Extension/Group/Queue/etc)
exten => AddLocator,1,NoOp(CUSTOM: 6 or 7 digit extension dialed. Changing Caller ID for ${CALLERID(all)} to ${PBXLocator}${CALLERID(number)})
exten => AddLocator,n,Set(CALLERID(number)=${PBXLocator}${CALLERID(number)})
exten => AddLocator,n,NoOp(CUSTOM: Caller ID changed to ${CALLERID(all)})
exten => AddLocator,n,Return

[global_custom.conf]

; This has been Set for vPBX-XXX-01 which is: 100
PBXLocator=100

Looks okay to me, assuming you only want Cid changes for trunk calls.

Thanks @lgaetz

For now, this will only need to happen on trunk calls, so that does work. Now that you gave me guidance, I’m confident that I change the “AddLocator” to a custom context and do “GoSubIf” in the other hooks, if needed, and send to the “[AddLocator]” context.

Thank you again for all of your help!!!

1 Like

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