Beispiel #1
0
 public static function CallHold($callId, $result = false)
 {
     $res = VI\CallTable::getList(array('select' => array('ID', 'CALL_ID', 'CALLER_ID', 'USER_ID', 'TRANSFER_USER_ID', 'ACCESS_URL'), 'filter' => array('=CALL_ID' => $callId)));
     $call = $res->fetch();
     if (!$call) {
         return false;
     }
     $answer['COMMAND'] = $result ? 'hold' : 'unhold';
     $answer['OPERATOR_ID'] = $call['USER_ID'];
     $http = new \Bitrix\Main\Web\HttpClient();
     $http->waitResponse(false);
     $http->post($call['ACCESS_URL'], json_encode($answer));
     self::SendPullEvent(array('COMMAND' => $result ? 'hold' : 'unhold', 'USER_ID' => $call['USER_ID'], 'CALL_ID' => $call['CALL_ID']));
     return true;
 }
Beispiel #2
0
 public static function Timeout($callId)
 {
     $res = VI\CallTable::getList(array('select' => array('ID', 'CALL_ID', 'USER_ID', 'TRANSFER_USER_ID', 'ACCESS_URL'), 'filter' => array('=CALL_ID' => $callId)));
     $call = $res->fetch();
     if (!$call) {
         return false;
     }
     VI\CallTable::update($call['ID'], array('TRANSFER_USER_ID' => 0));
     self::SendPullEvent(array('COMMAND' => 'timeoutTransfer', 'USER_ID' => $call['TRANSFER_USER_ID'], 'CALL_ID' => $call['CALL_ID']));
     return true;
 }
Beispiel #3
0
 public static function Answer($callId)
 {
     $res = VI\CallTable::getList(array('select' => array('ID', 'ACCESS_URL'), 'filter' => array('=CALL_ID' => $callId)));
     $call = $res->fetch();
     if (!$call) {
         return false;
     }
     global $USER;
     $ViMain = new CVoxImplantMain($USER->GetId());
     $result = $ViMain->GetDialogInfo($_POST['NUMBER']);
     if ($result) {
         echo CUtil::PhpToJsObject(array('DIALOG_ID' => $result['DIALOG_ID'], 'HR_PHOTO' => $result['HR_PHOTO'], 'ERROR' => ''));
     } else {
         echo CUtil::PhpToJsObject(array('CODE' => $ViMain->GetError()->code, 'ERROR' => $ViMain->GetError()->msg));
     }
 }
Beispiel #4
0
 public static function StartCall($userId, $phoneNumber)
 {
     $phoneNormalized = CVoxImplantPhone::Normalize($phoneNumber);
     $userId = intval($userId);
     if ($userId <= 0 || !$phoneNormalized) {
         return false;
     }
     $call = VI\CallTable::add(array('CALL_ID' => 'temp.' . md5($userId . $phoneNumber) . time(), 'USER_ID' => $userId, 'CALLER_ID' => $phoneNormalized, 'STATUS' => VI\CallTable::STATUS_CONNECTING, 'DATE_CREATE' => new FieldType\DateTime()));
     $viHttp = new CVoxImplantHttp();
     $result = $viHttp->StartOutgoingCall($userId, $phoneNumber);
     VI\CallTable::update($call->GetId(), array('CALL_ID' => $result->call_id, 'ACCESS_URL' => $result->access_url, 'DATE_CREATE' => new FieldType\DateTime()));
     self::SendPullEvent(array('COMMAND' => 'outgoing', 'USER_ID' => $userId, 'PHONE_NUMBER' => $phoneNormalized, 'CALL_ID' => $result->call_id, 'CALL_DEVICE' => 'PHONE', 'EXTERNAL' => true));
     return $result ? true : false;
 }
Beispiel #5
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;
 }
Beispiel #6
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;
 }
Beispiel #7
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;
 }