Home » Technology » Keeping Telemarketers At Bay with Asterisk

The Most Versatile VoIP Provider: FREE PORTING

Keeping Telemarketers At Bay with Asterisk

blankJust when you thought the National Do-Not-Call Registry was getting you some peace and quiet during the dinner hour, VoIP telephony comes along to give the telemarketers a brand new universe to pollute. And, of course, the politicians exempted themselves and non-profits from the Do-Not-Call rules anyway. Thanks to Katrina and local elections in November, you can expect a wave of unwanted dinnertime calls from your best friends at campaign headquarters or the Fraternal Order of Police. Lucky for you, there's an Asterisk® PBX standing between the telemarketers and your dinner table. Here are a few simple additions you can make to your Asterisk PBX setup to all but eliminate unwanted callers from your life. There are three types of protection we'll address. First, you can build a separate context to handle callers without CallerID. Second, you can send a special information tone to certain callers to block autodialers. And finally, when all else fails, you can quickly place certain numbers in a BlackList database to make sure it's the last time that folks using that number ever disturb you again.

Managing CallerID-less Callers. Not all callers without a CallerID name and number are bad people, at least not quite. So we want to structure our treatment of calls without CallerID in such a way that we don't discard a call that might be important. There are a couple of things you can do to manage these calls. First, you can have Asterisk prompt such callers to either say their name or to key in their phone number. Our preference is recording the name of the caller because hearing the caller speak gives you a good idea whether you want to take the call whereas asking a caller to enter their phone number does nothing to deter really obnoxious telemarketers. With either of these options, our approach (which we previously covered in our security column) is to prompt the caller for the information, park the caller with music on hold, and then announce the call and play back either the caller's name or number. You then have the option of picking up the parked call or leaving the caller parked until they're automatically disconnected.


Our other recommendation for calls without CallerID is to send a special information tone when the call is answered. For those of you that spent $40 on a Telezapper, we're sorry. Asterisk can do it for free. And it really does work with many autodialers used by telemarketers. In fact, with most such systems, once the autodialer receives the special information tone, it places your number in their do-not-call database so you'll never be bothered again. Here's the code we previously recommended to handle calls without CallerID. First, for Asterisk@Home users and others using the Asterisk Management Portal, you tell Asterisk to send incoming calls to your AutoAttendant context. Of all the Asterisk@Home problems we read about, the number 1 issue hands down is incoming calls either ringing with a fast busy or being dropped immediately into voicemail. You fix both problems by deleting the current contents of your [from-sip-external] context and adding the following GoTo command to the [from-sip-external] context in the extensions.conf file. This will send incoming callers to your AutoAttendant (shown below).

exten => _.,1,Wait(1)
exten => _.,2,Goto(from-external-custom,s,1)

And then you drop the following AutoAttendant context into the bottom of your extensions_custom.conf config file. As we've mentioned before, if you cut-and-paste the code below, you'll need to manually replace the typographic quotation marks with regular quote marks, or Asterisk gets sent into the ozone.

[from-external-custom]
exten => s,1,Zapateller(answer|nocallerid)
exten => s,2,Wait(1)
exten => s,3,SetMusicOnHold(default)
exten => s,4,GotoIf($["${CALLERIDNUM}" = ""]?who-r-u,s,1)
exten => s,5,GotoIf($["foo${CALLERIDNUM}" = "foo"]?who-r-u,s,1)
exten => s,6,GotoIf($["${CALLERIDNAME:0:9}" = "Anonymous"]?who-r-u,s,1)
exten => s,7,GotoIf($["${CALLERIDNAME:0:7}" = "Unknown"]?who-r-u,s,1)
exten => s,8,GotoIf($["${CALLERIDNUM:0:7}" = "Private"]?who-r-u,s,1)
exten => s,9,GotoIf($["${CALLERIDNAME:0:7}" = "Private"]?who-r-u,s,1)
exten => s,10,GotoIf($["${CALLERIDNUM:0:10}" = "Restricted"]?who-r-u,s,1)
exten => s,11,GotoIf($["${CALLERIDNUM:0:4}" = "PSTN"]?who-r-u,s,1)
exten => s,12,DigitTimeout,3
exten => s,13,ResponseTimeout,3
exten => s,14,Background(custom/welcome)

exten => 0,1,Background(pls-hold-while-try)
exten => 0,2,AGI(directory,general,ext-local,${DIRECTORY:0:1}${DIRECTORY_OPTS})
exten => 0,3,VoiceMail(204@default) ; this assumes extension 204 is where you want your voicemail to land
exten => 0,4,Hangup
exten => 1,1,Background(pls-hold-while-try)
exten => 1,2,Dial(local/222@from-internal,20,m) ; we use extension 222 as a ring group to call ALL phones
exten => 1,3,VoiceMail(204@default)
exten => 1,4,Hangup
exten => 4,1,Authenticate(1234588)
exten => 4,2,Background(pls-wait-connect-call)
exten => 4,3,DISA(no-password|from-internal)

exten => 2XX,1,Background(pls-hold-while-try)
exten => 2XX,2,Dial(local/${EXTEN}@from-internal,20,m)
exten => 2XX,3,VoiceMail(${EXTEN}@default)
exten => 2XX,4,Hangup
exten => 2XX,103,Voicemail(${EXTEN}@default)
exten => 2XX,104,Hangup

exten => t,1,Background(pls-hold-while-try)
exten => t,2,Dial(local/204@from-internal,20,m)
exten => t,3,VoiceMail(204@default)
exten => t,4,Hangup

exten => o,1,Dial(local/204@from-internal,20,m) ; this is where pressing 0 takes the caller
exten => o,2,VoiceMail(204@default)
exten => o,3,Hangup

exten => i,1,Playback(wrong-try-again-smarty)
exten => i,2,Goto(s,16)

And finally you add the following two contexts to the bottom of the extensions_custom.conf file to handle the unidentified callers. The extension to ring to announce unidentified callers (204 in this example) is in line 70,5 below.

[who-r-u]
exten => s,1,Background(privacy-unident)
exten => s,2,Background(vm-rec-name)
exten => s,3,Wait(2)
exten => s,4,Record(/tmp/asterisk-stranger:gsm|5|15)
exten => s,5,Background(pls-hold-while-try)
exten => s,6,Goto(ext-park,70,1)
exten => s,7,VoiceMail(204@default)
exten => s,8,Playback(Goodbye)
exten => s,9,Hangup

[ext-park]
exten => 70,1,Answer
exten => 70,2,SetMusicOnHold(default)
exten => 70,3,SetCIDNum(200|a)
exten => 70,4,SetCIDName(Parked Call Info|a)
exten => 70,5,ParkAndAnnounce(silence/9:asterisk-friend:/tmp/asterisk-stranger:vm-isonphone:at-following-number:PARKED|40|local/204@from-internal|who-r-u,s,7)
exten => 70,6,Hangup

A footnote to all of this technology is that we personally receive so few legitimate calls from callers without CallerID that we've modified the [who-r-us] context to simply send all these callers straight to voicemail. We'll get a phone alert and an email whenever a new voicemail arrives so, if it's some sort of emergency, we can respond by returning the call immediately. Haven't seen one yet!

blankBlackListing. And then there are the smart telemarketers, and we'd put the Baby Bells at the top of this list. These are organizations that intentionally provide a fictitious CallerID number just to get around systems that block calls with no CallerID. They're still selling something, and they're just as annoying. They slip into your home under an exception to the Do-Not-Call Registry for "calls from organizations with which you have established a business relationship." In other words, if you buy local phone or cable TV service, these folks have a blank check to annoy the hell out of you ... forever! That's their interpretation of the statute anyway.


As luck would have it, Asterisk@Home 1.5 handles blacklisting callers using its internal database (ast_db) so you never have to take another annoying call from them. Just pick up your phone after an unwanted call, and press *32. That's it. Not much in what follows is original by the way. Our special thanks to Jacken's Blog for documenting all of this. All we've done is revise their code a bit to make it fit the configuration laid out in our other Asterisk@Home tutorials. Note also that problems have been reported using this code with the Asterisk@Home 2.0 betas, but we'll address that down the road as well. To implement BlackListing, we're going to add a line at the top and bottom of our AutoAttendant code and then renumber the 's' extension commands. We also need to adjust the pointer on line i,2 to goto s,17. So the new code looks like this. The way the LookupBlacklist command works is that, if a CallerID number is found in the BlackList database, execution jumps to line s,104 (3 + 101). From there, we send the call to a "special" context to handle blacklisted callers.

[from-external-custom]
exten => s,1,Zapateller(answer|nocallerid)
exten => s,2,Wait(1)
exten => s,3,LookupBlacklist ; If CID blacklisted, goto 104
exten => s,4,SetMusicOnHold(default)
exten => s,5,GotoIf($["${CALLERIDNUM}" = ""]?who-r-u,s,1)
exten => s,6,GotoIf($["foo${CALLERIDNUM}" = "foo"]?who-r-u,s,1)
exten => s,7,GotoIf($["${CALLERIDNAME:0:9}" = "Anonymous"]?who-r-u,s,1)
exten => s,8,GotoIf($["${CALLERIDNAME:0:7}" = "Unknown"]?who-r-u,s,1)
exten => s,9,GotoIf($["${CALLERIDNUM:0:7}" = "Private"]?who-r-u,s,1)
exten => s,10,GotoIf($["${CALLERIDNAME:0:7}" = "Private"]?who-r-u,s,1)
exten => s,11,GotoIf($["${CALLERIDNUM:0:10}" = "Restricted"]?who-r-u,s,1)
exten => s,12,GotoIf($["${CALLERIDNUM:0:4}" = "PSTN"]?who-r-u,s,1)
exten => s,13,DigitTimeout,3
exten => s,14,ResponseTimeout,3
exten => s,15,Background(custom/welcome)
exten => s,104,Goto(custom-blacklisted,s,1)

exten => 0,1,Background(pls-hold-while-try)
exten => 0,2,AGI(directory,general,ext-local,${DIRECTORY:0:1}${DIRECTORY_OPTS})
exten => 0,3,VoiceMail(204@default)
exten => 0,4,Hangup
exten => 1,1,Background(pls-hold-while-try)
exten => 1,2,Dial(local/222@from-internal,20,m)
exten => 1,3,VoiceMail(204@default)
exten => 1,4,Hangup
exten => 4,1,Authenticate(1234588)
exten => 4,2,Background(pls-wait-connect-call)
exten => 4,3,DISA(no-password|from-internal)

exten => 2XX,1,Background(pls-hold-while-try)
exten => 2XX,2,Dial(local/${EXTEN}@from-internal,20,m)
exten => 2XX,3,VoiceMail(${EXTEN}@default)
exten => 2XX,4,Hangup
exten => 2XX,103,Voicemail(${EXTEN}@default)
exten => 2XX,104,Hangup

exten => t,1,Background(pls-hold-while-try)
exten => t,2,Dial(local/204@from-internal,20,m)
exten => t,3,VoiceMail(204@default)
exten => t,4,Hangup

exten => o,1,Dial(local/204@from-internal,20,m)
exten => o,2,VoiceMail(204@default)
exten => o,3,Hangup

exten => i,1,Playback(wrong-try-again-smarty)
exten => i,2,Goto(s,17)

Now we need to drop in four BlackList contexts to let you respond to BlackListed callers and to manage your BlackList process using any touchtone phone. So, at the bottom of the extensions_custom.conf file, add the following:

[custom-blacklist-last]
exten => s,1,Answer
exten => s,2,Wait(1)
exten => s,3,DBget(number=CALLTRACE/${CALLERIDNUM}) ; goto 104 if no lastcaller
exten => s,4,GotoIf($"${number}" = ""?104) ; 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,Background(press-1)
exten => s,10,Background(or)
exten => s,11,Background(press-star-cancel)
exten => s,12,Hangup
exten => s,104,Playback(unidentified-no-callback)
exten => s,105,Background(goodbye)
exten => s,106,Hangup
exten => 1,1,DBput(blacklist/${number}=1)
exten => 1,2,Playback(privacy-blacklisted)
exten => 1,3,Wait,1
exten => 1,4,Background(goodbye)
exten => 1,5,Hangup
exten => t,1,Background(goodbye)
exten => t,2,Hangup
exten => i,1,Background(goodbye)
exten => i,2,Hangup
exten => o,1,Background(goodbye)
exten => o,2,Hangup

[custom-blacklist-add]
exten => s,1,Answer
exten => s,2,Wait(1)
exten => s,3,Playback(enter-num-blacklist)
exten => s,4,ResponseTimeout(30)
exten => s,5,Read(blacknr,then-press-pound)
exten => s,6,SayDigits(${blacknr})
exten => s,7,Playback(if-correct-press)
exten => s,8,Playback(digits/1)
exten => s,9,Hangup
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

[custom-blacklist-remove]
exten => s,1,Answer
exten => s,2,Wait(1)
exten => s,3,Playback(entr-num-rmv-blklist)
exten => s,4,DigitTimeout(5)
exten => s,5,ResponseTimeout(30)
exten => s,6,Read(blacknr,then-press-pound)
exten => s,7,SayDigits(${blacknr})
exten => s,8,Playback(if-correct-press)
exten => s,9,Playback(digits/1)
exten => s,10,Hangup
exten => 1,1,DBdel(blacklist/${blacknr})
exten => 1,2,SayDigits(${blacknr})
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,3,Background(tt-allbusy)
exten=>s,4,SetMusicOnHold,default
exten=>s,5,WaitMusicOnHold,30
exten=>s,6,Background(thank-you-for-calling)
exten=>s,7,Background(goodbye)
exten=>s,8,Congestion
exten=>s,9,Hangup

The [custom-blacklist-last] chunk of code automatically adds the phone number of your last incoming call to your BlackList. The [custom-blacklist-add] context lets you manually add a number to your BlackList. The [custom-blacklist-remove] context lets you remove a number that's already in your BlackList. And the [custom-blacklisted] context actually processes incoming callers who are on your BlackList. As currently written, the caller will get a message that "all members of the household are currently assisting other telemarketers ..." followed by music on hold. After 30 seconds, they are kissed goodbye with a congestion tone. I've also commented out the Jacken's Blog approach which is equally annoying. So take your pick.


The only remaining step to get all this working is to designate some extensions that will be dialed to access the three custom BlackList management contexts above. These need to be placed within the [from-internal-custom] context of your extensions_custom.conf file. Feel free to make up your own extension numbers so long as they don't conflict with existing extensions on your system. And be sure to change the Authenticate password in each of the three lines below. Once you add the extensions, reload Asterisk and BlackList someone you love... or at least someone you used to love.

exten => *30,1,Authenticate(45678)
exten => *30,2,Goto(custom-blacklist-add,s,1)

exten => *31,1,Authenticate(45678)
exten => *31,2,Goto(custom-blacklist-remove,s,1)

exten => *32,1,Authenticate(45678)
exten => *32,2,Goto(custom-blacklist-last,s,1)

exten => *33,1,Goto(custom-blacklisted,s,1)

How To Review Your BlackList. One final piece remains for our puzzle today. At some point down the line, you may want to review every number that's been entered into your BlackList. Here's how. Using SSH or Putty, connect to your Asterisk server and log in as root. Start up the Asterisk Command Line Interface (CLI) with the command asterisk -r. Now enter the following command at the asterisk*CLI> prompt: database show blacklist. You can manually delete an entry while you're here with the command: database del blacklist 0123456789 1. Don't forget the trailing 1. To manually add an entry to the database, enter the command: database put blacklist 0123456789 1.

You're an expert now. So just sit back and wait for the Bad Guys to call. They will.


Some Recent Nerd Vittles Articles of Interest...


8 Comments

  1. I changed the delete part of the blacklist function. With this version you need to accept the number to delete.

    [custom-blacklist-remove]
    exten=s,1,Playback(entr-num-rmv-blklist)
    exten=s,2,ResponseTimeout(60)
    ;exten=s,2,DigitTimeout(5)
    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

    Jacken

    [WM: Thanks very much. I made the changes you recommended in the body of the article as well.]

  2. WM, I’m an asterisk user, and not sure which version A@H is based on, but in the current version of asterisk, you can make life a lot easier by using "n" instead of a priority number (except for the first priority in an extension, which must be 1). This is a BIG win when modifying dial plans since you can avoid all that nasty renumbering stuff.

    If it works in A@H, I’d highly recommend you point it out and start using it in your examples.

    Thanks for all the great work. I’ve pulled a number of very useful things off your site for use in "Big" asterisk.

    Cheers,
    john

  3. I have posted an update on Jacken’s blog showing how I got Asterisk @ home v2.2 to check numbers against the blacklist without using the "lookupblacklist" function.

    [WM: One of my favorite sites! Thanks. Joel.]

  4. For the add and delete, you have exten => s,9,Hangup – I seem to be unable to get this to work with the hangup in there. I’ve removed it, and now it works. I think it was hanging up before it would give me a chance to press "1″ to accept the confirmation (to add or delete the number it just read back tome). I’m using AAH 2.5/Asterisk 1.2.4.

  5. in custom-blacklist-last for AAH-2.7 the following line:

    exten => s,4,GotoIf($"${number}" = ""?104) ; also if it’s blank (caller id blocked)

    needs to be changed to:
    exten => s,4,GotoIf($["${number}" = ""]?104) ; also if it’s blank (caller id blocked)

    Or at last that’s what works for me ; )
    (sorry if this msg dupes).

    G

  6. I removed

    exten=>s,8,Congestion

    and just added

    exten => s,8,Wait(1)
    exten => s,9,Hangup

    to my [custom-blacklisted]

    as it just gave a continuous congestion without a hangup. I don’t see much point in using congestion anyway after what you have put them through, but I do want my line back.

  7. This is very informative! Thank you for sharing this information! At least I can make some counter moves with those telemarketers calling me every hour!

    Thank you and more power!

Comments are closed.