Ejemplo n.º 1
0
 public static function RegisterCall($config, $params)
 {
     Bitrix\Voximplant\CallTable::add(array('CONFIG_ID' => $config['ID'], 'CALL_ID' => $params['CALL_ID'], 'USER_ID' => 0, 'CALLER_ID' => $params['CALLER_ID'], 'STATUS' => Bitrix\Voximplant\CallTable::STATUS_CONNECTING, 'CRM' => $config['CRM'], 'ACCESS_URL' => $params['ACCESS_URL'], 'DATE_CREATE' => new Bitrix\Main\Type\DateTime()));
     if ($config['WORKTIME_SKIP_CALL'] == 'Y') {
         $config['WORKTIME_USER_ID'] = 0;
         if ($config['CRM'] == 'Y') {
             $existsLead = false;
             $crmData = CVoxImplantCrmHelper::GetDataForPopup($params['CALL_ID'], $params['CALLER_ID']);
             if (isset($crmData['RESPONSIBILITY']['ID']) && $crmData['RESPONSIBILITY']['ID'] > 0) {
                 $config['WORKTIME_USER_ID'] = $crmData['RESPONSIBILITY']['ID'];
                 $existsLead = true;
             } else {
                 $res = VI\QueueTable::getList(array('select' => array('ID', 'USER_ID'), 'filter' => array('=CONFIG_ID' => $config['ID']), 'order' => array('LAST_ACTIVITY_DATE' => 'asc'), 'limit' => 1));
                 $queueUser = $res->fetch();
                 if ($queueUser) {
                     VI\QueueTable::update($queueUser['ID'], array('LAST_ACTIVITY_DATE' => new FieldType\DateTime()));
                     $config['WORKTIME_USER_ID'] = $queueUser["USER_ID"];
                 }
                 if ($config['WORKTIME_USER_ID'] > 0 && $crmData['FOUND'] == 'N' && $config['CRM_CREATE'] == CVoxImplantConfig::CRM_CREATE_LEAD) {
                     $id = CVoxImplantCrmHelper::AddLead(array('USER_ID' => $config['WORKTIME_USER_ID'], 'PHONE_NUMBER' => $params['CALLER_ID'], 'SEARCH_ID' => $params['SEARCH_ID'], 'CRM_SOURCE' => $config['CRM_SOURCE'], 'INCOMING' => true));
                     if ($id) {
                         $existsLead = true;
                     }
                 }
             }
             if ($existsLead) {
                 CVoxImplantCrmHelper::AddCall(array('CALL_ID' => $params['CALL_ID'], 'PHONE_NUMBER' => $params['CALLER_ID'], 'INCOMING' => CVoxImplantMain::CALL_INCOMING, 'USER_ID' => $config['WORKTIME_USER_ID'], 'DATE_CREATE' => new FieldType\DateTime()));
                 CVoxImplantCrmHelper::UpdateCall(array('CALL_ID' => $params['CALL_ID'], 'PHONE_NUMBER' => $params['CALLER_ID'], 'INCOMING' => CVoxImplantMain::CALL_INCOMING, 'USER_ID' => $config['WORKTIME_USER_ID'], 'DESCRIPTION' => GetMessage("WORKTIME_CALL")));
             }
         } else {
             $res = VI\QueueTable::getList(array('select' => array('ID', 'USER_ID'), 'filter' => array('=CONFIG_ID' => $config['ID']), 'order' => array('LAST_ACTIVITY_DATE' => 'asc'), 'limit' => 1));
             $queueUser = $res->fetch();
             if ($queueUser) {
                 $config['WORKTIME_USER_ID'] = $queueUser["USER_ID"];
             }
         }
     }
     return $config;
 }
Ejemplo n.º 2
0
 public static function Add($params)
 {
     if (strlen($params["CALL_ID"]) > 0) {
         $res = VI\CallTable::getList(array('select' => array('ID', 'DATE_CREATE', 'CRM', 'CONFIG_ID', 'USER_ID', 'TRANSFER_USER_ID'), 'filter' => array('=CALL_ID' => $params["CALL_ID"])));
         if ($call = $res->fetch()) {
             VI\CallTable::delete($call['ID']);
         }
     }
     $arFields = array("ACCOUNT_ID" => $params["ACCOUNT_ID"], "APPLICATION_ID" => $params["APPLICATION_ID"], "APPLICATION_NAME" => $params["APPLICATION_NAME"], "INCOMING" => $params["INCOMING"], "CALL_START_DATE" => $call ? $call['DATE_CREATE'] : new Bitrix\Main\Type\DateTime(), "CALL_DURATION" => $params["CALL_DURATION"], "CALL_STATUS" => $params["CALL_STATUS"], "CALL_FAILED_CODE" => $params["CALL_FAILED_CODE"], "CALL_FAILED_REASON" => $params["CALL_FAILED_REASON"], "COST" => $params["COST_FINAL"], "COST_CURRENCY" => $params["COST_CURRENCY"], "CALL_VOTE" => intval($params["CALL_VOTE"]), "CALL_ID" => $params["CALL_ID"], "CALL_CATEGORY" => $params["CALL_CATEGORY"]);
     if (intval($params["PORTAL_USER_ID"]) > 0) {
         $arFields["PORTAL_USER_ID"] = intval($params["PORTAL_USER_ID"]);
     }
     if (strlen($params["PHONE_NUMBER"]) > 0) {
         $arFields["PHONE_NUMBER"] = $params["PHONE_NUMBER"];
     }
     if (strlen($params["CALL_DIRECTION"]) > 0) {
         $arFields["CALL_DIRECTION"] = $params["CALL_DIRECTION"];
     }
     if (strlen($params["PORTAL_NUMBER"]) > 0) {
         $arFields["PORTAL_NUMBER"] = $params["PORTAL_NUMBER"];
     }
     if (strlen($params["ACCOUNT_SEARCH_ID"]) > 0) {
         $arFields["PORTAL_NUMBER"] = $params["ACCOUNT_SEARCH_ID"];
     }
     if (strlen($params["CALL_LOG"]) > 0) {
         $arFields["CALL_LOG"] = $params["CALL_LOG"];
     }
     $orm = Bitrix\VoxImplant\StatisticTable::add($arFields);
     if (!$orm) {
         return false;
     }
     if ($call && intval($arFields["PORTAL_USER_ID"]) <= 0) {
         $res = VI\QueueTable::getList(array('select' => array('ID', 'USER_ID'), 'order' => array('LAST_ACTIVITY_DATE' => 'asc'), 'filter' => array('=CONFIG_ID' => $call['CONFIG_ID']), 'limit' => 1));
         $queueUser = $res->fetch();
         if ($queueUser) {
             $arFields["PORTAL_USER_ID"] = $queueUser['USER_ID'];
         }
     }
     if (strlen($arFields["PHONE_NUMBER"]) > 0 && $arFields["PORTAL_USER_ID"] > 0 && $params["CALL_FAILED_CODE"] != 423) {
         $plusSymbol = strlen($arFields["PHONE_NUMBER"]) >= 10 ? '+' : '';
         if ($arFields["INCOMING"] == CVoxImplantMain::CALL_OUTGOING) {
             if ($arFields['CALL_FAILED_CODE'] == '603-S') {
                 $message = GetMessage('VI_OUT_CALL_DECLINE_SELF', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
             } else {
                 if ($arFields['CALL_FAILED_CODE'] == 603) {
                     $message = GetMessage('VI_OUT_CALL_DECLINE', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
                 } else {
                     if ($arFields['CALL_FAILED_CODE'] == 486) {
                         $message = GetMessage('VI_OUT_CALL_BUSY', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
                     } else {
                         if ($arFields['CALL_FAILED_CODE'] == 480) {
                             $message = GetMessage('VI_OUT_CALL_UNAVAILABLE', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
                         } else {
                             if ($arFields['CALL_FAILED_CODE'] == 404 || $arFields['CALL_FAILED_CODE'] == 484) {
                                 $message = GetMessage('VI_OUT_CALL_ERROR_NUMBER', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
                             } else {
                                 if ($arFields['CALL_FAILED_CODE'] == 402) {
                                     $message = GetMessage('VI_OUT_CALL_NO_MONEY', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
                                 } else {
                                     $message = GetMessage('VI_OUT_CALL_END', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"], '#INFO#' => '[PCH=' . $orm->getId() . ']' . GetMessage('VI_CALL_INFO') . '[/PCH]'));
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if ($arFields['CALL_FAILED_CODE'] == 304) {
                 if (strlen($params['URL']) > 0) {
                     $subMessage = GetMessage('VI_CALL_VOICEMAIL', array('#LINK_START#' => '[PCH=' . $orm->getId() . ']', '#LINK_END#' => '[/PCH]'));
                 } else {
                     $subMessage = '[PCH=' . $orm->getId() . ']' . GetMessage('VI_CALL_INFO') . '[/PCH]';
                 }
                 $message = GetMessage('VI_IN_CALL_SKIP', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"], '#INFO#' => $subMessage));
             } else {
                 $message = GetMessage('VI_IN_CALL_END', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"], '#INFO#' => '[PCH=' . $orm->getId() . ']' . GetMessage('VI_CALL_INFO') . '[/PCH]'));
             }
         }
         self::SendMessageToChat($arFields["PORTAL_USER_ID"], $arFields["PHONE_NUMBER"], $arFields["INCOMING"], $message);
     }
     if ($call['CRM'] == 'Y') {
         CVoxImplantCrmHelper::UpdateCall($arFields);
     }
     if (strlen($params['URL']) > 0) {
         $attachToCrm = $call['CRM'] == 'Y';
         $startDownloadAgent = false;
         $recordLimit = COption::GetOptionInt("voximplant", "record_limit");
         if ($recordLimit > 0 && !CVoxImplantAccount::IsPro()) {
             $sipConnectorActive = CVoxImplantConfig::GetModeStatus(CVoxImplantConfig::MODE_SIP);
             if ($params['PORTAL_TYPE'] == CVoxImplantConfig::MODE_SIP && $sipConnectorActive) {
                 $startDownloadAgent = true;
             } else {
                 $recordMonth = COption::GetOptionInt("voximplant", "record_month");
                 if (!$recordMonth) {
                     $recordMonth = date('Ym');
                     COption::SetOptionInt("voximplant", "record_month", $recordMonth);
                 }
                 $recordCount = CGlobalCounter::GetValue('vi_records', CGlobalCounter::ALL_SITES);
                 if ($recordCount < $recordLimit) {
                     CGlobalCounter::Increment('vi_records', CGlobalCounter::ALL_SITES, false);
                     $startDownloadAgent = true;
                 } else {
                     if ($recordMonth < date('Ym')) {
                         COption::SetOptionInt("voximplant", "record_month", date('Ym'));
                         CGlobalCounter::Set('vi_records', 1, CGlobalCounter::ALL_SITES, false);
                         CGlobalCounter::Set('vi_records_skipped', 0, CGlobalCounter::ALL_SITES, false);
                         $startDownloadAgent = true;
                     } else {
                         CGlobalCounter::Increment('vi_records_skipped', CGlobalCounter::ALL_SITES, false);
                     }
                 }
                 CVoxImplantHistory::WriteToLog(array('limit' => $recordLimit, 'saved' => CGlobalCounter::GetValue('vi_records', CGlobalCounter::ALL_SITES), 'skipped' => CGlobalCounter::GetValue('vi_records_skipped', CGlobalCounter::ALL_SITES), 'save to portal' => $startDownloadAgent ? 'Y' : 'N'), 'STATUS OF RECORD LIMIT');
             }
         } else {
             $startDownloadAgent = true;
         }
         if ($startDownloadAgent) {
             self::DownloadAgent($orm->getId(), $params['URL'], $attachToCrm);
         }
     }
     if (strlen($params["ACCOUNT_PAYED"]) > 0 && in_array($params["ACCOUNT_PAYED"], array('Y', 'N'))) {
         CVoxImplantAccount::SetPayedFlag($params["ACCOUNT_PAYED"]);
     }
     foreach (GetModuleEvents("voximplant", "onCallEnd", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array(array('CALL_ID' => $arFields['CALL_ID'], 'CALL_TYPE' => $arFields['INCOMING'], 'PHONE_NUMBER' => $arFields['PHONE_NUMBER'], 'PORTAL_NUMBER' => $arFields['PORTAL_NUMBER'], 'PORTAL_USER_ID' => $arFields['PORTAL_USER_ID'], 'CALL_DURATION' => $arFields['CALL_DURATION'], 'CALL_START_DATE' => $arFields['CALL_START_DATE'], 'COST' => $arFields['COST'], 'COST_CURRENCY' => $arFields['COST_CURRENCY'], 'CALL_FAILED_CODE' => $arFields['CALL_FAILED_CODE'], 'CALL_FAILED_REASON' => $arFields['CALL_FAILED_REASON'])));
     }
     return true;
 }
Ejemplo n.º 3
0
 public static function RegisterEntity($params)
 {
     if (!CModule::IncludeModule('crm')) {
         return false;
     }
     $callId = $params['ORIGIN_ID'];
     $callerId = '';
     if (substr($callId, 0, 3) == 'VI_') {
         $callId = substr($callId, 3);
     }
     $res = VI\CallTable::getList(array('filter' => array('=CALL_ID' => $callId)));
     if ($call = $res->fetch()) {
         $callerId = $call['CALLER_ID'];
         CVoxImplantCrmHelper::AddCall(array('CALL_ID' => $call['CALL_ID'], 'PHONE_NUMBER' => $call['CALLER_ID'], 'INCOMING' => $call['INCOMING'], 'USER_ID' => $call['USER_ID'], 'DATE_CREATE' => $call['DATE_CREATE']));
         if ($call['USER_ID'] > 0) {
             $crmData = CVoxImplantCrmHelper::GetDataForPopup($callId, $call['CALLER_ID'], $call['USER_ID']);
             $pullResult = CVoxImplantIncoming::SendPullEvent(array('COMMAND' => 'update_crm', 'USER_ID' => $call['USER_ID'], 'CALL_ID' => $callId, 'CALLER_ID' => $callerId, 'CRM' => $crmData));
         }
         CVoxImplantHistory::WriteToLog(array($callId, $call), 'CRM ATTACH INIT CALL');
     } else {
         $res = VI\StatisticTable::getList(array('filter' => array('=CALL_ID' => $callId)));
         if ($history = $res->fetch()) {
             $history['USER_ID'] = $history['PORTAL_USER_ID'];
             $history['DATE_CREATE'] = $history['CALL_START_DATE'];
             CVoxImplantCrmHelper::AddCall(array('CALL_ID' => $history['CALL_ID'], 'PHONE_NUMBER' => $history['PHONE_NUMBER'], 'INCOMING' => $history['INCOMING'] == CVoxImplantMain::CALL_OUTGOING ? CVoxImplantMain::CALL_OUTGOING : CVoxImplantMain::CALL_INCOMING, 'USER_ID' => $history['USER_ID'], 'DATE_CREATE' => $history['DATE_CREATE']));
             CVoxImplantCrmHelper::UpdateCall($history);
             CVoxImplantCrmHelper::AttachRecordToCall(array('CALL_ID' => $history['CALL_ID'], 'CALL_WEBDAV_ID' => $history['CALL_WEBDAV_ID'], 'CALL_RECORD_ID' => $history['CALL_RECORD_ID']));
             CVoxImplantHistory::WriteToLog(array($callId), 'CRM ATTACH FULL CALL');
         }
     }
     return true;
 }
Ejemplo n.º 4
0
 public static function Add($params)
 {
     if (strlen($params["CALL_ID"]) > 0) {
         $res = VI\CallTable::getList(array('select' => array('ID', 'DATE_CREATE', 'CRM', 'CONFIG_ID', 'USER_ID', 'TRANSFER_USER_ID'), 'filter' => array('=CALL_ID' => $params["CALL_ID"])));
         if ($call = $res->fetch()) {
             VI\CallTable::delete($call['ID']);
         }
     }
     $arFields = array("ACCOUNT_ID" => $params["ACCOUNT_ID"], "APPLICATION_ID" => $params["APPLICATION_ID"], "APPLICATION_NAME" => $params["APPLICATION_NAME"], "INCOMING" => $params["INCOMING"], "CALL_START_DATE" => $call ? $call['DATE_CREATE'] : new Bitrix\Main\Type\DateTime(), "CALL_DURATION" => $params["CALL_DURATION"], "CALL_STATUS" => $params["CALL_STATUS"], "CALL_FAILED_CODE" => $params["CALL_FAILED_CODE"], "CALL_FAILED_REASON" => $params["CALL_FAILED_REASON"], "COST" => $params["COST_FINAL"], "COST_CURRENCY" => $params["COST_CURRENCY"], "CALL_ID" => $params["CALL_ID"]);
     if (intval($params["PORTAL_USER_ID"]) > 0) {
         $arFields["PORTAL_USER_ID"] = intval($params["PORTAL_USER_ID"]);
     }
     if (strlen($params["PHONE_NUMBER"]) > 0) {
         $arFields["PHONE_NUMBER"] = $params["PHONE_NUMBER"];
     }
     if (strlen($params["CALL_DIRECTION"]) > 0) {
         $arFields["CALL_DIRECTION"] = $params["CALL_DIRECTION"];
     }
     if (strlen($params["PORTAL_NUMBER"]) > 0) {
         $arFields["PORTAL_NUMBER"] = $params["PORTAL_NUMBER"];
     }
     if (strlen($params["ACCOUNT_SEARCH_ID"]) > 0) {
         $arFields["PORTAL_NUMBER"] = $params["ACCOUNT_SEARCH_ID"];
     }
     if (strlen($params["CALL_LOG"]) > 0) {
         $arFields["CALL_LOG"] = $params["CALL_LOG"];
     }
     $orm = Bitrix\VoxImplant\StatisticTable::add($arFields);
     if (!$orm) {
         return false;
     }
     if ($call && intval($arFields["PORTAL_USER_ID"]) <= 0) {
         $res = VI\QueueTable::getList(array('select' => array('ID', 'USER_ID'), 'order' => array('LAST_ACTIVITY_DATE' => 'asc'), 'filter' => array('=CONFIG_ID' => $call['CONFIG_ID']), 'limit' => 1));
         $queueUser = $res->fetch();
         if ($queueUser) {
             $arFields["PORTAL_USER_ID"] = $queueUser['USER_ID'];
         }
     }
     if (strlen($arFields["PHONE_NUMBER"]) > 0 && $arFields["PORTAL_USER_ID"] > 0 && $params["CALL_FAILED_CODE"] != 423) {
         $plusSymbol = strlen($arFields["PHONE_NUMBER"]) >= 10 ? '+' : '';
         if ($arFields["INCOMING"] == CVoxImplantMain::CALL_OUTGOING) {
             if ($arFields['CALL_FAILED_CODE'] == '603-S') {
                 $message = GetMessage('VI_OUT_CALL_DECLINE_SELF', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
             } else {
                 if ($arFields['CALL_FAILED_CODE'] == 603) {
                     $message = GetMessage('VI_OUT_CALL_DECLINE', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
                 } else {
                     if ($arFields['CALL_FAILED_CODE'] == 486) {
                         $message = GetMessage('VI_OUT_CALL_BUSY', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
                     } else {
                         if ($arFields['CALL_FAILED_CODE'] == 480) {
                             $message = GetMessage('VI_OUT_CALL_UNAVAILABLE', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
                         } else {
                             if ($arFields['CALL_FAILED_CODE'] == 404 || $arFields['CALL_FAILED_CODE'] == 484) {
                                 $message = GetMessage('VI_OUT_CALL_ERROR_NUMBER', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
                             } else {
                                 if ($arFields['CALL_FAILED_CODE'] == 402) {
                                     $message = GetMessage('VI_OUT_CALL_NO_MONEY', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
                                 } else {
                                     $message = GetMessage('VI_OUT_CALL_END', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"], '#INFO#' => '[PCH=' . $orm->getId() . ']' . GetMessage('VI_CALL_INFO') . '[/PCH]'));
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if ($arFields['CALL_FAILED_CODE'] == 304) {
                 if (strlen($params['URL']) > 0) {
                     $subMessage = GetMessage('VI_CALL_VOICEMAIL', array('#LINK_START#' => '[PCH=' . $orm->getId() . ']', '#LINK_END#' => '[/PCH]'));
                 } else {
                     $subMessage = '[PCH=' . $orm->getId() . ']' . GetMessage('VI_CALL_INFO') . '[/PCH]';
                 }
                 $message = GetMessage('VI_IN_CALL_SKIP', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"], '#INFO#' => $subMessage));
             } else {
                 $message = GetMessage('VI_IN_CALL_END', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"], '#INFO#' => '[PCH=' . $orm->getId() . ']' . GetMessage('VI_CALL_INFO') . '[/PCH]'));
             }
         }
         self::SendMessageToChat($arFields["PORTAL_USER_ID"], $arFields["PHONE_NUMBER"], $arFields["INCOMING"], $message);
     }
     if ($call['CRM'] == 'Y') {
         CVoxImplantCrmHelper::UpdateCall($arFields);
     }
     if (strlen($params['URL']) > 0) {
         $attachToCrm = $call['CRM'] == 'Y';
         self::DownloadAgent($orm->getId(), $params['URL'], $attachToCrm);
     }
     if (strlen($params["ACCOUNT_PAYED"]) > 0 && in_array($params["ACCOUNT_PAYED"], array('Y', 'N'))) {
         CVoxImplantAccount::SetPayedFlag($params["ACCOUNT_PAYED"]);
     }
     foreach (GetModuleEvents("voximplant", "onCallEnd", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array(array('CALL_ID' => $arFields['CALL_ID'], 'CALL_TYPE' => $arFields['INCOMING'], 'PHONE_NUMBER' => $arFields['PHONE_NUMBER'], 'PORTAL_NUMBER' => $arFields['PORTAL_NUMBER'], 'PORTAL_USER_ID' => $arFields['PORTAL_USER_ID'], 'CALL_DURATION' => $arFields['CALL_DURATION'], 'CALL_START_DATE' => $arFields['CALL_START_DATE'], 'COST' => $arFields['COST'], 'COST_CURRENCY' => $arFields['COST_CURRENCY'], 'CALL_FAILED_CODE' => $arFields['CALL_FAILED_CODE'], 'CALL_FAILED_REASON' => $arFields['CALL_FAILED_REASON'])));
     }
     return true;
 }