Advertisement
TheGerman

TrueCNAM Perl example for use with Asterisk - call_start

Oct 15th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.26 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #
  3. # THIS SCRIPT IS INCOMPLETE - work in progress
  4.  
  5. use Asterisk::AGI;
  6. use LWP::UserAgent;
  7.  
  8. use strict;
  9.  
  10. # Set configuration parameters
  11. my $api_key = "YourAPIkey";
  12. my $api_password = "YourAPIpassword";
  13. my $service_url = "https://api.truecnam.net/api/v1";
  14.  
  15. #############################################################
  16. #
  17. # Get data from Asterisk
  18.  
  19. my $AGI = new Asterisk::AGI;
  20. my $calling_num = $AGI->get_variable("cidnum");
  21. my $called_num = $AGI->get_variable("callednum");
  22.  
  23. # Send request to TrueCNAM
  24.  
  25. my $url = $service_url."?username=".$api_key."&password=".$api_password."&resp_type=extended&resp_format=csv&calling_number=".$calling_num."&call_party=orig_call_start";
  26. $url .= "&called_number=".$called_num if ($called_num);
  27. my $content = "";
  28. my $ua = LWP::UserAgent->new;
  29. my $response = $ua->get($url);
  30.  
  31. if ($response->is_success) {
  32.         $content = $response->decoded_content;
  33.         #print $response->decoded_content . "\n";  # or whatever
  34. } else {
  35.         #die $response->status_line;
  36.         exit 0;
  37. }
  38.  
  39. my @res = split(",", $content);
  40.  
  41. # https://support.truecnam.com/support/solutions/articles/5000592940-trueclid-call-start-api-call-in-depth
  42. # ok,0,
  43. # Check for error
  44. #if ($res[11]) {
  45.         #exit 0;
  46. #}
  47.  
  48. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement