Files
crm.clientright.ru/callback_ai_response.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

84 lines
2.4 KiB
PHP

<?php
// callback_ai_response.php
// Endpoint для приема ответов от n8n
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit();
}
error_reporting(E_ALL);
ini_set('display_errors', 1);
try {
// Подключаемся к БД
include_once('config.inc.php');
$conn = new mysqli($dbconfig['db_server'], $dbconfig['db_username'], $dbconfig['db_password'], $dbconfig['db_name']);
if ($conn->connect_error) {
throw new Exception("DB connection failed: " . $conn->connect_error);
}
$conn->set_charset('utf8mb4');
// Получаем данные от n8n
$input = json_decode(file_get_contents('php://input'), true);
if (!$input) {
throw new Exception('Invalid JSON input');
}
$taskId = $input['taskId'] ?? null;
$response = $input['response'] ?? null;
$status = $input['status'] ?? 'completed';
$error = $input['error'] ?? null;
if (!$taskId) {
throw new Exception('Missing taskId');
}
error_log("Callback: Received response for task {$taskId}, status: {$status}");
// Обновляем запись в БД
if ($status === 'error') {
$stmt = $conn->prepare("UPDATE ai_responses SET status = 'error', error_message = ?, updated_at = NOW() WHERE task_id = ?");
$stmt->bind_param('ss', $error, $taskId);
} else {
$stmt = $conn->prepare("UPDATE ai_responses SET status = 'completed', response_data = ?, updated_at = NOW() WHERE task_id = ?");
$stmt->bind_param('ss', $response, $taskId);
}
if (!$stmt->execute()) {
throw new Exception("Failed to update task: " . $stmt->error);
}
$affected = $stmt->affected_rows;
$stmt->close();
$conn->close();
error_log("Callback: Updated task {$taskId}, affected rows: {$affected}");
echo json_encode([
'success' => true,
'message' => 'Response received',
'taskId' => $taskId,
'affected' => $affected
]);
} catch (Exception $e) {
error_log("Callback Error: " . $e->getMessage());
http_response_code(500);
echo json_encode([
'success' => false,
'error' => $e->getMessage()
]);
}
?>