- 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.
174 lines
7.8 KiB
Plaintext
174 lines
7.8 KiB
Plaintext
<?php
|
||
|
||
function NewMeeting($ws_entity) {
|
||
require_once 'include/Webservices/Utils.php';
|
||
require_once 'include/utils/Kontur.php';
|
||
require_once 'include/utils/Telegram.php';
|
||
require_once 'include/utils/WhatsApp.php';
|
||
include_once 'modules/Users/Users.php';
|
||
require_once 'include/Webservices/Create.php';
|
||
require_once 'includes/Loader.php';
|
||
vimport ('includes.runtime.Globals');
|
||
vimport ('includes.runtime.BaseModel');
|
||
vimport ('includes.runtime.LanguageHandler');
|
||
|
||
global $adb;
|
||
$user = Users::getActiveAdminUser(); // Получаем пользователя, под которым будем создавать записи
|
||
|
||
//$logstring = date('Y-m-d H:i:s').' - вошли в кастомный обработчик'.PHP_EOL;
|
||
//file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
|
||
// WS id
|
||
$ws_id = $ws_entity->getId();
|
||
$crmid = vtws_getCRMEntityId($ws_id);
|
||
//$logstring = date('Y-m-d H:i:s').' - получили ID проекта: '.$crmid.PHP_EOL;
|
||
//file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
|
||
$query = 'select p.projectname, cf.cf_1843 as startdate, cf.cf_1845 as starttime, p.linktoaccountscontacts as contactid, c.mobile, c.phone, c.firstname, e.smownerid as userid
|
||
from vtiger_project p
|
||
left join vtiger_projectcf cf on cf.projectid = p.projectid
|
||
left join vtiger_contactdetails c on c.contactid = p.linktoaccountscontacts
|
||
left join vtiger_crmentity e on e.crmid = p.projectid
|
||
where p.projectid = '.$crmid;
|
||
$result = $adb->pquery($query);
|
||
|
||
if ($adb->num_rows($result) == 0) {
|
||
$logstring = date('Y-m-d H:i:s').' - очень странно, но проекта с там ID нет...'.PHP_EOL;
|
||
file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
} else {
|
||
$name = $adb->query_result($result, 0, "projectname");
|
||
$startdate = $adb->query_result($result, 0, "startdate");
|
||
$starttime = $adb->query_result($result, 0, "starttime");
|
||
$contactid = $adb->query_result($result, 0, "contactid");
|
||
$tgid = $adb->query_result($result, 0, "phone");
|
||
$mobile = $adb->query_result($result, 0, "mobile");
|
||
$firstname = $adb->query_result($result, 0, "firstname");
|
||
$projectowner = $adb->query_result($result, 0, "userid");
|
||
|
||
if (empty($startdate) or empty($starttime)) {
|
||
$logstring = date('Y-m-d H:i:s').' - Найден проект: '.$name.'; но в нем не указана дата/время начала митинга'.PHP_EOL;
|
||
file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
} else {
|
||
$enddate = $startdate;
|
||
$endtime= date('H:i:s', strtotime($starttime) + 3600);
|
||
|
||
//$logstring = date('Y-m-d H:i:s').' - Найден проект: '.$name.'; время начала митинга: '.$startdate.' '.$starttime.'; время окончания: '.$enddate.' '.$endtime.PHP_EOL;
|
||
//file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
|
||
$result = CreateMeeting($crmid, $startdate, $starttime, $enddate, $endtime, $name, 'Рабочая встреча');
|
||
if ($result == 'YES') {
|
||
//$logstring = date('Y-m-d H:i:s').' - Встреча успешно создана'.PHP_EOL;
|
||
//file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
$query = 'update vtiger_projectcf set cf_1847 = "https://clientright.ktalk.ru/'.$crmid.'" where projectid = '.$crmid;
|
||
$result = $adb->pquery($query);
|
||
|
||
$message = $firstname.', добрый день. Мы запланировали видеовстречу '.date('d.m.Y', strtotime($startdate)).' в '.$starttime.', ссылку на подключение пришлем за 15 минут до начала';
|
||
|
||
if (!empty($tgid)) {
|
||
try {
|
||
$params = array (
|
||
'commentcontent' => $message,
|
||
'related_to' => $ws_id,
|
||
'channel' => 'Telegram',
|
||
'assigned_user_id' => $user
|
||
);
|
||
|
||
//$logstring = date('Y-m-d H:i:s').' - массив для телеги: '.json_encode($params).PHP_EOL;
|
||
//file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
|
||
$comment = vtws_create('ModComments', $params, $user);
|
||
|
||
//$logstring = date('Y-m-d H:i:s').' - создание коммента: '.json_encode($comment).PHP_EOL;
|
||
//file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
|
||
$commentid = substr($comment['id'], 3);
|
||
} catch (WebServiceException $ex) {
|
||
$output = $ex->getMessage();
|
||
$logstring = date('Y-m-d H:i:s').' - Коммент не создался. Ошибка: '.$output.PHP_EOL;
|
||
file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
}
|
||
|
||
if ($commentid > 0) {
|
||
$result = TelegramSendComment($commentid, $message);
|
||
//$logstring = date('Y-m-d H:i:s').' - Отправка уведомления в телегу: '.$result.PHP_EOL;
|
||
//file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
}
|
||
}
|
||
|
||
if (!empty($mobile)) {
|
||
try {
|
||
$params = array (
|
||
'commentcontent' => $message,
|
||
'related_to' => $ws_id,
|
||
'channel' => 'WhatsApp',
|
||
'assigned_user_id' => $user
|
||
);
|
||
|
||
//$logstring = date('Y-m-d H:i:s').' - массив для WhatsApp: '.json_encode($params).PHP_EOL;
|
||
//file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
|
||
$comment = vtws_create('ModComments', $params, $user);
|
||
$commentid = substr($comment['id'], 3);
|
||
} catch (WebServiceException $ex) {
|
||
$output = $ex->getMessage();
|
||
$logstring = date('Y-m-d H:i:s').' - Коммент не создался. Ошибка: '.$output.PHP_EOL;
|
||
file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
}
|
||
|
||
if ($commentid > 0) {
|
||
$result = WhatsAppSendComment($commentid, $message);
|
||
//$logstring = date('Y-m-d H:i:s').' - Отправка уведомления в WhatsApp: '.$result.PHP_EOL;
|
||
//file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
}
|
||
}
|
||
|
||
// Создатим событие в Календаре
|
||
|
||
try {
|
||
$params = array (
|
||
'subject' => 'Видеовстреча по проекту '.$name,
|
||
'activitytype' => 'Видеовстреча',
|
||
'date_start' => $startdate,
|
||
'due_date' => $startdate,
|
||
'time_start' => $starttime,
|
||
'time_end' => $endtime,
|
||
'sendnotification' => 0,
|
||
'duration_hours' => 1,
|
||
'duration_minutes' => 0,
|
||
'notime' => 0,
|
||
'recurringtype' => '--None--',
|
||
'taskstatus' => 'Planned',
|
||
'assigned_user_id' => '19x'.$projectowner
|
||
);
|
||
|
||
$logstring = date('Y-m-d H:i:s').' - массив для Календаря: '.json_encode($params).PHP_EOL;
|
||
file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
|
||
$activity = vtws_create('Calendar', $params, $user);
|
||
|
||
$logstring = date('Y-m-d H:i:s').' - создание Календаря: '.json_encode($comment).PHP_EOL;
|
||
file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
|
||
$activityid = substr($activity['id'], 2);
|
||
} catch (WebServiceException $ex) {
|
||
$output = $ex->getMessage();
|
||
$logstring = date('Y-m-d H:i:s').' - Событие не создалось. Ошибка: '.$output.PHP_EOL;
|
||
file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
$activityid = 0;
|
||
}
|
||
|
||
if ($activityid > 0) {
|
||
$query = 'insert into vtiger_cntactivityrel (contactid, activityid) values(?, ?)';
|
||
$result = $adb->pquery($query, array($contactid, $activityid));
|
||
}
|
||
|
||
|
||
} else {
|
||
$logstring = date('Y-m-d H:i:s').' - Что-то пошло не так. Ответ от Контура при создании встречи: '.$result.PHP_EOL;
|
||
file_put_contents('wfCreateKonturMeeting.log', $logstring, FILE_APPEND);
|
||
}
|
||
}
|
||
}
|
||
|
||
return;
|
||
} |