Support for notification popups on computers
plugger2:
hi MichiganTelephone,
I've got an alpha version (standard disclaimer for "still full of bugs, some known, most probably not") of a Python script that calls wget as a subprocess to grab the html from the call status every second or so. There are still a few things I don't understand about what it's doing, as I have two very similar versions, and one seem to be fairly robust with respect to handling the multiple popup windows, whereas as the other isn't (it may be timing problems, and the timing issues only show in one version but not the other. Probably means I have to rewrite some of threading code to really make it solid, even for the version that appears to be OK now.) In any case, I thought it would be interesting to see if we can get a version running at all on your Mac, to see if this approach has any chance of being portable.
If you are interested, I can email it or ftp it you... only thing is how do we exchange contact info so it doesn't end up in the public domain? I don't think this board has PM. Any ideas?
EDIT: I stand corrected. I've dropped you a PM.
AndroidsOfTara:
Quote from: MichiganTelephone on February 18, 2011, 10:49:02 am
I'd like to throw this out and just see if anyone has any thoughts on this. In the past, I have set things up so that whenever I get an incoming call, I get a popup on my computer screen.
I seem to have this working on my Ubuntu machine.
I took a bit of Perl code you posted somewhere in this thread and greatly enhanced it.
It polls the OBi every four seconds, grabs callstatus.htm and looks for inbound calls. It properly formats the phone number (xxx-xxx-xxxx) and (this is optional) will look the number up in a CSV contacts file (downloaded from Google Contacts). Finally, it uses Ubuntu's "notify-send" program to display the call on the screen in as a Growl-like notification.
I rarely do any programming, so please don't laugh too hard at my code. If anyone makes improvements, please share with us.
The only Ubuntu specific bit is the like where it calls upon the notify-send program, so I believe this code can very easily be adapted to run on any OS that supports a standard Perl installation.
Enjoy!
Code:
#!/usr/bin/perl
use LWP::UserAgent;
my $obi = "10.1.1.5:80";
my $obi_username = "admin";
my $obi_password = "admin";
my $url = 'http://10.1.1.5//callstatus.htm';
my $ua = new LWP::UserAgent;
my $debug = 0;
my $use_contacts = 0;
my $poll_time = 4;
my $sleep_time = 30;
if ($use_contacts == 1) {
print "Importing contacts...\n";
open(DATA,"<contacts1.csv") or die "Can't open data";
@contacts = <DATA>;
close(DATA);
}
$ua->timeout(2);
$ua->credentials($obi, 'admin@OBi110', $obi_username, $obi_password);
# loop forever
while(1) {
my $contact = "N/A";
my $request = HTTP::Request->new('GET');
$request->url($url);
my $response = $ua->request($request);
my $body = $response->content;
# look for 11 digit phone number
my @phones = $body =~ /\d{11}/g;
my $phone_number = $phones[0];
# look for the string "ringing"
# note: ringing state is "ringing" for inbound calls and "peer-ringing" for outbound calls
my @status_ringing = $body =~ /ringing/g;
my $phone_ringing = $status_ringing[0];
# look for the string "inbound"
my @status_direction = $body =~ /Inbound/g;
my $call_direction = $status_direction[0];
if ($debug == 1) {
print "---------------------------\n";
print "Phone: $phone_number\n";
print "Ringing: $phone_ringing\n";
print "Direction: $call_direction\n";
}
# check for inbound ring ("ringing") and not outbound ring ("peer-ringing")
if ($phone_ringing eq "ringing") {
# check for an inbound call
if ($call_direction eq "Inbound") {
if ($phone_number) {
$phone_number = formatPhoneNumber($phone_number);
$contact = searchContacts($phone_number);
my $message = "Incoming call from $contact ($phone_number)";
print "$message\n";
system("notify-send '$message' -t 2000");
sleep($sleep_time);
}
}
}
sleep($poll_time);
}
# properly format phone number
sub formatPhoneNumber {
my $number = shift;
my $number_length = length($number);
if ($number_length > 10) {
$number = substr($number, 1, 10);
}
$number =~ /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
my $number_formatted = "$1-$2-$3";
return $number_formatted;
}
# search contacts for phone number and return a contact name
sub searchContacts {
my $contact_search = shift;
my @contact_data = grep(/$contact_search/, @contacts);
my $contact = $contact_data[0];
my @contact_parts = split(',', $contact);
my $contact_name = @contact_parts[0];
$contact_name =~ s/"//g;
return $contact_name;
}
MichiganTelephone:
Quote from: AndroidsOfTara on March 26, 2011, 01:56:09 pm
Quote from: MichiganTelephone on February 18, 2011, 10:49:02 am
I'd like to throw this out and just see if anyone has any thoughts on this. In the past, I have set things up so that whenever I get an incoming call, I get a popup on my computer screen.
I seem to have this working on my Ubuntu machine.
I took a bit of Perl code you posted somewhere in this thread and greatly enhanced it.
Want to know the funny part? I hadn't seen your message and I started messing around with some Perl code this week. Didn't finish it (got everything but the part that generates the actual popups) but since you're working on this I'll show you what I have and you can see if there is anything at all you want to use (assuming you can figure it out). I am NOT a programmer so that's why something like this takes me so doggone long.
It polls the Obi once per second but in this demo only for 20 seconds, and prints out any notifications it receives (though what I found was that it does it after the program stops running, probably because you have to do something to flush the buffer and I don't know what). It does not have a contact search feature, but it does format 11 or 10 digit NANP numbers with dashes and 9 digit OBiTALK numbers with spaces. It also shows the time and day that the call was received (this might be especially useful if you use something like the "Recent Notifications" program with Ubuntu) and a destination identifier (whatever you put in the $ext variable near the top - it's helpful if you are monitoring more than one device and want to know which is ringing).
You obviously know more about Perl than I do so I don't know if there's anything here you would care to use, but if there is, feel free.
Code:
#!/usr/bin/perl
use LWP::UserAgent;
my $ext='2345';
my $ip='192.168.0.123';
my $pw='password';
my $obi='admin@OBi110';
my $regex1 = qr/current="(.*?)" >/;
my $regex2 = qr/type="input" default=" " current="'(.*?)>/;
my $regex3 = qr/^(.*?)'/;
my $regex4 = qr/' (.*?)"/;
my @months = (
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
);
my @weekdays = (
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
);
my $url = "http://$ip//PI_FXS_1_Stats.xml";
my $ua = new LWP::UserAgent;
$ua->timeout(2);
$ua->credentials("$ip:80", $obi, 'admin', $pw);
while ($count < 20) {
$count++;
sleep 1;
my $request = HTTP::Request->new('GET');
$request->url($url);
$request = $ua->request($request)->content;
my @status = $request =~ /$regex1/g;
if ( $status[0] eq "Ringing" ) {
if ( $flag== 0 ) {
$flag = 1;
my @cid = $request =~ /$regex2/g;
my @cidname = $cid[0] =~ /$regex3/g;
my @cidnum = $cid[0] =~ /$regex4/g;
$num = $cidnum[0];
$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/;
$num =~ s/^([2-9])(\d{2})(\d{3})(\d{3})$/$1$2 $3 $4/;
my (
$sec, $min, $hour, $mday, $mon,
$year, $wday, $yday, $isdst
) = localtime(time);
my $ampm = "AM";
if ( $hour > 12 ) {
$ampm = "PM";
$hour = ( $hour - 12 );
}
elsif ( $hour eq 12 ) { $ampm = "PM"; }
elsif ( $hour eq 0 ) { $hour = "12"; }
if ( $min < 10 ) { $min = "0" . $min; }
$year += 1900;
my $fulldate =
"$hour:$min $ampm on $weekdays[$wday], $months[$mon] $mday, $year";
print"$cidname[0]\n$num calling $ext at $fulldate\n";
}
}elsif ( $status[0] ne ""){
if ( $flag == 1 ) {
$flag = 0;
}
}
}
oleg:
I am curious why nobody mentioned SysLog facility. It's already implemented in OBi110 and for SIP calls can send more than enough information to the destination computer (although for GV calls it lacks call details - I hope OBi developers will catch up here ;)). Quite simple processing script may extract necessary details and pop-up message. Just my $0.02 :)
QBZappy:
MT
Just to suggest another possible option.
I know you are interested in finding a solution to obtain SIP notifications over the network using Growl. I came across this site which mentioned a open source SIP phone which works with Growl. It seems to work under Mac OS X as well. This might be something which might interest you.
http://en.wikipedia.org/wiki/Jitsi
Summary:
Jitsi (formerly SIP Communicator) is a VoIP, video conferencing, and instant messaging application for Windows, Linux and Mac OS X. It supports several popular instant messaging and telephony protocols.
Released under the terms of the GNU Lesser General Public License, Jitsi is free and open source software.
Jitsi is mostly written in Java which helps reuse most of the same code over the various operating systems it works on. The project also uses native code for the implementation of platform specific tasks such audio/video capture and rendering, IP address selection, and access to native popup notification systems such as Growl.
Edit: I just installed it on my Win 7 netbook. Network notifications is set enabled by default. Look under Tools->Options->Events for this setting. I don't use Growl, so unfortunately I can not test it.
Navigation
[0] Message Index
[#] Next page
[*] Previous page