Files
crm.clientright.ru/aiassist/crmHandler.php
Fedor ac7467f0b4 Major CRM updates: AI Assistant, Court Status API, S3 integration improvements, and extensive file storage system
- 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.
2025-10-16 11:17:21 +03:00

77 lines
3.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// aiassist/crmHandler.php
require_once 'database.php';
require_once 'logger.php';
function fetchDocumentData($pdo, $id) {
logMessage("Получение данных документа из CRM по ID: $id");
$sql = "
SELECT
n.title,
CASE
WHEN a.storedname IS NOT NULL THEN CONCAT(a.path, a.attachmentsid, '_', a.storedname)
ELSE CONCAT(a.path, a.attachmentsid, '_', a.name)
END AS filepath,
f.foldername AS folder_name,
f.folderid AS folder_id
FROM vtiger_senotesrel r
LEFT JOIN vtiger_notes n ON n.notesid = r.notesid
LEFT JOIN vtiger_crmentity e ON e.crmid = r.notesid
LEFT JOIN vtiger_notescf ncf ON ncf.notesid = r.notesid
LEFT JOIN vtiger_seattachmentsrel r2 ON r2.crmid = r.notesid
LEFT JOIN vtiger_attachments a ON a.attachmentsid = r2.attachmentsid
LEFT JOIN vtiger_attachmentsfolder f ON f.folderid = n.folderid
WHERE r.crmid = ? AND e.deleted = 0
AND (a.type = 'application/pdf' OR a.type = 'application/octet-stream')
";
try {
$stmt = $pdo->prepare($sql);
$stmt->execute([$id]);
$documents = $stmt->fetchAll(PDO::FETCH_ASSOC);
logMessage("Документы получены из CRM: " . json_encode($documents, JSON_UNESCAPED_UNICODE));
return $documents;
} catch (PDOException $e) {
logMessage("Ошибка при выполнении запроса к CRM: " . $e->getMessage());
return [];
}
}
if (!function_exists('sendAnalysisToCRM')) {
function sendAnalysisToCRM($caseId, $analysis) {
// Обеспечим наличие нужных ключей
/* if (!isset($analysis['content'])) {
$analysis['content'] = $analysis['анализ_gpt'] ?? 'Анализ не выполнен';
} */
if (!isset($analysis['moderationVerdict'])) {
$analysis['moderationVerdict'] = $analysis['вывод_gpt'] ?? 'Не определен';
}
if (!isset($analysis['status'])) {
$analysis['status'] = 'complete';
}
$final_output = [
"status" => $analysis['status'],
"content" => $analysis['content'],
"moderationVerdict" => $analysis['moderationVerdict']
];
$json_output = json_encode($final_output, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
if ($json_output === false) {
$error = json_last_error_msg();
logMessage("ERROR: Ошибка кодирования JSON: $error");
die(json_encode(["status" => "error", "message" => "Ошибка формирования ответа"]));
}
logMessage("DEBUG: Итоговый JSON для CRM: " . $json_output);
// Устанавливаем заголовок для JSON
header('Content-Type: application/json; charset=utf-8');
echo $json_output;
logMessage("Обработка завершена. Ответ успешно отправлен в CRM");
exit;
}
}
?>