FreePBX | Register | Issues | Wiki | Portal | Support

Strip off Country and Area Code from incoming Caller ID (name)

(Matthias Hester) #1


i have following situation:

Incoming call for example:

  • “CallerID num” is 089123456 (area code 089 for Munich, Germany
  • “CallerID name” is +4989123456 (country +49 Germany and area code 89 for Munich)

What I want

  • Display the incoming “Caller ID number” of my hometown (i.e. Munich) without area code 089. So it will be only 123456
  • Display the incoming “Caller ID name” without country code +49 and without area code 89. So it will be also only 123456

Country code +49 should always be removed from “Caller ID number” and if it´s not a call from Munich it should be prefixed with 0 before Area Code.
Area Code 089 (or +4989) should alwys be removed from “Caller ID name”.

I tried this:

exten => _.,1,ExecIf($[ "${CALLERID(num):0:3}" = "+49" ]?Set(CALLERID(num)=0${CALLERID(num):3}))
exten => _.,1,ExecIf($[ "${CALLERID(num):0:3}" = "089" ]?Set(CALLERID(num)=${CALLERID(num):3}))
exten => _.,n,Set(CALLERID(name)=${CALLERID(num)})
exten => _.,n,Goto(from-trunk,${EXTEN},1)

and changed context in trunk to "[from-trunk-arearemove]

But it didn´t work. The CallerID name and CallerID number will always displayed as the code wouldn´t exist.

I have FreePBX 13 running on Raspberry PI 2.

Could anyone please help me?


Set CID invalid number
Asterisk Phonebook vs CID Lookup source

We have “Set CallerID” module to do this.

(Matthias Hester) #3

Thanks for your reply. But I don´t understand how this works with the module. The guide also doesn´t help me. :frowning:


You have two priority 1’s in your code which will break it, but perhaps more robustly, I suggest you take the [from-pstn-e164-us] context in /etc/asterisk/extensiopns.conf as a template and build your own [from-pstn-e164-de] context to suit your particular dialing style and send inbound calls to that context, it will help with directories, callbacks and call presentation

explains well how the PSTN works in Germany.

The same source ( is always good if you are not DE, if you are UK it’s easy (apart from your granny who lives in Brampton :slight_smile: ) for IT it’s a pain.


You need to do some filtering (by calling/called number) in Incoming Routes then send a call to “Set CallerID” destination.
The sample “Set CallerID” entry:
CallerID Name ${CALLERID(name):4}
CallerID Number ${CALLERID(num):3}
Then you need to send the calls somewhere - the simple way is to specify the desired extension, ring group, etc as a Destination right here in “Set CallerID”.
You can also return a call back to your dialplan - create a Local trunk and specify it’s name as a destination here.
If you’re comfortable with the custom contexts - I fully support what was suggested by @dicko.

(Matthias Hester) #6

Thanks for your replys.

This is my solution:

In extensions_custom.conf I´ve added:

exten => _.,1,ExecIf($[ "${CALLERID(name):0:3}" = "+49" ]?Set(CALLERID(name)=0${CALLERID(name):3}))
exten => _.,n,ExecIf($[ "${CALLERID(num):0:3}" = "+49" ]?Set(CALLERID(num)=0${CALLERID(num):3}))
exten => _.,n,ExecIf($[ "${CALLERID(name):0:5}" = "02961" ]?Set(CALLERID(name)=${CALLERID(name):5}))
exten => _.,n,ExecIf($[ "${CALLERID(num):0:5}" = "02961" ]?Set(CALLERID(num)=${CALLERID(num):5}))

All tests worked until now.

(Lorne Gaetz) #7

There are good technical reasons NOT to use the context, from-pstn-custom in this way. I recommend that you change your trunk context to something like from-pstn-de then modify your code to:

exten => _.,1,ExecIf($[ "${CALLERID(name):0:3}" = "+49" ]?Set(CALLERID(name)=0${CALLERID(name):3}))
exten => _.,n,ExecIf($[ "${CALLERID(num):0:3}" = "+49" ]?Set(CALLERID(num)=0${CALLERID(num):3}))
exten => _.,n,ExecIf($[ "${CALLERID(name):0:5}" = "02961" ]?Set(CALLERID(name)=${CALLERID(name):5}))
exten => _.,n,ExecIf($[ "${CALLERID(num):0:5}" = "02961" ]?Set(CALLERID(num)=${CALLERID(num):5}))
exten => _.,n,goto(from-pstn,${EXTEN},1)

(Matthias Hester) #8

Ok thank you very much. I will try it tomorrow.

Can you explain why it’s not good to use this context?

(Lorne Gaetz) #9

Because of the way the includes are arranged, every line that you add to from-pstn-custom will overwrite a generated line in the from-pstn context.

(Matthias Hester) #10

With the from-pstn-de context It’s working like a charm. Thank you so much!


I came across this example when trying to figure out how to set CALLERID(num) and CALLERID(name) to “0” if they are “unknown”. Based on this post I created a custom context “from-trunk-unknown” in extensions_custom.conf, with the following lines:
exten => _.,1,ExecIf($[ “${CALLERID(name):0:7}” = “unknown”]?Set(CALLERID(name)=0))
exten => _.,n,ExecIf($[ “${CALLERID(num):0:7}” = “unknown”]?Set(CALLERID(num)=0))
exten => _.,n,Goto(from-trunk,${EXTEN},1)

and set context=from-trunk-unknown in the trunk SIP Settings under incoming. When I check /var/log/asterisk/full this context is never used after registering on “reload/apply”. Now im stuck trying to figure out how to set the CID info. Any hints on what I’m missing would be highly appreciated


(Dave Burgess) #12

1 - you should start your own thread instead of hooking onto an old one.
2 - make sure the context is getting pulled into the server. You can search for the context name in the ‘full’ logfile, or you can use the fwconsole context command to look at the contexts in your current system to see if it’s being pulled in or used.