IPv4 Fremnet Logo
TOOLS, TINKERINGS & CODE

Support me

AGIPennytelCredit.pl · May 6, 22:36 by Shannon Wynter

I use Pennytel as one of my VoIP Service Providers. Recently they started offering a SOAP API to query their data.

Being a lover of knowing how much credit I have, I decided to knock up this little AGI script. I’ve got it set up to tell me my credits before every outgoing call.

I’d love for Pennytel to offer an XML version of their call rates with Dialing Prefix’s listed as I’d love to be able to teach asterisk to tell me how many minutes I can spend on a call.

Anyway, without further delay – here’s the code

  1. #!/usr/bin/perl  
  2. #****************************************************    
  3. #* AGIPennytelCredit.pl Version 1.0 *****************    
  4. #****************************************************    
  5. #* Writen by Freman aka Fremean                     *    
  6. #****************************************************    
  7. #* Pay a vist to http://fremnet.net/contact if you  *    
  8. #* Feel the burning desire to leave comments,       *    
  9. #* compliments, or complaints                       *    
  10. #****************************************************    
  11. #* Place this file in your AGI-BIN directory which  *    
  12. #* for me is /var/lib/asterisk/agi-bin             *    
  13. #* Add a call to it: agi(AGIPennytelCredit.pl) in   *    
  14. #* your extensions conf/ael                         *    
  15. #****************************************************    
  16.   
  17. use Asterisk::AGI;  
  18. use strict;  
  19. use vars qw($AGI);  
  20. use SOAP::Lite;  
  21.   
  22. my %Config = (  
  23.         # Your Pennytel phone number  
  24.         'PennytelVoIPID' => '0987654321',  
  25.         # The password for your SIP account - NOT the web interface password  
  26.         'PennytelVoIPPassword' => 'password',  
  27.         # You can download this file from http://pennytel.com/pennytelapi/services/PennyTelAPI?WSDL  
  28.         'PathToPennytelWSDL' => 'file:/var/lib/asterisk/agi-bin/Pennytel.wsdl',  
  29.         # I like to know the exact figure, but others might not care once it gets to parts of cents  
  30.         'SayPoints' => 1  
  31. );  
  32.   
  33. #****************************************************    
  34. # Nothing configurable below this line...  
  35. #****************************************************    
  36.   
  37. # Talk to asterisk  
  38. $AGI = new Asterisk::AGI;  
  39. my %input = $AGI->ReadParse();  
  40.   
  41. # Talk to pennytel  
  42. my $Answer = SOAP::Lite  
  43.     ->service($Config{PathToPennytelWSDL})  
  44.     ->getAccount($Config{PennytelVoIPID},$Config{PennytelVoIPPassword});  
  45.   
  46. # Make it presentable  
  47. my ($Dollars,$Cents) = split(/\./,$Answer->{balance});  
  48. $Cents = $Cents / 1000;  
  49. my ($Cents,$Points) = split(/\./,$Cents);  
  50.   
  51. # Tell the user  
  52. StreamFiles('your','account-balance-is');  
  53. $AGI->say_number($Dollars);  
  54. StreamFiles('dollar'.(($Dollars == 1)?'':'s'),('and'));  
  55. $AGI->say_number($Cents);  
  56. if ($Config{SayPoints}) {  
  57.     StreamFiles('point');  
  58.     $AGI->say_digits($Points);  
  59. }  
  60. StreamFiles('cents');  
  61.   
  62. sub StreamFiles {  
  63.         foreach (@_) {  
  64.                 $AGI->stream_file($_);  
  65.         }  
  66. }  
  67.  
  68. Download this code: AGIPennytelCredit.pl (Downloaded 247 time(s))

Comments

your_ip_is_blacklisted_by sbl.spamhaus.org

---== Copyright Shannon Wynter - All rights reserved - All wrongs avenged ==---