Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #
- # Twilio API - TrueSpam by TrueCNAM
- # Cost: US$0.003 per request
- # Identify robocalls, telemarketers, scams and other unwanted calls
- # TrueSpam scores indicate the likelihood that an incoming call is
- # from a robocaller, telemarketer, scammer, or other unwanted caller.
- # Multiple sources are utilized to identify unwanted calls quickly
- # and accurately including: real-time traffic flows, a large honeypot
- # network, network deployed CAPTCHA's, feedback reports from
- # end-users, public and private government data, and other methods.
- # The TrueSpam service is trusted and deployed in carrier networks
- # throughout North America with established ILECs, CLECs, and VoIP
- # providers.
- use strict;
- use warnings;
- use JSON qw(from_json);
- use Asterisk::AGI;
- use LWP::UserAgent;
- # Set configuration parameters
- my $api_sid = "XYZ";
- my $api_token = "XYZ";
- my $service_url = "https://lookups.twilio.com/v1/PhoneNumbers/+1";
- my $api_name = "truecnam_truespam";
- my $voicemail = 40;
- my $disconnect = 80;
- #############################################################
- #
- # Get data from Asterisk
- #
- my $AGI = new Asterisk::AGI;
- my $calling_num = $AGI->get_variable("cidnum");
- my $called_num = $AGI->get_variable("callednum");
- # Send request to Twilio API
- my $url = $service_url . $calling_num . "/?AddOns=" . $api_name;
- my $content = "";
- my $ua = LWP::UserAgent->new(agent => "Mozilla/5.0");
- # make request
- my $request = HTTP::Request->new(GET => $url);
- # authenticate
- $request->authorization_basic($api_sid, $api_token);
- # get response
- my $response = $ua->request($request);
- if ($response->is_success) {
- $content = $response->decoded_content;
- }
- else {
- die $response->status_line;
- exit 0;
- }
- my $res = from_json($content); # convert JSON to a Perl data structure
- my $risk_match = $res->{add_ons}{results}{truecnam_truespam}{result}{spam_score_match};
- my $risk_level = $res->{add_ons}{results}{truecnam_truespam}{result}{spam_score};
- my $risk_status = $res->{add_ons}{results}{truecnam_truespam}{status};
- my $risk_sid = $res->{add_ons}{results}{truecnam_truespam}{request_sid};
- # If everything is OK, write results to variables below
- $AGI->exec('Set', "TSmatch=$risk_match");
- $AGI->exec('Set', "TSscore=$risk_level");
- $AGI->exec('Set', "TSstatus=$risk_status");
- $AGI->exec('Set', "TSsid=$risk_sid");
- if ($risk_level >= $disconnect) {
- $AGI->exec('Set', 'SPAMROUTE=HANGUP');
- } else {
- $AGI->exec('Set', 'SPAMROUTE=PASS');
- }
- exit 0;
Add Comment
Please, Sign In to add comment