Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # Product website: https://data.youmail.com/
- # Documentation: https://data.youmail.com/documentation
- #
- # Script revised by freecode768
- # https://www.fiverr.com/freecode768
- use strict;
- use warnings;
- use JSON qw(from_json);
- use Asterisk::AGI;
- use LWP::UserAgent;
- # Set configuration parameters
- my $api_sid = "977222...5605"; # UPDATE with your REAL API SID
- my $api_token = "ba2227d...bb7f333380"; # UPDATE with your REAL API TOKEN
- my $service_url = "https://dataapi.youmail.com/api/v2/phone/";
- #############################################################
- #
- # Get data from Asterisk
- my $AGI = new Asterisk::AGI;
- my $calling_num = $AGI->get_variable("CALLERID(num)");
- my $calling_name = $AGI->get_variable("CALLERID(name)");
- my $called_num = $AGI->get_variable("DID");
- # Send request to YouMail
- my $url = $service_url . $calling_num . "/?format=json&callee=" . $called_num . "&callerId=" . $calling_name;
- my $content = "";
- my $ua = LWP::UserAgent->new(agent => "Mozilla/5.0");
- # authenticate
- $ua->default_header( 'DataApiSid' => $api_sid );
- $ua->default_header( 'DataApiKey' => $api_token );
- # make request
- my $request = HTTP::Request->new(GET => $url);
- # 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 $statusCode = $res->{statusCode};
- my $recordFound = $res->{recordFound};
- my $phoneNumber = $res->{phoneNumber};
- my $timestamp = $res->{timestamp};
- my $spamRisklevel = $res->{spamRisk}{level};
- # spamRisk->level:
- # 0 = This number appears to be valid (not likely a spammer)
- # 1 = This number appears to be a spammer, but the data is inconclusive
- # 2 = There is very strong evidence that this number is a spammer
- # If everything is OK, write results to variables below
- $AGI->exec('Set', "UMcode=$statusCode");
- $AGI->exec('Set', "UMfound=$recordFound");
- $AGI->exec('Set', "UMlevel=$spamRisklevel");
- $AGI->exec('Set', "UMnumbr=$phoneNumber");
- $AGI->exec('Set', "UMtime=$timestamp");
- if ($recordFound && ($spamRisklevel eq "1" || $spamRisklevel eq "2")) {
- $AGI->exec('Set', 'SPAMROUTE=HANGUP');
- } else {
- $AGI->exec('Set', 'SPAMROUTE=CLEAN');
- }
- exit 0;
Add Comment
Please, Sign In to add comment