Last active
May 3, 2017 09:13
-
-
Save stefb69/ca024db6108e89ff749e52fe3c7c4542 to your computer and use it in GitHub Desktop.
Mojolicious::Lite App to lookup contacts or leads phone number from Vtiger for Asterisk with FreePBX CIDLookup feature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojolicious::Lite; | |
use WebService::Vtiger; | |
app->config(hypnotoad => {listen => ['http://*:3002'], | |
pid_file => '/tmp/ypvtast.pid' }); | |
app->attr(vt => sub { | |
my $c = shift; | |
my $vt = WebService::Vtiger->new("http://yourhost/vtigercrm/webservice.php"); | |
return $vt; | |
}); | |
helper vts => sub { | |
my $c = shift; | |
my $username = 'webservice'; | |
my $pin = 'CHANGEME'; | |
my $session = $c->app->vt->getSession($username, $pin); | |
return $session; | |
}; | |
helper fetchnumber => sub { | |
my $c = shift; | |
my $cid = $c->param('cid'); | |
return "" if ($cid eq '' || !defined($cid)); | |
my $contact; | |
$contact = $c->app->vt->query( | |
$c->vts->{'sessionName'}, | |
"select firstname, lastname from Contacts where mobile = '". $cid . "' or phone = '" . $cid . "';" | |
); | |
unless (scalar(@{$contact})) { | |
$contact = $c->app->vt->query( | |
$c->vts->{'sessionName'}, | |
"select firstname, lastname from Leads where mobile = '". $cid . "' or phone = '" . $cid . "';" | |
); | |
} | |
return join ' ', ($contact->[0]->{firstname}, $contact->[0]->{lastname}); | |
}; | |
get '/' => sub { | |
my $c = shift; | |
$c->render(text => $c->fetchnumber); | |
}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then just add a CID Lookup source in Freepbx.
Params :
Source Type : HTTP
Host : well, your host running the mojolicious app
Port : 3002 (by default)
Path : /
Query : cid=[NUMBER]