Customize outgoing caller name and caller ID

 

Caller ID reference material

Set outgoing caller ID name and number based on source extension or outgoing trunk

By default, FreePBX can set outgoing caller name and caller ID either at the extension level or at the trunk level (setting this at the trunk level is less work than doing so for all the extensions individually). This is the usual way to set outgoing caller ID.

  • Applications > Extensions

    • (select extension)

      • Extension Options > Outbound CID: (enter caller ID name and number string)

or

  • Connectivity > Trunks

    • (select trunk)

      • General Settings

        • Outbound CallerID: (enter caller ID name and number string)

        • CID Options: Force Trunk CID

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()

Reload the FreePBX configuration

For the changes to take effect, the FreePBX configuration needs to be reloaded by submitting any configuration page in the Web GUI and clicking "Apply Config" or using the "amportal a r" command line command.

Return to Documentation Home I Return to Sangoma Support