Asterisk Caller ID Blocking Recipe

Here’s another quick little Asterisk recipe that I threw together. It’s a handy because it only takes about 10 minutes to setup and is infinitely useful to the sales types. Just a note, this was done with Asterisk 1.4.8.

I wanted to do a little in AEL just to get a feel for it. It is a little AEL and a little regular extensions.conf type stuff.

The basic way that this CallerID Blocking recipe works is to use the Asterisk DB. An entry with the family of CIDBlock and the key of the dialing users extension will have a value of 1 or 0. The user initially sets their preference to either enabled (1) or disabled (0). When the number gets dialed, the preference gets checked and then the CALLERID(name)/CALLERID(number) values are set accordingly. In order for the user to enable CID Blocking, they need to dial *81. It will stay enabled until they dial *82.

How do we accomplish this? Easy. The sounds come with the asterisk sounds package.

Open up your extensions.conf and add the following lines (to whichever context works for you):

; Enable CallerID Blocking for the dialing extension
exten => *81,1,Set(DB(CIDBlock/${CHANNEL:4:4})=1)
exten => *81,2,Playback(privacy-your-callerid-is)
exten => *81,3,Playback(enabled)
exten => *81,4,Hangup()

; Disable CallerID Blocking for the dialing extension
exten => *82,1,Set(DB(CIDBlock/${CHANNEL:4:4})=0)
exten => *82,2,Playback(privacy-your-callerid-is)
exten => *82,3,Playback(disabled)
exten => *82,4,Hangup()

The last modification that needs to happen is that you have to change the exten that dials out to check the DB and react accordingly. Here is a snippet of mine (with the numbers changed to protect the innocent):

; Outbound calling for 111.222.3456 (my phone number)
exten =>_1NXXNXXXXXX,1,Set(CIDBlock=${DB(CIDBlock/${CHANNEL:4:4})})
exten =>_1NXXNXXXXXX,2,Set(${IF($[${CIDBlock} = 1]?CALLERID(name)=Unavailable:CALLERID(name)=MyCompany)})
exten =>_1NXXNXXXXXX,3,Set(${IF($[${CIDBlock} = 1]?CALLERID(number)=0-1-999:CALLERID(number)=1112223456)})
exten =>_1NXXNXXXXXX,4,DIAL(SIP/provider/${EXTEN},60,tr)
exten =>_1NXXNXXXXXX,5,Hangup

That’s really all it takes to set it up. Quick and handy.

* Note: *81 & *82 are arbitrary number combinations. Adjust to what works for you.

If you’re feeling really frisky, I added this AEL extension to check the status of your CallerID Blocking on *83. For fun, I have also included my *67 script for those who need an idea of how its done. As with almost anything in Asterisk, there are many ways to do it, this is just how I chose to accomplish this.

// Extra's for sending things outbound
context outbound-extra {
   *83 => {
            Playback(privacy-your-callerid-is);
            Set(CIDBlock=${DB(CIDBlock/${CHANNEL:4:4})});
            if(${CIDBlock} == 1) {
                Playback(enabled);
            }
            else {
                Playback(disabled);
            }   
            Hangup();
   };

   *67 => {
      // Remove the *67 from the number we are dialing
      Set(dialed_number=${EXTEN:3:11});
      Set(CALLERID(name)=Unavailable):
      Set(CALLERID(number)=0-1-999):
      DIAL(SIP/provider/${dialed_number},60,tr);
      Hangup();
   };
};
  • koenigjm

    Hey thanks for the recipe! I am new to asterisk and was looking to add this feature to my dialplan.Your guide certainly helped me understand asterisk workings a bit better.

    I followed the steps above I added the exten defs to the default context under my extensions.conf, but after I reload asterisk all I get is a dial tone after dialing *81. Any ideas?

  • james

    Eric,

    Tried the above example to enable callerid and while it shows it works on cli when I go to type in my local 11 digit number, Telus recording comed back that CID is blocked. What else could be cuase of this? I entered in the rest of the outgoing code and while everything looks good on cli, still cannot enable cid.

    Thanks

  • Lucky225

    Or you could use something RFC-3323 compliant and not spoof some random BS number that’s going to confuse cellphone callers(0-1-999, wtf?)

    Sending RFC-3323 compliant privacy headers in sip calls

    ftp://ftp.rfc-editor.org/in-notes/rfc3323.txt

    exten => _9.,1,SIPAddHeader(P-Asserted-Identity: )
    exten => _9.,n,SIPAddHeader(Privacy: user\; header\; session)
    exten => _9.,n.SetCallerPres(prohib_not_screened) ; this might not be needed — needs further testing
    exten => _9.,n,Set(CALLERID(num)=)
    exten => _9.,n,Set(CALLERID(name)=Anonymous)
    exten => _9.,n,Dial(SIP/+${EXTEN:1}@sipcarrier)
    exten => _9.,n,Hangup()