Ejemplo n.º 1
0
 public static function Invite($callId, $transferUserId)
 {
     $transferUserId = intval($transferUserId);
     if ($transferUserId <= 0) {
         return false;
     }
     $res = VI\CallTable::getList(array('select' => array('ID', 'CALL_ID', 'USER_ID', 'CALLER_ID', 'CRM', 'TRANSFER_USER_ID'), 'filter' => array('=CALL_ID' => $callId)));
     $call = $res->fetch();
     if (!$call) {
         return false;
     }
     if ($call['TRANSFER_USER_ID'] > 0) {
         self::Cancel($callId, $call);
     }
     VI\CallTable::update($call['ID'], array('TRANSFER_USER_ID' => $transferUserId));
     $crmData = array();
     if ($call['CRM'] == 'Y') {
         $crmData = CVoxImplantCrmHelper::GetDataForPopup($call['CALL_ID'], $call['CALLER_ID'], $transferUserId);
     }
     self::SendPullEvent(array('COMMAND' => 'inviteTransfer', 'USER_ID' => $transferUserId, 'CALL_ID' => $call['CALL_ID'], 'CALLER_ID' => $call['CALLER_ID'], 'CRM' => $crmData));
     return true;
 }
Ejemplo n.º 2
0
 public static function Init($params)
 {
     $callAdd = true;
     if ($params['CALL_ID_TMP']) {
         $res = VI\CallTable::getList(array('filter' => array('=CALL_ID' => $params['CALL_ID_TMP'])));
         if ($call = $res->fetch()) {
             $result = VI\CallTable::update($call['ID'], array('CONFIG_ID' => $params['CONFIG_ID'], 'CALL_ID' => $params['CALL_ID'], 'CRM' => $params['CRM'], 'USER_ID' => $params['USER_ID'], 'CALLER_ID' => $params['PHONE_NUMBER'], 'STATUS' => VI\CallTable::STATUS_CONNECTING, 'ACCESS_URL' => $params['ACCESS_URL']));
             if ($result) {
                 $callAdd = false;
             }
         }
     }
     if ($callAdd) {
         VI\CallTable::add(array('CONFIG_ID' => $params['CONFIG_ID'], 'CALL_ID' => $params['CALL_ID'], 'CRM' => $params['CRM'], 'USER_ID' => $params['USER_ID'], 'CALLER_ID' => $params['PHONE_NUMBER'], 'STATUS' => VI\CallTable::STATUS_CONNECTING, 'ACCESS_URL' => $params['ACCESS_URL'], 'DATE_CREATE' => new FieldType\DateTime()));
     }
     if ($params['CRM'] == 'Y') {
         CVoxImplantCrmHelper::AddCall(array('CALL_ID' => $params['CALL_ID'], 'PHONE_NUMBER' => $params['PHONE_NUMBER'], 'INCOMING' => CVoxImplantMain::CALL_OUTGOING, 'USER_ID' => $params['USER_ID'], 'DATE_CREATE' => new FieldType\DateTime()));
         $crmData = CVoxImplantCrmHelper::GetDataForPopup($params['CALL_ID'], $params['PHONE_NUMBER'], $params['USER_ID']);
     } else {
         $crmData = array();
     }
     self::SendPullEvent(array('COMMAND' => 'outgoing', 'USER_ID' => $params['USER_ID'], 'CALL_ID' => $params['CALL_ID'], 'CALL_ID_TMP' => $params['CALL_ID_TMP'], 'CALL_DEVICE' => $params['CALL_DEVICE'], 'PHONE_NUMBER' => $params['PHONE_NUMBER'], 'EXTERNAL' => $params['CALL_ID_TMP'] ? true : false, 'CRM' => $crmData));
     return true;
 }
Ejemplo n.º 3
0
 public static function Complete($callId, $device = 'WEBRTC')
 {
     $res = VI\CallTable::getList(array('select' => array('ID', 'CALL_ID', 'CRM_LEAD', 'CALLER_ID', 'USER_ID', 'TRANSFER_USER_ID', 'ACCESS_URL', 'CRM', 'CONFIG_ID'), 'filter' => array('=CALL_ID' => $callId)));
     $call = $res->fetch();
     if (!$call) {
         return false;
     }
     VI\CallTable::update($call['ID'], array('USER_ID' => $call['TRANSFER_USER_ID'], 'TRANSFER_USER_ID' => 0));
     CVoxImplantHistory::TransferMessage($call['USER_ID'], $call['TRANSFER_USER_ID'], $call['CALLER_ID']);
     self::SendPullEvent(array('COMMAND' => 'completeTransfer', 'USER_ID' => $call['USER_ID'], 'TRANSFER_USER_ID' => $call['TRANSFER_USER_ID'], 'CALL_ID' => $call['CALL_ID']));
     $crmDataSend = false;
     if ($call['CRM'] == 'Y' && $call['CONFIG_ID'] > 0) {
         $config = CVoxImplantConfig::GetConfig($call['CONFIG_ID']);
         if (isset($config['CRM_TRANSFER_CHANGE']) && $config['CRM_TRANSFER_CHANGE'] == 'Y') {
             if ($call['CRM_LEAD'] > 0) {
                 $crmData = array('LEAD_DATA' => array('ID' => $call['CRM_LEAD'], 'ASSIGNED_BY_ID' => 0));
             } else {
                 $crmData = CVoxImplantCrmHelper::GetDataForPopup($call['CALL_ID'], $call['CALLER_ID']);
             }
             if (isset($crmData['LEAD_DATA']) && $crmData['LEAD_DATA']['ASSIGNED_BY_ID'] >= 0 && $call['TRANSFER_USER_ID'] > 0 && $crmData['LEAD_DATA']['ASSIGNED_BY_ID'] != $call['TRANSFER_USER_ID']) {
                 CVoxImplantCrmHelper::UpdateLead($crmData['LEAD_DATA']['ID'], array('ASSIGNED_BY_ID' => $call['TRANSFER_USER_ID']));
                 $crmDataSend = CVoxImplantCrmHelper::GetDataForPopup($call['CALL_ID'], $call['CALLER_ID'], $call['TRANSFER_USER_ID']);
             }
         }
     }
     self::SendPullEvent(array('COMMAND' => 'completeTransfer', 'USER_ID' => $call['TRANSFER_USER_ID'], 'TRANSFER_USER_ID' => $call['TRANSFER_USER_ID'], 'CALL_DEVICE' => $device, 'CALL_ID' => $call['CALL_ID'], 'CRM' => $crmDataSend));
     return true;
 }
Ejemplo n.º 4
0
 public static function CallStart($callId, $userId, $callDevice = 'WEBRTC', $external = false)
 {
     // TODO check $callId, $userId
     $res = Bitrix\Voximplant\CallTable::getList(array('select' => array('ID', 'CALL_ID', 'CALLER_ID', 'DATE_CREATE', 'CRM_LEAD', 'PORTAL_USER_ID'), 'filter' => array('=CALL_ID' => $callId)));
     if ($call = $res->fetch()) {
         $crmData = false;
         if ($call['CRM_LEAD'] > 0) {
             CVoxImplantCrmHelper::UpdateLead($call['CRM_LEAD'], array('ASSIGNED_BY_ID' => $userId));
             $crmData = CVoxImplantCrmHelper::GetDataForPopup($call['CALL_ID'], $call['CALLER_ID'], $userId);
         }
         Bitrix\Voximplant\CallTable::update($call['ID'], array('USER_ID' => $userId, 'STATUS' => Bitrix\Voximplant\CallTable::STATUS_CONNECTED));
         foreach (GetModuleEvents("voximplant", "onCallStart", true) as $arEvent) {
             ExecuteModuleEventEx($arEvent, array(array('CALL_ID' => $call['CALL_ID'], 'USER_ID' => $userId)));
         }
         $pushUser = array($userId);
         if ($call['PORTAL_USER_ID'] > 0) {
             $pushUser[] = $call['PORTAL_USER_ID'];
         }
         foreach ($pushUser as $userId) {
             self::SendPullEvent(array('COMMAND' => 'start', 'USER_ID' => $userId, 'CALL_ID' => $callId, 'CALL_DEVICE' => $callDevice, 'EXTERNAL' => $external ? true : false, 'CRM' => $crmData));
         }
     }
 }
Ejemplo n.º 5
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.º 6
0
 public static function Init($params)
 {
     $result['STATUS'] = 'OK';
     $result['PORTAL_CALL'] = 'N';
     if (strlen($params['PHONE_NUMBER']) > 0 && strlen($params['PHONE_NUMBER']) <= 4) {
         $res = CVoxImplantUser::GetList(array('select' => array('ID', 'IS_ONLINE_CUSTOM', 'UF_VI_PHONE', 'ACTIVE'), 'filter' => array('=UF_PHONE_INNER' => intval($params['PHONE_NUMBER']), '=ACTIVE' => 'Y')));
         if ($userData = $res->fetch()) {
             $result['PORTAL_CALL'] = 'Y';
             $result['USER_ID'] = $userData['ID'];
             $result['COMMAND'] = CVoxImplantIncoming::RULE_HUNGUP;
             if (CModule::IncludeModule('pull')) {
                 $orm = \Bitrix\Pull\PushTable::getList(array('select' => array('ID'), 'filter' => array('=USER_ID' => $userData['ID'])));
                 $userData['USER_HAVE_MOBILE'] = $orm->fetch() ? 'Y' : 'N';
             } else {
                 $userData['USER_HAVE_MOBILE'] = 'N';
             }
             if ($userData['ID'] == $params['USER_ID']) {
                 $result['COMMAND'] = CVoxImplantIncoming::RULE_HUNGUP;
             } else {
                 if ($userData['IS_ONLINE_CUSTOM'] == 'Y' || $userData['UF_VI_PHONE'] == 'Y' || $userData['USER_HAVE_MOBILE'] == 'Y') {
                     $result['COMMAND'] = CVoxImplantIncoming::RULE_WAIT;
                     $result['TYPE_CONNECT'] = CVoxImplantIncoming::TYPE_CONNECT_DIRECT;
                     $result['USER_HAVE_PHONE'] = $userData['UF_VI_PHONE'] == 'Y' ? 'Y' : 'N';
                     $result['USER_HAVE_MOBILE'] = $userData['USER_HAVE_MOBILE'];
                     $result['USER_SHORT_NAME'] = '';
                 }
             }
         }
     }
     $callAdd = true;
     if ($params['CALL_ID_TMP']) {
         $res = VI\CallTable::getList(array('filter' => array('=CALL_ID' => $params['CALL_ID_TMP'])));
         if ($call = $res->fetch()) {
             $res = VI\CallTable::update($call['ID'], array('CONFIG_ID' => $params['CONFIG_ID'], 'CALL_ID' => $params['CALL_ID'], 'CRM' => $params['CRM'], 'USER_ID' => $params['USER_ID'], 'CALLER_ID' => $params['PHONE_NUMBER'], 'STATUS' => VI\CallTable::STATUS_CONNECTING, 'ACCESS_URL' => $params['ACCESS_URL'], 'PORTAL_USER_ID' => $result['PORTAL_CALL'] == 'Y' ? $result['USER_ID'] : 0));
             if ($res) {
                 $callAdd = false;
             }
         }
     }
     if ($callAdd) {
         VI\CallTable::add(array('CONFIG_ID' => $params['CONFIG_ID'], 'CALL_ID' => $params['CALL_ID'], 'CRM' => $params['CRM'], 'USER_ID' => $params['USER_ID'], 'CALLER_ID' => $params['PHONE_NUMBER'], 'STATUS' => VI\CallTable::STATUS_CONNECTING, 'ACCESS_URL' => $params['ACCESS_URL'], 'PORTAL_USER_ID' => $result['PORTAL_CALL'] == 'Y' ? $result['USER_ID'] : 0, 'DATE_CREATE' => new FieldType\DateTime()));
     }
     $config = self::GetConfigByUserId($params['USER_ID']);
     if ($params['CRM'] == 'Y' && $result['PORTAL_CALL'] == 'N') {
         if ($config['CRM_CREATE'] == CVoxImplantConfig::CRM_CREATE_LEAD) {
             $crmData = CVoxImplantCrmHelper::GetDataForPopup($params['CALL_ID'], $params['PHONE_NUMBER']);
             if ($crmData['FOUND'] == 'N') {
                 CVoxImplantCrmHelper::AddLead(array('USER_ID' => $params['USER_ID'], 'PHONE_NUMBER' => $params['PHONE_NUMBER'], 'SEARCH_ID' => $config['SEARCH_ID'], 'CRM_SOURCE' => $config['CRM_SOURCE'], 'INCOMING' => false));
             }
         }
         CVoxImplantCrmHelper::AddCall(array('CALL_ID' => $params['CALL_ID'], 'PHONE_NUMBER' => $params['PHONE_NUMBER'], 'INCOMING' => CVoxImplantMain::CALL_OUTGOING, 'USER_ID' => $params['USER_ID'], 'DATE_CREATE' => new FieldType\DateTime()));
         $crmData = CVoxImplantCrmHelper::GetDataForPopup($params['CALL_ID'], $params['PHONE_NUMBER'], $params['USER_ID']);
     } else {
         $crmData = array();
     }
     CVoxImplantHistory::WriteToLog(array('COMMAND' => 'outgoing', 'USER_ID' => $params['USER_ID'], 'CALL_ID' => $params['CALL_ID'], 'CALL_ID_TMP' => $params['CALL_ID_TMP'], 'CALL_DEVICE' => $params['CALL_DEVICE'], 'PHONE_NUMBER' => $params['PHONE_NUMBER'], 'EXTERNAL' => $params['CALL_ID_TMP'] ? true : false, 'PORTAL_CALL' => $result['PORTAL_CALL'], 'PORTAL_CALL_USER_ID' => $params['USER_ID'], 'CRM' => $crmData));
     $portalUser = array();
     if ($result['PORTAL_CALL'] == 'Y') {
         if (CModule::IncludeModule('im')) {
             $portalUser = CIMContactList::GetUserData(array('ID' => array($params['USER_ID'], $result['USER_ID']), 'DEPARTMENT' => 'N', 'HR_PHOTO' => 'Y'));
         } else {
             $portalUser = array();
         }
     }
     self::SendPullEvent(array('COMMAND' => 'outgoing', 'USER_ID' => $params['USER_ID'], 'CALL_ID' => $params['CALL_ID'], 'CALL_ID_TMP' => $params['CALL_ID_TMP'], 'CALL_DEVICE' => $params['CALL_DEVICE'], 'PHONE_NUMBER' => $params['PHONE_NUMBER'], 'EXTERNAL' => $params['CALL_ID_TMP'] ? true : false, 'PORTAL_CALL' => $result['PORTAL_CALL'], 'PORTAL_CALL_USER_ID' => $result['USER_ID'], 'PORTAL_CALL_DATA' => $portalUser, 'CONFIG' => array('RECORDING' => $config['RECORDING'], 'CRM_CREATE' => $config['CRM_CREATE']), 'CRM' => $crmData));
     if ($result['PORTAL_CALL'] == 'Y' && $result['USER_ID'] > 0) {
         CVoxImplantIncoming::SendPullEvent(array('COMMAND' => 'invite', 'USER_ID' => $result['USER_ID'], 'CALL_ID' => $params['CALL_ID'], 'CALLER_ID' => $params['USER_DIRECT_CODE'], 'PHONE_NAME' => $params['CALLER_ID'], 'PORTAL_CALL' => 'Y', 'PORTAL_CALL_USER_ID' => $params['USER_ID'], 'PORTAL_CALL_DATA' => $portalUser, 'CONFIG' => array('RECORDING' => $config['RECORDING'], 'CRM_CREATE' => $config['CRM_CREATE'])));
     }
     return $result;
 }
Ejemplo n.º 7
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.º 8
0
 public static function DownloadAgent($historyID, $recordUrl, $attachToCrm = true)
 {
     $historyID = intval($historyID);
     if (strlen($recordUrl) <= 0 || $historyID <= 0) {
         return false;
     }
     $http = new \Bitrix\Main\Web\HttpClient();
     $http->query('HEAD', $recordUrl);
     if ($http->getStatus() != 200) {
         CAgent::AddAgent("CVoxImplantHistory::DownloadAgent('{$historyID}','{$recordUrl}','{$attachToCrm}');", 'voximplant', 'N', 30, '', 'Y', ConvertTimeStamp(time() + CTimeZone::GetOffset() + 30, 'FULL'));
         return false;
     }
     $history = VI\StatisticTable::getById($historyID);
     $arHistory = $history->fetch();
     try {
         $recordFile = CFile::MakeFileArray($recordUrl);
         if (is_array($recordFile) && $recordFile['size'] && $recordFile['size'] > 0) {
             $recordFile = array_merge($recordFile, array('MODULE_ID' => 'voximplant'));
             $fileID = CFile::SaveFile($recordFile, 'voximplant');
             if (is_int($fileID) && $fileID > 0) {
                 $elementID = CVoxImplantDiskHelper::SaveFile($arHistory, CFile::GetFileArray($fileID), CSite::GetDefSite());
                 $elementID = intval($elementID);
                 if ($attachToCrm && $elementID > 0) {
                     CVoxImplantCrmHelper::AttachRecordToCall(array('CALL_ID' => $arHistory['CALL_ID'], 'CALL_RECORD_ID' => $fileID, 'CALL_WEBDAV_ID' => $elementID));
                 }
                 VI\StatisticTable::update($historyID, array('CALL_RECORD_ID' => $fileID, 'CALL_WEBDAV_ID' => $elementID));
             }
         }
     } catch (Exception $ex) {
     }
     return false;
 }