[asterisk-users] Block Spam Calls

Julian Beach jb_soft at trink.co.uk
Sat Dec 14 07:12:47 CST 2019


Hello Jeff,

Friday, December 13, 2019, 7:42:38 PM, you wrote:

> Mind posting your dialplan code?  I was thinking the same thing - very
> much like an old spam control program I used to use whose name now
> escapes me.  First time senders would have to respond to an auto-reply,
> then were added to a whitelist.

This  is not the neatest of code segments, as there are a few checks I
make before I let calls through to the phones:

(1) It  checks  for  blacklisted  callers, and sends them off to a go-away
message

(2) It checks whether there is Caller ID information, and sends sends
anon calls to another handler (again asking callers to press 1 or
leave a message) but there is also a switch to just send them to
voicemail: I had a problem with 1 anon caller phoning repeatedly a few
years ago, and that was the solution!

(3) For calls with a CID number, it checks whether these have called
before and if not, adds them to the previous caller db then sends them
to an IVR to play them a message and ask them to press a key (this
means that if they call again, they will always go through to the phones, as
a  number  of  genuine callers cannot, or won't, dial 1 - if they turn
out to be a robocall, they are blacklisted)

(4) Calls that pass all the tests go through to the phones

I  am  sure that I could make the code much more efficient, but it has
not  been  a  priority and I have been adding features as I need them,
rather than re-writing!


[from-pstn] (initial handler for PSTN calls)
exten => s,1,Log(NOTICE, Incoming PSTN Call from CDR ${CDR(src)} and CID ${CALLERID(name)})
exten => s,n,GotoIf(${DB_EXISTS(blacklist/${CDR(src)})}?block) ; Check whether caller blacklisted
exten => s,n,Set(DB(callers/lastcall)=${CDR(src)})
exten => s,n,Set(GLOBAL(CALLEDLINE)=L1-)
exten => s,n,GotoIf($["${CDR(src)}" != ""]?toincoming) ; if there is valid CID go to IncomingHome
exten => s,n,GotoIf($["${CALLERID(name)}" = "WITHHELD"]?nocid) ; if anon call...
exten => s,n,GotoIf($["${CALLERID(name)}" = "INTERNATIONAL"]?nocid)
exten => s,n,GotoIf($["${CALLERID(name)}" = "UNAVAILABLE"]?nocid)
exten => s,n,GotoIf($["${CALLERID(name)}" = "PAYPHONE"]?nocid)
exten => s,n,GotoIf($["${CDR(src)}" = ""]?drop)
exten => s,n(toincoming),GotoIf(${DB_EXISTS(previous/${CDR(src)})}?:unknown) ; Check whether caller has rung before
exten => s,n,GoSub(IncomingHome,s,1) ; answer the call in the macro
exten => s,n(nocid),GotoIf($[ $[ "${DB(variables/ANONTOVM)}" = "1" ] ]?vm) ; ...check whether anon goes straight to vm
exten => s,n,GoSub(IncomingHome,s,1) ; answer the call in the macro
exten => s,n(block),GoSub(Handler-MarketingCall,s,1) ; deal with blacklisted callers
exten => s,n(vm),Log(NOTICE, No CID data or AnontoVM set) ; send anon callers to AnonCall IVR
exten => s,n,Goto(AnonCall-menu,s,1)
exten => s,n(unknown),Log(NOTICE, Unknown caller to IVR) ; send unknown callers to UnknownCaller IVR
exten => s,n,Set(DB(previous/${CDR(src)})=1) ; add number to previous caller DB
exten => s,n,GoSub(UnknownCaller-menu,s,1,(${CDR(src)}))
exten => s,n(drop),Log(NOTICE, No CID data, call dropped) ; drop calls with no CID info
exten => s,n,Wait(15)
exten => s,n,Hangup()


[UnknownCaller-menu]  ; The  Unknown  caller IVR - with some logging of
call volumes

exten => s,1,Log(NOTICE,Unknown Caller ${ARG1} - Caller to IVR)
exten => s,n,Verbose(2,Anon Calls = ${DB(unknown/total)} Total, ${DB(unknown/valid)} Valid, ${DB(unknown/invalid)} Invalid)
exten => s,n,Set(unknown=$[${DB(unknown/total)} + 1])
exten => s,n,Set(DB(unknown/total)=${unknown})
exten => s,n,Verbose(2,Unknown Calls set to ${DB(unknown/total)})
exten => s,n,Answer(500)
exten => s,n(loop),Background(unknown)
exten => s,n,WaitExten()
; 1 - Call to incoming call handler
exten => 1,1,NoOp(Real caller progressing)
exten => 1,n,Log(NOTICE,Unknown Call - Caller dialled to continue to phones)
exten => 1,n,Set(valid=$[${DB(unknown/valid)} + 1])
exten => 1,n,GoSub(IncomingHome,s,1)
exten => 1,n,Hangup()
; 2 - invalid entry
exten => i,1,Playback(invalid)
exten => i,n,Log(NOTICE,Unknown Call - Caller dialled invalid number)
exten => i,n,Set(invalids=$[${DB(unknown/invalid)} + 1])
exten => i,n,Set(DB(unknown/invalid)=${invalids})
exten => i,n,Goto(s,loop)
; 3 - timeout
exten => t,1,Playback(invalid)
exten => t,n,Log(NOTICE,Unknown Call - Caller timed out)
exten => t,n,Set(invalids=$[${DB(unknown/invalid)} + 1])
exten => t,n,Set(DB(unknown/invalid)=${invalids})
exten => t,n,GoSub(subMessaging,s,1,(${ARG1}),("Unknown"))
exten => t,n,Hangup()



--
Best regards,
 Julian                            mailto:jb_soft at trink.co.uk 




More information about the asterisk-users mailing list