如何在 FreePBX 中添加新的 CID Superfecta 源?

如何在 FreePBX 中添加新的 CID Superfecta 源?

我找不到有关如何添加新 CID Superfecta 的信息来源(我自己定制的编程的)在 FreePBX 中。文档没有说明,也没有在 FreePBX 管理界面中执行此操作的明显方法。我只找到了添加新方案(它们是来源的集合)。

我如何添加新来源?

我想要执行一个 HTTP GET,或者最好是POST,来查找呼叫者 ID。

使用 FreePBX 14.0.2.10。

答案1

使用 FreePBX 模块并添加它。

需要注意的是,我对 FreePBX Asterisk 的 CID Superfecta 进行了修改,以合并 ConnectWise ClientID 和 REST API。

您将需要请求访问 ConnectWise 开发者网络并创建一个私人 ClientID。

https://developer.connectwise.com/ClientID

修改的是位于 FreePBX 服务器上的 php 脚本,地址为 /var/www/html/admin/modules/superfecta/sources/source-ConnectWise.module

这将首先检查 CW 公司是否有电话号码匹配,并返回公司名称,然后,如果未找到,则检查 CW 联系人,并返回联系人的名字和姓氏。

将以下内容剪切并粘贴到 source-ConnectWise.module 中。注意换行符,本应为 1 行,粘贴为 2 行。

只要我仍能获得信用,请在 CW 论坛之外自由分享此内容。有一种方法可以让开发人员 ClientID 进行多次安装。


<?php

/***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** *****
 * Module Dev notes:
 *
 *
 * Revision History:
 *    v0.1.0: Initial Release Version by myitguy
 *    v0.1.1: Minor bug fix by bushbomb
 *    v0.1.2: More bug fixes id'd by bushbomb
 *    v0.1.3: Initial migration to 2.11 by lgaetz
 *    2014-08-22  Added user param to set the API version in the URL
 *    2015-05-01  Add field for user supplied CNAM prefix
 *    2018-06-30  Fix for bug FREEPBX-17727
 *    2020-01-06  Modified by Clinton Pownall of Computer Business to
 *                accommodate the ConnectWise REST API and the ConnectWise
 *                Required ClientID.
***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** *****/

class ConnectWise extends superfecta_base {

    public $description = "Look up data in local or remote ConnectWise CRM.";
    public $version_requirement = "2.11";
    public $source_param = array(
        'DB_Site' => array(
                'description' => 'ConnectWise Site URL not including the initial https://',
                'type' => 'text',
        ),
        'DB_Company' => array(
                'description' => 'ConnectWise Company ID',
                'type' => 'text',
        ),
        'DB_Public_Key' => array(
                'description' => 'Integration Public Key Created in ConnectWise: Members -> API Members -> API Keys',
                'type' => 'text',
        ),
        'DB_Private_Key' => array(
                'description' => 'Integration Private Key Created in ConnectWise: Members -> API Members -> API Keys',
                'type' => 'password',
        ),
        'DB_ClientID' => array(
                'description' => 'Client ID created using the ConnectWise Developer Site, See https:// developer.connectwise.com/ClientID',
                'type' => 'password',
        ),
        'Search_Type' => array(
                'description' => 'The ConnectWise type of entries that should be used to match the number',
                'type' => 'select',
                'option' => array (
                    '1' => 'Companies Only',
                    '2' => 'Contacts Only',
                    '3' => 'Companies --> Contacts',
                ),
                'default' => '3',
        ),
        'Filter_Length' => array(
                'description' => 'The number of rightmost digits to check for a match. Enter zero to disable this setting',
                'type' => 'number',
                'default' => 10
        ),
        'CNAM_prefix' => array(
                'description' => 'This text will be prefixed to all CNAM returned by this module (optional)',
                'type' => 'text',
                'default' => null
        ),
        'API_Version' => array(
                'description' => 'The part of the URL excluding slashes following the host name that indicates the API version, e.g. "v2014_4" or "v4_6_release" (without quotes)',
                'type' => 'text',
                'default' => 'v2014_4',
        ),
    );


    function get_caller_id($thenumber, $run_param=array()) {
        $caller_id = null;

                $site = $run_param['DB_Site'];
                $companyid = $run_param['DB_Company'];
                $APIPublicKey = $run_param['DB_Public_Key'];
                $APIPrivateKey = $run_param['DB_Private_Key'];
                $varSearchType = $run_param['Search_Type'];
        $clientid = $run_param['DB_ClientID'];

        $varSearchType = $run_param['Search_Type'];
        if ($run_param['API_Version']) {
            $apiver = $run_param['API_Version'];
        } else {
            $apiver = 'v4_6_release';
        }

        $wquery_string = "";
        $wquery_result = "";
        $wresult_caller_name = "";

        $this->DebugPrint("Searching ConnectWise ... ");

        if ($run_param['Filter_Length'] != 0) {
            if (strlen($thenumber) > $run_param['Filter_Length']) $thenumber = substr($thenumber, -$run_param['Filter_Length']);  // keep only the filter_length rightmost digits
        }

        $APIEndpoint = 'https://' .$site. '/'.$apiver.'/apis/3.0';

        $APIkey = 'Basic ' . base64_encode($companyid . '+' . $APIPublicKey . ':' . $APIPrivateKey);


        // Search Companies
        if($run_param['Search_Type'] == 1 || $run_param['Search_Type'] == 3)  {
            $this->DebugPrint("Searching Companies ... ");
            /* COMPANY */
            $conditions='conditions=phoneNumber%20like%20%22'.$thenumber.'%22%20';

            $url = '/company/companies?'.$conditions.'&fields=name&pageSize=1000';

            $url = $APIEndpoint . $url;

            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_HTTPHEADER, array('clientId:' . $clientid,'Authorization:'. $APIkey,    'Content-Type: application/json',));
               curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
               curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
               curl_setopt($curl, CURLINFO_HEADER_OUT, true);

            $result = curl_exec($curl);

            if(!$result){die("Connection Failure");}
            curl_close($curl);

            $name=preg_split('/"*"/i', $result, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);

            if (!empty($name[3])) {
                $wresult_caller_name = $name[3];
            }
            else
            {
                $this->DebugPrint("Not found in Companies... ");
            }
        }

        // Search Contacts
        if($run_param['Search_Type'] == 2 || $run_param['Search_Type'] == 3 && $wresult_caller_name =="")  {
            $this->DebugPrint("Searching Contacts ... ");
            /* CONTACT */
            $conditions='childconditions=communicationItems/value%20like%20%22'.$thenumber.'%22%20AND%20communicationItems/communicationType="Phone"';

            $url = '/company/contacts?'.$conditions.'&fields=&pageSize=1000';

            $url = $APIEndpoint . $url;

            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_HTTPHEADER, array('clientId:' . $clientid,'Authorization:'. $APIkey,    'Content-Type: application/json',));
             curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
            curl_setopt($curl, CURLINFO_HEADER_OUT, true);
            $result = curl_exec($curl);

            if(!$result){die("Connection Failure");}
            curl_close($curl);

            $name=preg_split('/"*"/i', $result, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);;

            if (!empty($name[9])) {
                 $wresult_caller_name = $name[5]." ".$name[9]; }

            }
            if ($wresult_caller_name =="")  {
                $this->DebugPrint("Not found in Contacts... ");
            }


            if(strlen($wresult_caller_name) > 0) {
                $caller_id = $run_param['CNAM_prefix'].trim(strip_tags($wresult_caller_name));
                return $run_param['CNAM_prefix'].$caller_id;
            }
            else {
                $this->DebugPrint("Not found in ConneceWise");
            }
    }
}

?>

相关内容