vtiger and incoming call popup

Discussion in 'General' started by janwillem, Nov 10, 2010.

  1. janwillem

    Joined:
    Nov 10, 2010
    Messages:
    2
    Likes Received:
    0
    Dear All,

    I've been googling all over the net to find information on registering incoming calls in vtigercrm. It seems that only the first call generates a popup and that's it.

    It seems to me nobody has this working.

    The module that one needs to be running is

    AsteriskClient.php

    Basically what this module does is using the asterisk API to monitor what's happening. And a lot is happening, so I believe that's where the problem originates. If this PHP script has to filter through all the data it receives the status of an incoming I can imagine it stops working. You will see what I mean if you run this script in a terminal window.

    Now going back in history I found that earlier approaches to make register incoming calls was through an agi script. This makes much more sense to me, because instead of running a script that monitors and may or may not see an incoming call, you only trigger the agi script if indeed a call comes in.

    I found information about this approach at:

    http://forums.vtiger.com/viewtopic.php?t=14314

    But to me implementing this is a bit too drastic, as they handle incoming and outgoing calls, while the outgoing already works fine.

    The agi part is quite a simple perl script:

    use LWP::Simple;
    use Asterisk::AGI;
    $AGI = new Asterisk::AGI;
    my %input = $AGI->ReadParse(); #Read in the initial data
    my $id = $input{"callerid"};
    my $ex = $input{"extension"};
    $id =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
    $ex =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
    my $url = 'http://localhost/vtigercrm/asterisk/call_ident.php?callerid=' . $id . '&extension=' . $ex;
    use LWP::Simple;
    my $content = get $url
    ;



    now as you can see it calls a php script with the callerid and the extension and that script seems to do the rest.

    Well I didn't get any deeper into this solution as it is quite drastic in changing your vtiger setup (including doing some patches), which I don't want as all works fine, execpt for the incoming calls.

    So why can't we use the agi approach (with the above script as an example) and do what AsteriskClient.php does?

    If we look at the logic of AsteriskClient.php:

    open api socket
    while (true){
    if incoming call {
    if extension is known in vtiger{
    inserts the values into the vtiger_asteriskincomingcalls table
    }
    }
    }


    So IMHO we could have a simple agi script that inserts callerid and extension in the vtiger_asteriskincoming calls table and we would have working incoming call popups.

    Or am I overlooking something?

    Any input much appreciated,

    regards,

    Jan Willem Smeenk
     
  2. mm.alpha2k

    Joined:
    Jun 19, 2010
    Messages:
    165
    Likes Received:
    0
    Good morning, I use the outcall (http://outcall.sourceforge.net/) through the manager.
    If not the best solution. In the FreePBX do you connect to a database, where I get the cidname

    Saludos
     
  3. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    This works in 5.1 and Elastix 1.6
    Stick a call to it in /etc/rc.d/rc.local

    I have put this project in abeyance as 5.2 is now available but PaloSanto are not interested in packaging it, it needs a few changes for 5.2


    Code:
    #!/usr/bin/php
    <?php
    /***********************************************************************************
     * The contents of this file are subject to the vtiger CRM Public License Version 1.0
     * ("License"); You may not use this file except in compliance with the License
     * The Original Code is:  vtiger CRM Open Source
     * The Initial Developer of the Original Code is vtiger.
     * Portions created by vtiger are Copyright (C) vtiger.
     * All Rights Reserved.
     * Some Code added by dicko for the Elastix Project
     ************************************************************************************/
    
    /**
     * this file will be run as a shell script (in linux) or a batch file (under windows).
     * the purpose of the file is to create a master socket which will be connecting to the asterisk server
     * and to keep it (the socket) alive all the time. 
     */
    
    ini_set("include_path", "/var/www/html/vtigercrm/");
    #"../../../");
    require_once('modules/PBXManager/utils/AsteriskClass.php');
    require_once('config.php');
    require_once('include/utils/utils.php');
    require_once('include/language/en_us.lang.php');
    require_once('modules/PBXManager/AsteriskUtils.php');
    
    
    
    
    asteriskClient();
    
    /**
     * this function defines the asterisk client
     */
    //echo "hello";
    
    function asteriskClient(){
    	global $app_strings, $current_user;
    	global $adb, $log;
    	
    	$data = getAsteriskInfo($adb);
    	$server = $data['server'];
    	$port = $data['port'];
    	$username = $data['username'];
    	$password = $data['password'];
    	$version = $data['version'];
    
    	$errno = $errstr = NULL;
    	$sock = @fsockopen($server, $port, $errno, $errstr, 1);
    	stream_set_blocking($sock, true);
    	if( $sock === false ) {
    		echo "Socket cannot be created due to error: $errno:  $errstr\n";
    		$log->debug("Socket cannot be created due to error:   $errno:  $errstr\n");
    		exit(0);
    	}else{
    		echo "Date: ".date("d-m-Y")."\n";
    		echo "Connecting to asterisk server.....\n";
    		$log->debug("Connecting to asterisk server.....\n");
    	}
    	echo "Connected successfully\n\n\n";
    	$asterisk = new Asterisk($sock, $server, $port);
    
    	authorizeUser($username, $password, $asterisk);
    		
    	//keep looping continuosly to check if there are any calls
    	while (true) {
    		//check for incoming calls and insert in the database
    		$incoming = handleIncomingCalls($asterisk, $adb, $version);
    	}
    	fclose($sock);
    	unset($sock);
    }
    
    /**
     * this function checks if there are any incoming calls for the current user
     * if any call is found, it just inserts the values into the vtiger_asteriskincomingcalls table
     * 
     * @param $asterisk - the asterisk object
     * @param $adb - the peardatabase type object
     * @return	incoming call information if successful
     * 			false if unsuccessful
     */
    function handleIncomingCalls($asterisk, $adb, $version="1.4"){
    
    	$response = $asterisk->getAsteriskResponse();
    	if(empty($response)){
    		return false;
    	}
    
    	if($version == "1.6"){
    		$state = "ChannelStateDesc";
    	}else{
    		$state = "State";
    	}
    
    	if($response['Event'] == 'Dial'){
    	print date('m/d/Y H:i:s')." - Event: ".$response['Event']. " | ";
    //	Print_r($response);
    	$dest = explode("/",$response['Destination']);
    	$ext = explode("-",$dest[1]);
    
    	$extension=$ext[0];
    	$callerType=$dest[0];
    $callerType="";
    	$callerNumber=$response['CallerID'];
    	$callerName=$response['CallerIDName'];
    
    print "To: ".$extension." From: ".$callerName." <".$callerNumber.">\n";
    
    		if(checkExtension($extension, $adb)){
    
    	print date('m/d/Y H:i:s')." - AddToMysqld | To: ".$extension." From: ".$callerName." <".$callerNumber.">\n";
    
    		//insert into database
    			$sql = "insert into vtiger_asteriskincomingcalls values (?,?,?,?,?,?)";
    	        	$flag= 0;
    	        	$timer = time();
    	        	$params = array($callerNumber, $callerName, $extension, $callerType,$flag,$timer);
    	        	$adb->pquery($sql, $params);
    	        	addToCallHistory($extension, $callerType.":".$callerNumber, $extension, "incoming", $adb);
    			// break;  //break the while loop
    		}
    
    	return true;
    	}
    	else
    	{
    print date('m/d/Y H:i:s')." - Event: ".$response['Event']."                               \r";
    	return false;
    	}
    	
    }
    
    
    /**
     * this function takes a XML response and converts it to an array format
     * @param string $response - the xml response
     * @return the xml formatted into an array
     */
    function getArray($xml){
    	$lines = explode("\r\n", $xml);
    
    	$response = array();
    	foreach($lines as $line){
    		list($key, $value) = explode(":", $line);
    		$response[$key] = $value;
    	}
    	return $response;	
    }
    
    /**
     * this function checks if the given extension is a valid vtiger extension or not
     * if yes it returns true
     * if not it returns false
     * 
     * @param string $ext - the extension to be checked
     * @param object $adb - the peardatabase object
     */
    function checkExtension($ext, $adb){
    	$sql = "select * from vtiger_asteriskextensions where asterisk_extension='$ext'";
    	$result = $adb->pquery($sql, array());
    	
    	if($adb->num_rows($result)>0){
    		
    		return true;
    	}else{
    		return false;
    	}
    }
    ?>
    
    Make sure the vTiger manager in manager.conf has sufficient permissions (all works ;)
     
  4. gardo

    Joined:
    Nov 10, 2010
    Messages:
    3
    Likes Received:
    0
    I've been trying to find a stable working solution for the incoming call pop-ups but no luck yet. Running the modified script above gives me:

    The pop-up will appear when calling the phone extension associated with the Vtiger user. However, hanging up the call will crash the script. Tried also calling the queue where the phone extension is a member crashes the script too with the same message above.

    Running the following on Elastix 2.0:

    Asterisk 1.6
    VtigerCRM 5.10

    Let me know what else I can do to help debug the problem.
     
  5. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    The script will ONLY run on asterisk 1.4 and vtiger 5.1

    start it on bootup in /etc/rc.d/rc.local

    something like
    Code:
    while [ ! -f /var/run/mysqld/mysqld.pid ];do sleep 1;done&&/var/lib/asterisk/bin/ElastixFreePBXAsteriskClient.php >> /var/log/vtiger
    
    to make sure mysqld is running first

    you can monitor the events later with

    tail -f /var/log/vtiger
    You will notice I moved it into /var/lib/asterisk/bin, it's now a blocking socket connection and should only be called once.

    un-comment the

    // Print_r($response);

    line and restart the script for more verbosity



    the manager I use is


    [vtiger]
    secret = vtigersecretpassword
    deny=0.0.0.0/0.0.0.0
    permit=127.0.0.1/255.255.255.0
    permit=20.30.40.5/255.255.255.255
    displayconnects = yes
    read=all
    write=all,originate


    I really believe a busy vtiger host does not belong on the same box as your VOIP server
    here of course it is a separate machiono 20.30.40.50

    Maybe I'll add the proper events to watch for in Asterisk 1.6 later. The Dial event appears impeccable in Asterisk 1.4 and seems usable in 1.6 but I as yet don't have an Elastix 2.0.<someridicoulousnuber> server in production for testing.


    There are some more hacks I posted a while back in the bug-tracker. Perhaps they are more complete.
     
  6. gardo

    Joined:
    Nov 10, 2010
    Messages:
    3
    Likes Received:
    0
    I had no choice but to use Elastix 1.6. Incoming calls pop-up works great. A lot more stable than using Asterisk 1.6 with VtigerCRM 5.1.
     
  7. gardo

    Joined:
    Nov 10, 2010
    Messages:
    3
    Likes Received:
    0
    Hey Dicko,

    How's everything going. I need your help. I have a client who wants this integration (Asterisk and Vtiger). I don't have the time to sort things out on the issues they're encountering. I was hoping I can pass them on to your expertise and give them professional support. Please get in touch with me demian @ goautodial.com.
     
  8. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    I'm sorry, I won't do that.

    There is a paid support link to PaloSanto below though.
     
  9. Amphibian

    Joined:
    Sep 8, 2009
    Messages:
    1,128
    Likes Received:
    2
    Good evening fine people.

    I have wanted for some time to check out the CRM software provided with Elastix ("E") such as VtigerCRM and SugarCRM and after a year of running E I am finally getting to it. Up to present I have been using my own written CRM/Database sitting on another machine that I have to manually enter the info each time a call comes in so I don' have any real knowledge of either of these two programs or for that matter any CRM packages available out there for use.

    So I am looking at this point for either opinions or recommendation to the following in hopes of determining what is the better way to go. I have read both web sites, they seem very comparable ( in other words, they each seem to offer the same and some different capabilities) in what they do. I admit I'm lazy and don't want to install and learn both so here it goes. I am leaning towards Vtiger at this point but thought I would ask anyways.

    I posted a request (within the last few weeks) under Call Center for some programming desires on what my needs are. I received an e-mail shortly after that from a friend (yes I have one or two) stating that Vtiger & Sugar provide this function I am looking for. In my search I see that Vtiger offers a pop-up but didn't notice the same for Sugar.

    1: So great people, how many use SugarCRM and/or how many are using VtigerCRM and why would I want to go with one or the other. I'm interested in the pros and cons of both. I have done a search on the goog thing but haven't found any real comparisons, good or bad.

    2: Am interested in seeing how many people have gotten the pop-up to work, how involved it is in coding the web page that pops up and maybe if someone would share their web page coding so I can actually see what and how it works even if I have to pay for it.

    3: Is either one of these programs still in their infancy and/or am I wasting my time on the pop-up issue? It appears that both have been around for a while. I just don't find any documentation on how to setup the pop-up portion on either of these two programs (This may need to be a question for the respective software on their respective sites, but that's why I'm trying to see if anyone here has it working...).

    I know it's been said many times by many others, but I have obtained some great info on this site with respect to users of E and figured that I would go directly to the horses mouth and get opinions from actual E & CRM users.

    Thanks in advance.

    Amphibian
     
  10. janwillem

    Joined:
    Nov 10, 2010
    Messages:
    2
    Likes Received:
    0
    Hello Amphibian,

    If you want telephone/crm integration Vtiger is the product of choice.
    SugarCRM only has Skype integration for calling out and no interface for incoming calls.

    There are a few plugins for Sugar that may offer Asterisk integration but are all tied to different (older) versions of Sugar, while vTiger has all of this functionality built in.

    In version 5.2 the popups for incoming calls work very well once you have fixed two small bugs.

    1. You have to manually enter the asterisk version number (1.6) in the MYSQL table vtiger_asterisk (the pulldown in Settings-> Module Manager ->PBX Manager from which you should be able to select the Asterisk version doesn't work).

    2. In the table vtiger_asteriskincomingevents you have to change the field type of from_number from bigint to varchar.


    Once you have fixed those you have to make sure the AsteriskClient.php script runs on startup of your machine and your popups work like a charm.

    All the best,

    Jan Willem
     
  11. Amphibian

    Joined:
    Sep 8, 2009
    Messages:
    1,128
    Likes Received:
    2
    Thanks Jan,

    I was leaning to Vtiger and I think this just made the choice for me. I felt Vtiger had more to offer as standard and that was why I leaned that direction.

    I'm not sure as to if I really understand the second half (the modify thingee) of what you are talking about and not sure I know how to do that. This may be half due to the fact that I have been going without sleep (working) for the last 38 hours and the other half due to my mental handicap I have (being a dumb ass). So I'm fixing to hit the sack here in a few more hours and will re-read this again later.

    Thanks though for responding and feeding me the knowledge.

    Have a great day
    Amphibian
     
  12. innova-pty

    Joined:
    Sep 26, 2010
    Messages:
    12
    Likes Received:
    0
    Re: Re:vtiger and incoming call popup

    Hello,
    I have updated to vtiger 5.2, I have done what you suggest and incoming popups still not working.
    I see the AsteriskClient.php freezed when it gets an incoming call, then goes back again.
    Any other ideas ?
    Thank you.
     
  13. intouchcsi

    Joined:
    Nov 18, 2010
    Messages:
    5
    Likes Received:
    0
    I'm new to all of this, and I'm not really a tech guy, although I played one in a past life.

    Where do I find the "vtiger_asteriskincomingevents" file?


    Thank you!
     
  14. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    vtiger_asteriskincomingevents

    is not a file, it is a table in the vtiger mysql database schema.
     
  15. intouchcsi

    Joined:
    Nov 18, 2010
    Messages:
    5
    Likes Received:
    0
    I don't suppose you can tell me where to find it?

    Directory path would be helpful.
     
  16. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    By default all mysql data can be found in

    /var/lib/mysql/

    vtigercrm510 is the directory of the vtiger database, you will need to use mysql or some-such mysql client to manage the data though, if you just want to browse a textual version

    mysqldump -u vtigercrm -p vtiger2007 vtigercrm510 > vtigerdumptest.sql

    actually the table is

    vtiger_asteriskincomingcalls, the Events are used to parsethe AMI socket to decide what is a call.
     
  17. darkT

    Joined:
    Jan 20, 2011
    Messages:
    4
    Likes Received:
    0
    thanks!! works perfectly!!
     
  18. kosacrta

    Joined:
    Feb 4, 2011
    Messages:
    2
    Likes Received:
    0
    Hi darkT,

    I am trying to make it work witj elastix 2.0.3 & vtiger 5.2....
    can you post your AsteriskClient.php?

    I changed in database from biginit to varchar and can select asterisk version in pbxmanager but incoming popup does not show, it records the incoming call in pbxmanager but no popup...

    enlight me please...
    Vlidimir
     
  19. darkT

    Joined:
    Jan 20, 2011
    Messages:
    4
    Likes Received:
    0
  20. innova-pty

    Joined:
    Sep 26, 2010
    Messages:
    12
    Likes Received:
    0
    Hi darkT, what Asterisk version are you running ?
     

Share This Page