Skip to content

Instantly share code, notes, and snippets.

@stefb69
Last active May 3, 2017 09:13
Show Gist options
  • Save stefb69/ca024db6108e89ff749e52fe3c7c4542 to your computer and use it in GitHub Desktop.
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
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;
@stefb69
Copy link
Author

stefb69 commented May 3, 2017

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment