Asterisk block incoming call with certain Caller IDs

asterisk

So I know this is a fairly simple question, but I can't seem to find a good answer to it. I have a DID which is getting hit fairly hard (or at least for me, about 1-3 calls per day) with telemarketers from non 1-8XX numbers. However there are only a handful of numbers that call day in and day out. So naturally I would just like to block them so my phone doesn't ring and I don't get billed for a call.

I'm looking to send a SIP/404 or some other non-answer response– not send them to voicemail or another recording. I don't really care about logging or anything like that, I just would like to be able to add (or remove) a number fairly easily so I can cut down on unnecessary calls.

Everything I find seems to be either too complex or too simple (only one blocked number) and I can't find a good medium. Hopefully someone else will have better insight! I am using Asterisk 1.6. Thank you!

Best Answer

I've done something similar and like the other submitter, I used a database. Instead of using the built int DB functionality, I used cmd MySQL. This was so I could write a web page that interacts with the same DB AND my DBA could do cross DB selects between this "Directory" table and the MySQL CDR.

In my example, I setup a table with 4 fields. id (auto_increment int), number (the phone number), name (The name of user), ban (an int that defaults to 0). The example does 2 things, 1- it looks up name from the DB and sets that as the caller id (Since our POTS line doesn't communicate that) 2- It looks up to see if ban is set to 1, and blocks the call.

exten => s,1,Answer
exten => s,n,NoOp("Caller ID IS: ${CALLERID(number)}")
exten => s,n,MYSQL(Connect connid HOST USER PASSWORD database)
exten => s,n,MYSQL(Query resultid ${connid} SELECT name,ban FROM directory WHERE number='${CALLERID(number)}')
exten => s,n,MYSQL(Fetch fetchid ${resultid} name ban)
exten => s,n,NoOp("We found: ${name} ${ban}")
exten => s,n,MYSQL(Clear ${resultid})
exten => s,n,MYSQL(Disconnect ${connid});
exten => s,n,Set(CALLERID(name)=${name})
exten => s,10,NoOp()
exten => s,n,GotoIf($["${ban}" = "1"]?wedontlikeyou,s,1)
exten => s,n,Goto(mainmenu,s,1)

After this you'd have your [mainmenu] and [wedontlikeyou]. The later is your ban, it could be a simple hangup, error message, what ever you want. My preference is Congestion() since that tends to make people think the phone number is out of service.