📜 ⬆️ ⬇️

Calls within the organization from the Corporate Portal


Many organizations use a wealth of diverse information systems and technical solutions to secure and facilitate their work. Sooner or later the question of the integration of these systems and solutions arises, and often the choice of a “link” is adopted in favor of web technologies. At such a moment, before the web programmer there is a need to master all these hitherto unfamiliar products and solutions.


In this article I will describe the integration process:

on the example of creating a call system from the point of view of a web programmer.


First of all, of course, you should have:
  1. Customized phone system inside the organization
  2. Available to connect Asterisk and its web server
  3. Phone number information
  4. Corporate portal (however, only in this example. The solution can be used on any engine of similar functionality)

')
Basically, the solution of these issues goes beyond the competence of a specialist in web technologies, so suppose that we have everything we need and proceed directly to the server and client parts.

We will use the following elements:
  1. Separate MySQL table with logins and employee numbers. Data will be downloaded from AD and imported with minimal effort. In principle, it is possible to refer to the Portal users table, but firstly, it is not welcomed by the Beatrix developers, and secondly - in ours - as I think, in many others - an organization, a phone number can be not only personal, therefore the binding only to one user is irrational. In addition, we separately made a gadget for the Portal’s desktop, which allows you to instantly change your internal number in the call system, which allows the Coordination Center's specialists to easily make calls from their profile from any physical workplace.
    An example of an entry in the `phones` table:
    idusernumber
    238LutovVO50512

  2. PHP file directly passing parameters to an Asterisk server using the CURL library and processing return values
    call.php
    <? //       require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php"); $USER = new CUser; $userlogin = $USER->GetLogin(); //       $results = $DB->Query("SELECT `number` FROM `phones` WHERE `user`='".$userlogin."' LIMIT 1"); $userphone = $results->Fetch(); if (!empty($_POST['call'])) { //      $recipient = str_replace(' ', '', $_POST['recipient']); $recipient = str_replace('+', '', $recipient); $recipient = str_replace('-', '', $recipient); $recipient = str_replace('(', '', $recipient); $recipient = str_replace(')', '', $recipient); $answer = ''; // C   Asterisk $command = array(); $command[1] = 'action=login&username=PORTAL&secret=PASSWORD&events=off'; $command[2] = 'action=originate&channel=local/'.$userphone['number'].'@PORTAL&context=redirportal&exten='.$recipient.'&priority=1&CallerID=PORTAL'; $command[3] = 'action=logoff'; //      CURL $curl = curl_init(); foreach($command as $key => $data) { //    ,       $mansession = $_COOKIE['mansession_id']; $cookie = 'mansession_id="'.$mansession.'"'; //   - Asterisk curl_setopt($curl, CURLOPT_URL, 'http://127.0.0.1:8088/rawman'); //    curl_setopt($curl, CURLOPT_HEADER, 1); //    POST curl_setopt($curl, CURLOPT_POST, 1); //   cookie curl_setopt($curl, CURLOPT_COOKIE, $cookie); // CURL  ,      (    ) curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //   curl_setopt($curl, CURLOPT_POSTFIELDS, $data); $res = curl_exec($curl); //   ,       if(!$res) { $error = curl_error($curl).'('.curl_errno($curl).')'; echo $error; } //    ,   else { //          preg_match('/mansession_id="(.*)";/', $res, $cut); $_COOKIE['mansession_id'] = $cut[1]; //     $tech_answer .= '<h2> '.$key.': '.$data.'</h2>'.'<p><b>:</b></p>'.nl2br($res).'<br/><hr><br/>'; $answer = '<p style="color:green;"> </p>'; } } curl_close($curl); die('ok'); } else { die('not_ok'); } ?> 


  3. A JavaScript file that allows you to call using AJAX technology without reloading the page. 90% of it consists of creating the well-known XMLHTTPRequest object and its wrappers, so if you already use the implementation of this object from some js-library, everything may even be more compact
    script.js
     function createRequestObject() { if (typeof XMLHttpRequest === 'undefined') { XMLHttpRequest = function() { try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e) {} try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e) {} try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} throw new Error("This browser does not support XMLHttpRequest."); }; } return new XMLHttpRequest(); } function ajax_submit(params, path) { var req; req = createRequestObject(); req.open('POST', path, true); req.timeout=5000; req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); req.onreadystatechange = function() { if (req.readyState == 4) { if(req.status == 200) { // alert(" : "+req.responseText); if (req.responseText=='ok') { // alert('!'); } else { // alert(' !'); } } else { // alert(' '); } } } req.send(params); } function call_to (number) { var params = 'call=1&recipient='+number; var path = '/services/telephony/call/'; ajax_submit(params, path) } 


  4. Calling a function in the required templates or on the pages of Bitrix
     <span class="link" onclick="call_to('50512')"></span>  



In general, this is all that is needed.
The algorithm of actions of an employee who wants to call is as follows:
  1. Check on the Desktop of the Portal whether its number is registered in the network (for most, the number is already recorded, only new or relocating employees have to re-register, so this action needs to be performed, usually no more than once)
  2. Find a target number through a search, company structure or telephone directory
  3. Click on the number

After that, the phone on his desk starts to ring. It is necessary to pick up the phone, as will the connection to the target number.

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


All Articles