Professional Documents
Culture Documents
or
Set outgoing caller name and caller ID based on outgoing caller ID number
In the case below, another connected PBX that is routing calls out through Asterisk can set the outgoing caller ID number but unfortunately does
not set the outgoing caller ID name.
As a workaround, custom logic below looks for specific outgoing caller ID number strings and also then sets the desired outgoing caller ID name.
Prerequisites
If FreePBX is configured to set a trunk-level caller ID override, the foreign PBX caller ID number will be overwritten before the code
below runs, so for the code below to work as expected, the FreePBX trunk setting needs to be "Allow any CID", not "Force Trunk CID"
Implementation
FreePBX provides a place to modify outgoing call logic through use of a pre-existing code hook called "macro-dialout-trunk-predial-hook". This
macro code will be called by Asterisk during each outgoing call. The code is placed into a file FreePBX reserves for user-added custom code.
vi /etc/asterisk/extensions_custom.conf
; Customization: Add a trunk predial hook to examine the outbound caller
ID number and set the
; outbound caller ID name based on the number (a workaround for a
foreign PBX that cannot set the caller ID name string)
[macro-dialout-trunk-predial-hook]
; add log output to show outgoing caller ID information before any changes
are made
; note: don't comment out the first line without modifying the new actual
first line of code to be sequence number 1
exten => s,1,NoOp(CUSTOM: calleridall is ${CALLERID(all)})
exten => s,n,NoOp(CUSTOM: calleridnumber is ${CALLERID(number)})
; test number case for debugging: override outgoing caller name and caller
ID number for calls set to have the outgoing caller ID number to 555-555-
1212 (remove comments to enable)
;;exten => s,n,ExecIf($["${CALLERID(number)}" = "+15555551212"]?NoOp
(CUSTOM: Setting Caller ID override for source ${CALLERID(number)}))
;;exten => s,n,ExecIf($["${CALLERID(number)}" = "+15555551212"]?Set
(CALLERID(all)="Test Number" <5555551212>))
; branch office location 1: override outgoing caller name and caller ID
number for calls set to have the outgoing caller ID number to 519-123-4567
exten => s,n,ExecIf($["${CALLERID(number)}" = "+15191234567"]?NoOp(CUSTOM:
Setting Caller ID override for source ${CALLERID(number)}))
exten => s,n,ExecIf($["${CALLERID(number)}" = "+15191234567"]?Set(CALLERID
(all)="Branch Office" <5191234567>))
; default case for the main office: override outgoing caller name and
caller ID number for calls set to have the outgoing caller ID number to
nothing to be the main office caller ID name and number
exten => s,n,ExecIf($["${CALLERID(number)}" = ""]?Set(CALLERID(all)="Main
Office" <5192345678>))
; exit back
exten => s,n,MacroExit()