Category Archives: Asterisk

Custom FreePBX/Asterisk code for caller ID

If you have your system set up with escape digit such as “9” for outside line (still a popular practice in UK and Europe), you will need to put this 9 on any incoming caller IDs so endusers can dial the numbers from the history menu of VOIP telephones.

Add this code to extensions_custom.conf in /etc/asterisk

; ***********************************************
; * ratcoTEL Networks Ipswich, Suffolk, England *
; *                                             *
; * custom code for Asterisk goes here          *
; ***********************************************
;
; put 9 on VOIP calls
; altered to get both name and number correct
; and deal correctly with WITHHELD or ANONYMOUS etc
; this assumes that trunks present the name and
; number in UK format with leading "0"
; leave CLID from voipfone alone 
; and present as normal number
; leave behind CNAM in case this contains something useful

[from-trunk-custom]
exten => _X.,1,GotoIf($[ "${CALLERID(name)}" != "anonymous" ] ?cidothername)
exten => _X.,n,Set(CALLERID(all)="WITHHELD <WITHHELD>")
exten => _X.,n(cidothername),GotoIf($[ "${CALLERID(num):0:1}" != "0" ] ?cidnotpstn)

; here there is a numeric CLID but check if CNAM contains number or anything else
exten => _X.,n,GotoIf($[ "${CALLERID(name):0:1}" != "0" ] ?cnamisalpha)
; if CNAM is a number put the 9 on the front
exten => _X.,n,Set(CALLERID(name)=9${CALLERID(num)})
exten => _X.,n(cnamisalpha),Set(CALLERID(num)=9${CALLERID(num)})
exten => _X.,n(cidnotpstn),Noop(CallerID on VOIP trunk is ${CALLERID(all)})
exten => _X.,n,Goto(from-trunk,${EXTEN},1)