AppleScript C Perl Shell Xcode Other

FreePBX Send to Growl, Local CID Lookup and CRM

Post Reply
coding / perl     Views: 1042Prev .. Next
FreePBX Send to Growl, Local CID Lookup and CRMPosted: Tuesday, February 13, 2018 [21:27:47] - 1
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
Used FreePBX at home for few months now and phone ring always spooks me.
Went investigating how can I show sort of Growl message on my Macs before phone starts ringing.
It turned-out there in a an option in CallerID Superfecta - Send to Growl.
Played around with it for a while and it never worked. Did not find any info on how to debug the situation and decided to do it myself.

Also, I wanted to know weather I spoke with the person earlier or not before picking up the phone.
FreePBX reports all calls to my Mac and Mac keeps the database of calls and names. Sorta home-made CRM (Customer Relationship Management) database.

So, there is an option in FreePBX to set local CID Lookup using HTTP/HTTPS requests. I set a HTTP CID Lookup requests to one of my Macs on LAN:

Post 18575267 Image 1

After it's all good and dandy Inbound Routes have to be configured to fire-up a local (or Web) request.

Post 18575267 Image 2

and result is a Growl message on a big screen TV:

Post 18575267 Image 3

Now, before phone starts ringing we have a nice informative pop-up with sound, so phone ring is not a surprise.
Also, Growl shows a sticky message and if we missed a call or two - they all on a screen.There's no place like ~
RE: FreePBX Send to Growl, Local CID Lookup and CRMPosted: Tuesday, February 13, 2018 [22:00:49] - 2
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
Also wanted to say a few words on how to make things work.
It appears that caching results for CIDLookup make CallerID Superfecta to lose the CID record for know callers, so CIDLookup is set Cache Results to "No".

Here is a snip of Perl that does a CID lookup:
View Code#!/usr/bin/perl
..
# process input $ENV{'QUERY_STRING'}
..
print "Content-type: text/plain\n\n";
my $reportname;
## See if a phone number in a Contacts database
if(-f "/http/cdr/search.phones.txt") {eval {require "/http/cdr/search.phones.txt"};
if($dsrch{$in{'number'}}{'en'}) {
# Print Contact name - that is all we will print as a Lookup result
print "$dsrch{$in{'number'}}{'en'}";
$reportname=$dsrch{$in{'number'}}{'en'};
} ## End number in Contacts
} ## End if DB file present

## Get info record unless present
unless($dsrch{$in{'number'}}{'city'}) {
my $ipres = `/opt/local/bin/curl "http://apilayer.net/api/validate?access_key=xxxxxxxxxxxxxxxxxxxxxx&number=+$in{'number'}"`;
# and write it to a database
} ## End unless city present
my $kztme=time;$kztme = localtime($kztme);$kztme =~ tr/ //s;
my ($wd,$mo,$da,$ti,$ye) = split(/\s/,$kztme);
my $when = "$wd, $mo $da, $ye [$ti]";

# Send it to Growl
eval {use Net::Growl};
unless($@) {
register(host => 'localhost',
application=>"IncomingCalls",
password=>'your_password', ) if ! $ALREADY_REGISTERED;
notify(
application=>"IncomingCalls",
title=>'Incoming Call from',
description=> "$reportname\n$in{'number'}\n$dsrch{$in{'number'}}{'city'}$dsrch{$in{'number'}}{'state'}\n$dsrch{$in{'number'}}{'carrier'}\n$when",
priority=>2,
sticky=>'False',
password=>'your_password',
);
} ## END GOOD EVAL


All kind of information can be send to Growl and Growl can send this message to other Macs.

And yes, in 2018 we're still using Show Leopard as our main Mac OS X on 5 Macs without any needs to upgrade.
We love cats!
;)There's no place like ~
Forward lookup results to Growl on LANPosted: Wednesday, October 3, 2018 [20:57:20] - 3
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
For some reason I was unable to make Growl to communicate with other computers with Growl running on LAN.
It did not hit me until now - I can curl the result to other Macs.

Just added CURL request to my laptop that is always with me after the Growl message being processed to a cid.cgi Perl script.
If I am not home - program will not forward. Just added to the cid.cgi the following:
View Code..
## Make sure MacBook is present on LAN
my $dcheck = `ping -q -c 1 -W 1 192.168.2.32`;
if($dcheck =~ m/1 packets received/) {## Run only if response received
my $data="$reportname\n\n$in{'number'}$carrier$location\n$when";$data =~ s/([\W])/"%" . uc(sprintf("%2.2x",ord($1)))/eg;
`curl http://192.168.2.32/cid.cgi?data=$data`;
} ## END GOOD PING


and on MacBook I have similar perl script, but shorter:
View Code
#!/usr/bin/perl
..
# process input $ENV{'QUERY_STRING'}
..

if($in{'data'}) {
BEGIN {
push ( @INC,"/opt/local/lib/perl5/site_perl/5.24");
}
eval {use Net::Growl};
unless($@) {
register(host => 'localhost',
application=>"IncomingCalls",
password=>'Growl_Password', ) if ! $ALREADY_REGISTERED;
notify(
application=>"IncomingCalls",
title=>'Incoming Call from',
description=> $in{'data'},
priority=>2,
sticky=>'False',
password=>'Growl_Password',
);

} ## END GOOD EVAL
else {
$err=$@;
print "Content-type: text/plain\n\nGrowl Error: $err";exit(0);
} ## END EVAL ERROR

} ## END IF DATA PRESENT

print "Content-type: text/plain\n\nthank you!";

and that is it. The same Growl message appears on my MacBook as well as on family big screen TV.There's no place like ~
coding / perlPrev .. Next
 
Post Reply
Home - Coding: AppleScript C Perl Shell Xcode Other
Our Telegram Group