Last weeks I get more and more telephone calls from call-centres. I want to filter out this telephone calls in my Asterisk server. Call-centres often do not send their telephone number. In case a call-centre is calling, the telephone number is not shown. The number display present something like “0000000000” or “Private”, something like that. That is what I would like to use to filter this calls.

There are several ways to filter out telephone calls in Asterisk:

  • Using the Blacklist() function
  • Using Goto in case the telephone number is unknown

Configuring the Asterisk

In this case it is very simple to use the Goto solution to filter the unknown telephone numbers.

To do this, open the extensions.conf file, and go to the section where the external calls are coming in. In my case [external].

$ vi / etc/asterisk/extensions.conf

[external]

exten => s,1,GotoIf($["${CALLERID(num)}" = "Unknown"]?unknown_cid)
exten => s,n,Dial(SIP/501&SIP/502,35)
exten => s,n,Goto(mainmenu,s,1)
exten => s,n(unknown_cid),Background(mysounds/cid_unknown)
exten => s,n,Goto(mainmenu,s,1)_

[mainmenu]

Create the message cid_unknown in your mysounds directory on the Asteriks server.

Now you need to restart the Asterisk server:

$ /etc/init.d./asterisk restart

A small explanation

If the CALLERID contains “Unknown” the internal telephones 501&502 are not going to ring, the “Unknown” will get a message like:

The number display of your telephone is blocked, that is why we do not take your telephone call. This is to block unwanted telephone calls.

After this message the caller will get the possibility to use the voice-mail system. This will give other people the possibility to give a messages to you. This in case they have blocked their telephone number by themselves.

Testing the system

To test the system, you need to call with a blocked number display. In my case it is possible to do this, by putting #31# before your telephone number. So dial #31#, and you will get the new message.

Side effect

I also have the possibility to put on my home server via the Asterisk server. Now I can call to my house with #31# and I am directly in the IVR menu, without waiting for 35 seconds ringing the telephone.