📜 ⬆️ ⬇️

“Correct” call to softphones from AMOCRM (call2click)

Greetings community!
Who was engaged in asterisk and amocrm integration, he knows that it is possible to initiate a call from AMO only by origination. Origination is when the server first makes a call to your internal number, and when you pick up the phone, a second call is made to the desired client number. Sometimes such a decision for various reasons does not suit customers or me.

Attempts to persuade AMO technical support to embed the possibility of placing links of the form “sip:” or “tel:” instead of calling the amocrm.php script with origination failed. Then this “crutch” was born. Perhaps it will be useful to someone.

So, we are in the customer card, click on the number, select “AsteriskNow” in the drop-down list. The browser makes a call to the amocrm.php script on your server with action = call.

Open and rule:
')
}elseif ($action==='call'){ // originate a call /*$params=array( 'action'=>'Originate', 'channel'=>'SIP/'.intval($_GET['from']), 'Exten'=>strval($_GET['to']), 'Context'=>'from-internal', 'priority'=>'2', 'Callerid'=>'"'.strval($_GET['as']).'" <'.intval($_GET['from']).'>', 'Async'=>'Yes', // Not Implemented: //'Callernumber'=>'150', //'CallerIDName'=>'155', ); $resp=asterisk_req($params,true); if ($resp[0]['response']!=='Success') answer(array('status'=>'error','data'=>$resp[0])); answer(array('status'=>'ok','action'=>$action,'data'=>$resp[0])); */ //custom /*CREATE TABLE IF NOT EXISTS `callout` ( `from` varchar(4) NOT NULL, `to` varchar(12) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1;*/ //mysql mysql_connect("localhost","asteriskuser","asteriskuserpssword") or die("no connect to MySQL."); mysql_select_db("asteriskcdrdb") or die("ERROR: ".mysql_error()); mysql_query('INSERT INTO `callout` (`from`,`to`) VALUES ("'.$_GET['from'].'","'.$_GET['to'].'")') or die("ERROR: ".mysql_error()); answer(array('status'=>'ok','action'=>$action,'data'=>'')); //end custom 

We commented out what was happening by default (origin) and added our own code, starting with // custom, which throws data into the “callout” table in asteriskcdrdb who is calling. Now, by clicking on "AsteriskNow" we have an entry in the table.

Next, next to amorcm.php, we put our gn.php file, which will return the number to call on request:

 <?php //mysql if(!isset($_GET['iid']) || empty($_GET['iid'])) die('NO PARAMS'); mysql_connect("localhost","asteriskuser","asteriskuserpassword") or die("no connect to MySQL."); mysql_select_db("asteriskcdrdb") or die("ERROR: ".mysql_error()); $data = mysql_fetch_array(mysql_query('SELECT * FROM `callout` WHERE `from` = "'.$_GET['iid'].'" LIMIT 1'), MYSQL_ASSOC); mysql_query('DELETE FROM `callout` WHERE `from` = "'.$_GET['iid'].'"') or die("ERROR: ".mysql_error()); print $data['to']; ?> 

Now, if we request this file with the parameter iid = internal_number (for example, 100), then the response script will return the first number scored into the database through the menu in the AMO, and clean up the rest.

The last stage is a survey of this script and transfer to the softphone number that you need to dial. For this autoIT is well suited:

 $phone = 100 $oHTTPError = ObjEvent("AutoIt.Error","oHTTPErrFunc") Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", "https://ip-or-url-of-your-asterisk-server/gn.php?iid="&$phone, False) While 1 $oHTTP.Send() If $oHTTP.Status == 200 And $oHTTP.ResponseText() <> "" Then ShellExecute("sip:"&$oHTTP.ResponseText()) EndIf Sleep(1000) WEnd Func oHTTPErrFunc() $_eventerror = 1 Endfunc 

We put this text in script.txt next to AutoIT.exe and make a shortcut to the latter, in which we write “script.txt” as the first parameter. Next, the shortcut can be thrown into autoload.

I recommend that you also take care of the security issue - screw the token, or check for ip, or close the file with a password via htaccess / htpasswd and substitute it in the url when calling from autoIt.

We check that the sip: set up for processing links is automatically launched and starts to call the specified number. In my case, it was PhonerLite.

Thanks for attention!

Source: https://habr.com/ru/post/359298/


All Articles