Blocking Telemarketers

From Etel

Jump to: navigation, search

Contents

Title

Blocking Known Telemarketers

Problem

You want to block known telemarketers from ever ringing your phone based on their callerid.


Solution

Using a community driven database of telemarketers (http://whocalled.us) you can reduce the marketing calls you receive by sending them directly to voicemail, an endless loop, or whatever you desire.


Create the Following Telemarketer AGI Script in your AGI folder. Typically /var/lib/asterisk/agi-bin/ and give it execute permissions. Register on the whocalled.us website so you can use the web API changing the applicable information in the script.

#!/usr/bin/perl
use strict;
use Asterisk::AGI;
use LWP::Simple qw($ua get);
my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
#
# www.whocalled.us is a community driven database of telemarketers.. 
# Register on the whocalled.us website and enter your credentials here
my $whocalleduser = 'user';
my $whocalledpass = 'pass';
# How many reports to consider the number to be spam
my $wc_score = 5; 
# No Need to change anything below here.
$ua->agent('Mozilla/4.0 (compatible; Telemarketer Lookup)');
my $callerid = $input{'callerid'}; 
# Validate it is a 10 digit number..
if ($callerid !~ /^\d{10}$/){
    # Callerid Number is not 10 digits.. Mark it as spam..
    $AGI->set_variable('SPAM', 'yes');
    exit;
}
# Check the Whocalled.us WebSite
my $url = 'http://whocalled.us/do?action=getScore&name=' . $whocalleduser . '&pass=' . $whocalledpass. '&phoneNumber=' . $callerid;
my $output = get($url);
my ($score) = grep {/score/} split(/&/ , $output);
(undef,$score) = split(/=/, $score);
$score =~ s/\D//g;
$score = 0 unless $score =~ /^\d+$/;
if ($score >= $wc_score){
    # Spam Call
    $AGI->set_variable('SPAM', 'yes');
    exit;
}
# Passed the spam checks
$AGI->set_variable('SPAM', 'unknown');

Call the AGI script from your dialplan:

exten => _NXXNXXXXXX,1,AGI(callerid.pl)
# AGI Script Sets the SPAM variable.
exten => _NXXNXXXXXX,n,GotoIf($["${SPAM}"="yes"]?block)
exten => _NXXNXXXXXX,n,Dial()
exten => _NXXNXXXXXX,n(block),Voicemail(<voicemailbox>,u)


Discussion

See Also:

Metadata

David Van Ginneken davevg@btwtech.com

Personal tools