Update: The code below does not work in Asterisk 2.0b4 or newer. I will update with instructions on how to get it to work in those versions. Thanks to Dan for pointing this out.

Update: I have changed the code to the removed part. It now requires a key press to accept the number to delete.

I have added a blacklist function to my Asterisk@Home server and thought that I’d share it here if someone is interested. There are two ways to add a number to the blacklist. The easiest is to dial *32. Then you get a voice telling you the number of the last incoming call. To add it to the blacklist, press 1. Great use against pesky telemarketers and If you want to add it manually,  press *30. Then you can enter the phone number directly on your telephone. To remove an entry from the blacklist, press *31 and enter the phone number. If you don’t like the codes I use, change them.

Here’s How You Add A Black-list Function In Asterisk

Add the code below at the end of extensions_custom.conf. You can edit it from the web interface, go under Maintenance and Config Edit and select extensions_custom.conf. You have to add it to the _custom file because AMP changes the _additional.conf file every time you update something.

[custom-blacklist-add] exten => s,1,Playback(enter-num-blacklist);
exten => s,2,DigitTimeout(5)
exten => s,2,ResponseTimeout(60)
exten => s,3,Read(blacknr,then-press-pound)
exten => s,4,SayDigits(${blacknr})
exten => s,5,Playback(if-correct-press)
exten => s,6,Playback(digits/1)
exten => 1,1,DBput(blacklist/${blacknr}=1)
exten => 1,2,Playback(num-was-successfully)
exten => 1,3,Playback(added)
exten => 1,4,Wait(1)
exten => 1,5,Hangup
exten=_X.,3,Playback(num-was-successfully)
exten=_X.,4,Playback(added)
exten=_X.,5,Hangup [custom-blacklist-remove]
exten => s,1,Playback(entr-num-rmv-blklist)
exten => s,2,ResponseTimeout(60)
exten => s,3,Read(blacknr,then-press-pound)
exten => s,4,SayDigits(${blacknr})
exten => s,5,Playback(if-correct-press)
exten => s,6,Playback(digits/1)
exten => 1,1,DBdel(blacklist/${blacknr})
exten => 1,2,SayDigits($blacklist)
exten => 1,3,Playback(num-was-successfully)
exten => 1,4,Playback(removed)
exten => 1,5,Hangup [custom-blacklisted]
exten=s,1,Answer exten=s,2,Wait(1)
exten=s,3,Playback(nbdy-avail-to-take-call)
exten=s,4,Playback(carried-away-by-monkeys)
exten=s,5,Playback(lots-o-monkeys)
exten=s,6,Hangup [custom-blacklist-last]
exten => s,1,Answer
exten => s,2,Wait(1)
exten => s,3,DBget(number=CALLTRACE/${CALLERIDNUM}); goto 104 if no last caller
exten => s,4,GotoIf($"${number}" = ""?104,1) ; also if it's blank (caller id blocked)
exten =>s,5,Playback(privacy-to-blacklist-last-caller)
exten => s,6,Playback(telephone-number)
exten => s,7,SayDigits(${number})
exten => s,8,Wait,1
exten => s,9,Playback(if-correct-press)
exten => s,10,Playback(digits/1)
exten => 1,1,DBput(blacklist/${number}=1)
exten => 1,2,Playback(privacy-blacklisted)
exten => 1,3,Wait,1
exten => 1,4,Hangup
exten => s,104,Playback(unidentified-no-callback)
exten => s,106,Hangup

 

You also need to add a custom function to the from-PSTN context, a function that gets called before the normal incoming call handler. So it checks if the incoming number is on the blacklist. If so, give a weird message (or maybe just congestion?)

Add the following at the beginning of extensions_custom.conf. Make sure there’s not a declaration for that context already. If so, add the lines there.

[from-pstn-custom]
exten => s,1,LookupBlacklist        ; If CID blacklisted, goto 102
exten => s,102,Goto(custom-blacklisted,s,1)

And then the last change. Add the following lines in extensions_custom.conf in the [from-internal-custom] context. There are already some lines there, but add the following after that.

exten => *30,1,Goto(custom-blacklist-add,s,1)
exten => *31,1,Goto(custom-blacklist-remove,s,1)
exten => *32,1,Goto(custom-blacklist-last,s,1)

You’ll probably like to change the [custom-blacklisted] to do something like congestion or hang up instead of the weird message my version does.