Mypbx and Vtiger CRM Integration Configuration Guide: Yeastar Information Technology Co. LTD
Mypbx and Vtiger CRM Integration Configuration Guide: Yeastar Information Technology Co. LTD
Mypbx and Vtiger CRM Integration Configuration Guide: Yeastar Information Technology Co. LTD
Configuration Guide
Version 1.0
Overview
Figure 1
2/11
Integration MyPBX and Vtiger CRM
Figure 2
1. Login as any user and go to Settings Icon , click on the My Preferences link
on the top right of the page. On this page you will find a block labeled Asterisk
Configuration.
2. Asterisk Extension: MyPBX extension, here take 705 for example.
3. Receive Incoming Calls: check the box, yes for enabling incoming calls.
3/11
Integration MyPBX and Vtiger CRM
Figure 3
Click to Call
Till now, we have finished all the configurations on Vtiger CRM, but it is not over yet.
There are steps we should do to make it work with MyPBX.
1. Edit the file AsteriskClass.php. Since we install Vtiger on Windows, so here we will
find the file in the path:
\Vtigercrm-5.4.0\apache\htdocs\VtigerCRM\modules\PBXManager\utils\
AsteriskClass.php
The file on Linux will be found in:
www/html/Vtigercrm/modules/PBXManager/utils/AsteriskClass.php
In order to find the correct context, we will change the context according to the
contexts in MyPBX. For example, context for extension 705 on MyPBX is
[DLPN_DialPlan705]. Therefore, we will firstly get the extension number using the
sentence “$extensionnumber = split('\/',$from);” Then change the context with”
$context= "DLPN_DialPlan".$extensionnumber[1];”
• Add the two sentences:
$extensionnumber = split('\/',$from);
$context= "DLPN_DialPlan".$extensionnumber[1];
• Comment the section “switch” to disable it.
• Modified section of the file:
$extensionnumber = split('\/',$from);
$context= "DLPN_DialPlan".$extensionnumber[1];
/*
switch($typeCalled){
case "SIP":
$context = " from-internal";
break;
case "PSTN":
$context =" ";//"outbound-dialing";
break;
default:
$context = " ";
}*/
4/11
Integration MyPBX and Vtiger CRM
Figure 4
Figure 5
• The extension you saved in User Preferences will start getting a call. In this guide,
705 will ring.
• Pick up the call (705), a call will be made to the number clicked in Vtiger CRM
(here is 702).
• Check the call log in PBX Manager.
Figure 6
5/11
Integration MyPBX and Vtiger CRM
Figure 7
For Linux System, you need use terminal to do the operation.
2. Make a call to the user extension to test. Here we will call from 702 to 705. Once
the call is set up, the users will get a pop-up notifying the caller name (if the
number is present in Vtiger CRM) and the number.
Figure 8
6/11
Integration MyPBX and Vtiger CRM
[Appendix]
if(!empty($mainresponse)) {
$state = ($version == "1.6")? "ChannelStateDesc" : "State";
return false;
}
if(
$mainresponse['Event'] == 'Newexten' && (strstr($appdata,
"__DIALED_NUMBER") || strstr($appdata, "EXTTOCALL"))
){
7/11
Integration MyPBX and Vtiger CRM
$uniqueid = $mainresponse['Uniqueid'];
$channel = $mainresponse['Channel'];
$splits = explode('/', $channel);
$callerType = $splits[0];
$parseSuccess = true;
} else if($mainresponse['Event'] == 'OriginateResponse'){
//if the event is OriginateResponse then its an outgoing call and set the flag to
1, so that AsteriskClient does not pick up as incoming call
$uniqueid = $mainresponse['Uniqueid'];
$adb->pquery("UPDATE vtiger_asteriskincomingevents set flag = 1 WHERE
uid = ?", array($uniqueid));
}else if($mainresponse['Event'] == 'Dial'&& $mainresponse['SubEvent'] ==
'Begin'){
$uniqueid = $mainresponse['UniqueID'];
$channel = $mainresponse['Channel'];
$splits = explode('/', $channel);
$callerType = $splits[0];
$extension = $mainresponse['Dialstring'];
$parseSuccess = true;
}
/* Add else if($mainresponse['Event'] == 'Dial'&& $mainresponse['SubEvent'] ==
'Begin'){ } */
$channel = $mainresponse['Channel'];
$splits = explode('/', $channel);
$callerType = $splits[0];
$extension = $mainresponse['CallerIDNum'];
$parseSuccess = true;
}
*/
if($parseSuccess) {
8/11
Integration MyPBX and Vtiger CRM
if(checkExtension($extension, $adb)) {
}
}
}
return false;
}
return true;
}
9/11
Integration MyPBX and Vtiger CRM
$response = $asterisk->getAsteriskResponse();
if(empty($response)){
return false;
}
$callerNumber = "Unknown";
$callerName = "Unknown";
if($version == "1.6"){
$state = "ChannelStateDesc";
}else{
$state = "State";
}
if(!empty($response['CallerID'])){
$callerNumber = $response['CallerID'];
}elseif(!empty($response['CallerIDNum'])){
$callerNumber = $response['CallerIDNum'];
}
if(!empty($response['CallerIDName'])){
$callerName = $response['CallerIDName'];
}
$unique_id = $response['Uniqueid'];
while(true){
$response = $asterisk->getAsteriskResponse();
if(($response['Event'] == 'Dial') && ($response['CallerIDNum'] ==
$callerNumber) && ($response['UniqueID'] == $unique_id)){
$dest_unique_id = $response['DestUniqueID'];
while (true) {
$response = $asterisk->getAsteriskResponse();
if (($response['Event'] == 'Newstate') &&
($response['ChannelStateDesc'] == 'Ringing') && ($response['Uniqueid'] ==
$dest_unique_id)) {
if(strstr($response['Channel'], $callerNumber)){
$temp = explode("/",$response['Channel']);
$callerType = $temp[0];
}
break;
}
}
break;
10/11
Integration MyPBX and Vtiger CRM
}
}
}else{
return false;
}
}
<The end>
11/11