- Added comprehensive AI Assistant system (aiassist/ directory): * Vector search and embedding capabilities * Typebot proxy integration * Elastic search functionality * Message classification and chat history * MCP proxy for external integrations - Implemented Court Status API (GetCourtStatus.php): * Real-time court document status checking * Integration with external court systems * Comprehensive error handling and logging - Enhanced S3 integration: * Improved file backup system with metadata * Batch processing capabilities * Enhanced error logging and recovery * Copy operations with URL fixing - Added Telegram contact creation API - Improved error logging across all modules - Enhanced callback system for AI responses - Extensive backup file storage with timestamps - Updated documentation and README files - File storage improvements: * Thousands of backup files with proper metadata * Fix operations for broken file references * Project-specific backup and recovery systems * Comprehensive file integrity checking Total: 26,461+ files added/modified including AWS SDK, vendor dependencies, and extensive backup system.
116 lines
5.2 KiB
PHP
116 lines
5.2 KiB
PHP
<?php
|
||
/*********************************************************************************
|
||
* API-интерфейс для создания Контакта из Telegram
|
||
* Минимальные данные: tgid и phone
|
||
* All Rights Reserved.
|
||
* Contributor(s): Фёдор
|
||
********************************************************************************/
|
||
|
||
include_once 'include/Webservices/Query.php';
|
||
include_once 'modules/Users/Users.php';
|
||
require_once('include/Webservices/Utils.php');
|
||
require_once 'include/Webservices/Create.php';
|
||
require_once 'include/Webservices/Revise.php';
|
||
require_once 'includes/Loader.php';
|
||
vimport ('includes.runtime.Globals');
|
||
vimport ('includes.runtime.BaseModel');
|
||
vimport ('includes.runtime.LanguageHandler');
|
||
|
||
function vtws_createtgcontact($tgid, $mobile = '', $firstname = '', $lastname = '', $user = false) {
|
||
|
||
$logstring = date("Y-m-d H:i:s").' '.json_encode($_REQUEST);
|
||
file_put_contents('logs/CreateTGContact.log', $logstring.PHP_EOL, FILE_APPEND);
|
||
|
||
// Проверяем минимальные обязательные поля - только tgid
|
||
if(empty($tgid)){
|
||
$logstring = date("Y-m-d H:i:s").' Не указано обязательное поле: tgid';
|
||
file_put_contents('logs/CreateTGContact.log', $logstring.PHP_EOL, FILE_APPEND);
|
||
throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Не заполнено обязательное поле: tgid");
|
||
}
|
||
|
||
// Очищаем и форматируем мобильный телефон (если передан)
|
||
if(!empty($mobile)) {
|
||
$mobile = preg_replace('/[^0-9]/', '', $mobile);
|
||
if (strlen($mobile) == 11 && substr($mobile, 0, 1) == '8') {
|
||
$mobile = "7".substr($mobile, 1);
|
||
} else if (strlen($mobile) == 10) {
|
||
$mobile = "7".$mobile;
|
||
} else if (strlen($mobile) == 11 && substr($mobile, 0, 1) == '7') {
|
||
// Уже в правильном формате
|
||
} else {
|
||
$logstring = date("Y-m-d H:i:s").' Некорректный номер телефона: '.$mobile;
|
||
file_put_contents('logs/CreateTGContact.log', $logstring.PHP_EOL, FILE_APPEND);
|
||
// Не выбрасываем ошибку, просто очищаем некорректный номер
|
||
$mobile = '';
|
||
}
|
||
}
|
||
|
||
$output = 'Внутренняя ошибка CRM, данные не сохранены';
|
||
|
||
// Формируем имя и фамилию если не переданы
|
||
if(empty($firstname)) {
|
||
$firstname = 'Telegram';
|
||
}
|
||
if(empty($lastname)) {
|
||
$lastname = 'User_' . substr($tgid, -4); // Последние 4 цифры tgid
|
||
}
|
||
|
||
$params = array (
|
||
'firstname' => $firstname,
|
||
'lastname' => $lastname,
|
||
'mobile' => $mobile, // Мобильный телефон (опциональный)
|
||
'phone' => $tgid, // Сохраняем tgid в поле phone
|
||
'email' => '', // Пустой email
|
||
'birthday' => '01-01-1900', // Дефолтная дата рождения
|
||
'cf_1257' => '', // ИНН пустой
|
||
'cf_1157' => '', // Отчество пустое
|
||
'cf_1263' => '', // Место рождения пустое
|
||
'mailingstreet' => '', // Адрес пустой
|
||
'cf_1849' => '', // Реквизиты пустые
|
||
'cf_1580' => '' // Код пустой для TG контактов
|
||
);
|
||
|
||
global $adb, $current_user;
|
||
|
||
// Проверяем существование контакта по tgid (в поле phone)
|
||
$query = "select c.contactid
|
||
from vtiger_contactdetails c
|
||
left join vtiger_crmentity e on e.crmid = c.contactid
|
||
where e.deleted = 0 and c.phone = ?
|
||
limit 1";
|
||
$result = $adb->pquery($query, array($tgid));
|
||
|
||
if ($adb->num_rows($result) > 0) {
|
||
// Контакт с таким tgid уже существует - обновляем
|
||
$params['id'] = '12x'.$adb->query_result($result, 0, 'contactid');
|
||
$logstring = date('Y-m-d H:i:s').' Массив для обновления TG Контакта: '.json_encode($params).PHP_EOL;
|
||
file_put_contents('logs/CreateTGContact.log', $logstring, FILE_APPEND);
|
||
try {
|
||
$contact = vtws_revise($params, $current_user);
|
||
$output = substr($contact['id'], 3);
|
||
$logstring = date('Y-m-d H:i:s').' обновлен TG Контакт с id '.$output.PHP_EOL;
|
||
file_put_contents('logs/CreateTGContact.log', $logstring, FILE_APPEND);
|
||
} catch (WebServiceException $ex) {
|
||
$logstring = date('Y-m-d H:i:s').' '.$ex->getMessage().PHP_EOL;
|
||
file_put_contents('logs/CreateTGContact.log', $logstring, FILE_APPEND);
|
||
}
|
||
} else {
|
||
// Создаем новый контакт
|
||
$params['assigned_user_id'] = vtws_getWebserviceEntityId('Users', $current_user->id);
|
||
$logstring = date('Y-m-d H:i:s').' Массив для создания TG Контакта: '.json_encode($params).PHP_EOL;
|
||
file_put_contents('logs/CreateTGContact.log', $logstring, FILE_APPEND);
|
||
try {
|
||
$contact = vtws_create('Contacts', $params, $current_user);
|
||
$output = substr($contact['id'], 3);
|
||
$logstring = date('Y-m-d H:i:s').' создан TG Контакт с id '.$output.PHP_EOL;
|
||
file_put_contents('logs/CreateTGContact.log', $logstring, FILE_APPEND);
|
||
} catch (WebServiceException $ex) {
|
||
$logstring = date('Y-m-d H:i:s').' '.$ex->getMessage().PHP_EOL;
|
||
file_put_contents('logs/CreateTGContact.log', $logstring, FILE_APPEND);
|
||
}
|
||
}
|
||
|
||
return $output;
|
||
}
|
||
?>
|