Adding asterisk notifications to prowl

An iPhone client for Growl available on the App Store.
joule
Harmless
Posts: 9
Joined: Thu Jul 09, 2009 2:04 pm

Adding asterisk notifications to prowl

Postby joule » Thu Jul 09, 2009 3:07 pm

My code is based on growlsend.agi and uses WebService::Prowl from Sekimura.
You will need to install Asterisk::AGI and WebService::Prowl from CPAN or similar sources.

First create a file named /var/lib/asterisk/agi-bin/prowlsend.agi with the content:

Code: Select all

#!/usr/bin/perl
use strict;
use warnings;
use Asterisk::AGI;
my $agi = new Asterisk::AGI;
my %input = $agi->ReadParse();
my $num = $input{'callerid'};
my $name = $input{'calleridname'};
my $ext = $input{'extension'};

if ( $ARGV[1] ne "" ) {
        $ext = $ARGV[1];
}

my @months = (
    "January", "February", "March",     "April",   "May",      "June",
    "July",    "August",   "September", "October", "November", "December"
);
my @weekdays = (
    "Sunday",   "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday"
);
my (
   $sec,  $min,  $hour, $mday, $mon,
   $year, $wday, $yday, $isdst
) = localtime(time);
my $ampm     = "AM";
my $datahour = $hour;
if ( $hour eq 12 ) { $ampm = "PM"; }
if ( $hour eq 0 )  { $hour = "12"; }
if ( $hour > 12 ) {
    $ampm = "PM";
    $hour = ( $hour - 12 );
}
if ( $min < 10 ) { $min = "0" . $min; }
$year += 1900;
my $fulldate = "$hour:$min $ampm on $weekdays[$wday], $months[$mon] $mday, $year";

# Next two lines normalize NANP numbers, probably not wanted outside of U.S.A./Canada/other NANP places
$num =~ s/^([2-9])(\d{2})([2-9])(\d{2})(\d{4})$/$1$2-$3$4-$5/;
$num =~ s/^(1)([2-9])(\d{2})([2-9])(\d{2})(\d{4})$/$1-$2$3-$4$5-$6/;

use WebService::Prowl;
my $ws = WebService::Prowl->new('apikey' => $ARGV[0]);
$ws->verify || die $ws->error();
$ws->add(application => "Asterisk",
         event       => "Incoming Call",
         description => "$num at $fulldate");


chmod a+x the script, so Asterisk can execute it.
Then, in the asterisk extensions.conf, where you receive calls, add

Code: Select all

exten => s,n,AGI(prowlsend.agi,${PROWLKEY},${EXTEN});


For instance, I have

Code: Select all

[from-pstn]
exten => s,1,Set(CALLERID(name)=${IF($["${CALLERID(name)}"=""]?${CALLERID(number)}:${CALLERID(name)})})
exten => s,n,AGI(prowlsend.agi,${PROWLKEY},${EXTEN});
exten => s,n,Dial(${PHONE},20,tr);

(first line normalizes missing caller ids in Argentina).

Notice you can use variables, and add your prowl key to a variable.

I hope this helps someone, just wanted to give something back.

netnut404
Harmless
Posts: 16
Joined: Thu Mar 25, 2010 6:44 pm

Re: Adding asterisk notifications to prowl

Postby netnut404 » Thu Mar 25, 2010 7:40 pm

Which version of asterisk is this written for? I was wondering if that makes a difference, as I have been trying to add this, but not getting anywhere.. maybe my freepbx is getting on the way..
since I want it to notify before ringing a specific extension it must go into extensions_adittional.conf it looks like in my case..
I was looking for the best way to have it execute when ringing a specific extension, or ring group..
any pointers would be great, thanks..

Net Nut

aniskhwaja
Harmless
Posts: 1
Joined: Fri Jul 16, 2010 12:50 am

Re: Adding asterisk notifications to prowl

Postby aniskhwaja » Fri Jul 16, 2010 1:10 am

netnut,
I am using freepbx as well, rebuilt a couple of months ago, don't remember the freepbx (1.6? whatever was current a couple of months ago) version but asterisk is 1.4. This script works perfectly.
1. You need to add the lines in extensions_custom.conf not in extensions_adittional.conf. extensions_adittional.conf is overwritten every time by freepbx whenever you make changes. if you dont have extensions_custom.conf just make one.

2. Near the top of extensions_custom.conf there should be a section [from-internal-custom]
in this section add the following:

exten => ****555,1,AGI(prowlsend.agi,fxxxxxxxxxxxxx8e8f0e38axxxxxx,${EXTEN})
exten => ****555,n,Busy

where fxxxxxxxxxxxxx8e8f0e38axxxxxx is your Prowl API key, and ****555 is the extension, from there on you can put this extension in a ring group, and choose ringall, and you will get the notifications.

netnut404
Harmless
Posts: 16
Joined: Thu Mar 25, 2010 6:44 pm

Re: Adding asterisk notifications to prowl

Postby netnut404 » Fri Jul 16, 2010 3:30 am

awesome.. that was perfect thanks :!: =-)

netnut404
Harmless
Posts: 16
Joined: Thu Mar 25, 2010 6:44 pm

Re: Adding asterisk notifications to prowl

Postby netnut404 » Fri Jul 16, 2010 8:17 pm

ok, so something odd.. I can dial the extension it gives a busy tone, and I get instant notification on my phone.. but adding that # to a ring group does not notify me when that ring group is called.

netnut404
Harmless
Posts: 16
Joined: Thu Mar 25, 2010 6:44 pm

Re: Adding asterisk notifications to prowl

Postby netnut404 » Fri Aug 06, 2010 12:40 am

Is this actually working for you inside the ring group?
I get the push notification fine if I dial extension directly, but adding to the ring group does nothing..
seems I am missing something..

NetNut

aniskhwaja wrote:netnut,
I am using freepbx as well, rebuilt a couple of months ago, don't remember the freepbx (1.6? whatever was current a couple of months ago) version but asterisk is 1.4. This script works perfectly.
1. You need to add the lines in extensions_custom.conf not in extensions_adittional.conf. extensions_adittional.conf is overwritten every time by freepbx whenever you make changes. if you dont have extensions_custom.conf just make one.

2. Near the top of extensions_custom.conf there should be a section [from-internal-custom]
in this section add the following:

exten => ****555,1,AGI(prowlsend.agi,fxxxxxxxxxxxxx8e8f0e38axxxxxx,${EXTEN})
exten => ****555,n,Busy

where fxxxxxxxxxxxxx8e8f0e38axxxxxx is your Prowl API key, and ****555 is the extension, from there on you can put this extension in a ring group, and choose ringall, and you will get the notifications.

netnut404
Harmless
Posts: 16
Joined: Thu Mar 25, 2010 6:44 pm

Re: Adding asterisk notifications to prowl

Postby netnut404 » Sun Aug 08, 2010 11:07 am

Just in case anyone finds this thread and has the same trouble I did, I found I had to put the extension and a # symbol at the end in the ring group for it to actually send the notifications when the ring group was called instead of just the extension directly..

I hope that might help someone, and thanks again for the code.. now if we could only get the notifications to launch the wifone app I would be set.. is this possible?

Net Nut.

netnut404 wrote:Is this actually working for you inside the ring group?
I get the push notification fine if I dial extension directly, but adding to the ring group does nothing..
seems I am missing something..

NetNut

aniskhwaja wrote:netnut,
I am using freepbx as well, rebuilt a couple of months ago, don't remember the freepbx (1.6? whatever was current a couple of months ago) version but asterisk is 1.4. This script works perfectly.
1. You need to add the lines in extensions_custom.conf not in extensions_adittional.conf. extensions_adittional.conf is overwritten every time by freepbx whenever you make changes. if you dont have extensions_custom.conf just make one.

2. Near the top of extensions_custom.conf there should be a section [from-internal-custom]
in this section add the following:

exten => ****555,1,AGI(prowlsend.agi,fxxxxxxxxxxxxx8e8f0e38axxxxxx,${EXTEN})
exten => ****555,n,Busy

where fxxxxxxxxxxxxx8e8f0e38axxxxxx is your Prowl API key, and ****555 is the extension, from there on you can put this extension in a ring group, and choose ringall, and you will get the notifications.

donnib
Harmless
Posts: 1
Joined: Mon Sep 12, 2011 10:54 am

Re: Adding asterisk notifications to prowl

Postby donnib » Mon Sep 12, 2011 10:57 am

Hi, I wanted to post an more simplified version of the above script for others. An user named mst (http://www.shadowcat.co.uk/blog/matt-s-trout/) from the #perl IRC chat channel on Freenode helped me to create this one:

Code: Select all

#!/usr/bin/perl
use strict;
use warnings;
use Asterisk::AGI;
use POSIX qw(strftime);
my $agi = Asterisk::AGI->new;
my %input = $agi->ReadParse();

# Variables passed from Asterisk dialplan
my ($num, $name, $dnid) = @input{qw(callerid callername dnid)};

# Get the system time
my $fulldate = strftime("%T on %A, %B %d, %Y", localtime);

# Next two lines normalize NANP numbers, probably not wanted outside of U.S.A./Canada/other NANP places
$num =~ s/^([2-9])(\d{2})([2-9])(\d{2})(\d{4})$/$1$2-$3$4-$5/;
$num =~ s/^(1)([2-9])(\d{2})([2-9])(\d{2})(\d{4})$/$1-$2$3-$4$5-$6/;

use WebService::Prowl;
my $ws = WebService::Prowl->new(apikey => $ARGV[0]);
$ws->verify || die $ws->error();
$ws->add(application => "Asterisk",
         event       => "Incoming Call",
         description => "Call on $dnid from $name $num at $fulldate");


The script does the same thing as the above one but is simplified.

donnib

netnut404
Harmless
Posts: 16
Joined: Thu Mar 25, 2010 6:44 pm

Re: Adding asterisk notifications to prowl

Postby netnut404 » Mon Sep 12, 2011 5:07 pm

Thanks, I will give that a try.. been using the previous one for a while now
maybe some day zoiper for the iphone will allow urls and we can use the push notifications to launch the app :rolleyes:

Net Nut

netnut404
Harmless
Posts: 16
Joined: Thu Mar 25, 2010 6:44 pm

Re: Adding asterisk notifications to prowl

Postby netnut404 » Fri Sep 30, 2011 7:35 pm

this is kind of asterisk related, but definitely related to this thread.. Since my iPhone is jailbroken I edited the Info.plist for zoiper for the iphone and added a custom url to prowl so a incoming call to a ring group notifies the phone and launches zoiper quite nicely.. the only problem is the extension for the zoiper is already determined to not be connected, so it is not ringing to answer the call once the app opens up I have been able to do a **and dial one of the extensions in the ring group.. but I wondered if you had any idea how to tell it to ring that extension no matter what.. at very least I thought I could share my progress and tell you how I am using the notifications. :)

zoa
Harmless
Posts: 1
Joined: Fri Nov 04, 2011 7:54 am

Re: Adding asterisk notifications to prowl

Postby zoa » Fri Nov 04, 2011 7:58 am

Zoiper support here :)

Just found this thread by coincidence, please send all feature requests to support@zoiper.com and we will try to incorporate them in future versions. The next version is about to be released, i hope it will be on the app store in a week. It should be quite an improvement over the currently available 1.2, i hope you will like it. The url support is not there yet, but we have it on our todo list so it will probably make it in the near future.

Joachim

kris2012
Harmless
Posts: 2
Joined: Tue Feb 21, 2012 12:52 am

Re: Adding asterisk notifications to prowl

Postby kris2012 » Tue Feb 21, 2012 1:04 am

thanks, hope this will work. I'm new to perl and experiment it with asterisk on my linux box. btw can you explain the below codes?
$num =~ s/^([2-9])(\d{2})([2-9])(\d{2})(\d{4})$/$1$2-$3$4-$5/;
$num =~ s/^(1)([2-9])(\d{2})([2-9])(\d{2})(\d{4})$/$1-$2$3-$4$5-$6/;


donnib wrote:Hi, I wanted to post an more simplified version of the above script for others. An user named mst (http://www.shadowcat.co.uk/blog/matt-s-trout/) from the #perl IRC chat channel on Freenode helped me to create this one:

Code: Select all

#!/usr/bin/perl
use strict;
use warnings;
use Asterisk::AGI;
use POSIX qw(strftime);
my $agi = Asterisk::AGI->new;
my %input = $agi->ReadParse();

# Variables passed from Asterisk dialplan
my ($num, $name, $dnid) = @input{qw(callerid callername dnid)};

# Get the system time
my $fulldate = strftime("%T on %A, %B %d, %Y", localtime);

# Next two lines normalize NANP numbers, probably not wanted outside of U.S.A./Canada/other NANP places
$num =~ s/^([2-9])(\d{2})([2-9])(\d{2})(\d{4})$/$1$2-$3$4-$5/;
$num =~ s/^(1)([2-9])(\d{2})([2-9])(\d{2})(\d{4})$/$1-$2$3-$4$5-$6/;

use WebService::Prowl;
my $ws = WebService::Prowl->new(apikey => $ARGV[0]);
$ws->verify || die $ws->error();
$ws->add(application => "Asterisk",
         event       => "Incoming Call",
         description => "Call on $dnid from $name $num at $fulldate");


The script does the same thing as the above one but is simplified.

donnib

netnut404
Harmless
Posts: 16
Joined: Thu Mar 25, 2010 6:44 pm

Re: Adding asterisk notifications to prowl

Postby netnut404 » Thu Jun 07, 2012 5:53 pm

I have been using this new version of the code for a while, and it works quite well thanks, but I have had one problem that always buggs me the notification always says "Call on unknown from" and then the phone # is that supposed to tell me which trunk it's using or something ? knowing which trunk it came in on would be awesome . anyway thanks again and any help you can provide on the $dnid / unknown thing would be great

NetNut


donnib wrote:Hi, I wanted to post an more simplified version of the above script for others. An user named mst (http://www.shadowcat.co.uk/blog/matt-s-trout/) from the #perl IRC chat channel on Freenode helped me to create this one:


donnib wrote: my ($num, $name, $dnid) = @input{qw(callerid callername dnid)};

description => "Call on $dnid from $name $num at $fulldate");
donnib

netnut404
Harmless
Posts: 16
Joined: Thu Mar 25, 2010 6:44 pm

Re: Adding asterisk notifications to prowl

Postby netnut404 » Wed Feb 06, 2013 12:35 am

can anyone tell me what I should replace $dnid with in asterisk 1.8 so instead of saying a new call on unknown it could tell me the trunk/line they dialed in on?



This has bugged me for a while, but I know nothing about asterisk agi scripts lol :sad:

Any help would be greatly appreciated

donnib wrote this..

Code: Select all

    #!/usr/bin/perl
    use strict;
    use warnings;
    use Asterisk::AGI;
    use POSIX qw(strftime);
    my $agi = Asterisk::AGI->new;
    my %input = $agi->ReadParse();

    # Variables passed from Asterisk dialplan
    my ($num, $name, $dnid) = @input{qw(callerid callername dnid)};

    # Get the system time
    my $fulldate = strftime("%T on %A, %B %d, %Y", localtime);

    # Next two lines normalize NANP numbers, probably not wanted outside of U.S.A./Canada/other NANP places
    $num =~ s/^([2-9])(\d{2})([2-9])(\d{2})(\d{4})$/$1$2-$3$4-$5/;
    $num =~ s/^(1)([2-9])(\d{2})([2-9])(\d{2})(\d{4})$/$1-$2$3-$4$5-$6/;

    use WebService::Prowl;
    my $ws = WebService::Prowl->new(apikey => $ARGV[0]);
    $ws->verify || die $ws->error();
    $ws->add(application => "Asterisk",
             event       => "Incoming Call",
             description => "Call on $dnid from $name $num at $fulldate");


Return to “Prowl”

Who is online

Users browsing this forum: No registered users