180 lines
7.6 KiB
HTML
180 lines
7.6 KiB
HTML
|
|
<!DOCTYPE html>
|
||
|
|
<html lang="ru">
|
||
|
|
<head>
|
||
|
|
<meta charset="UTF-8">
|
||
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
|
<title>Тест n8n Debug</title>
|
||
|
|
<style>
|
||
|
|
body { font-family: Arial, sans-serif; margin: 20px; }
|
||
|
|
.container { max-width: 800px; margin: 0 auto; }
|
||
|
|
.log { background: #f5f5f5; padding: 15px; border-radius: 5px; margin: 10px 0; font-family: monospace; white-space: pre-wrap; }
|
||
|
|
.button { background: #007bff; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; margin: 5px; }
|
||
|
|
.button:hover { background: #0056b3; }
|
||
|
|
.error { background: #f8d7da; color: #721c24; }
|
||
|
|
.success { background: #d4edda; color: #155724; }
|
||
|
|
.info { background: #d1ecf1; color: #0c5460; }
|
||
|
|
</style>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div class="container">
|
||
|
|
<h1>🔍 Тест n8n Debug</h1>
|
||
|
|
|
||
|
|
<h3>1. Тест истории чата:</h3>
|
||
|
|
<button class="button" onclick="testHistory()">Запросить историю</button>
|
||
|
|
<div id="history-result" class="log"></div>
|
||
|
|
|
||
|
|
<h3>2. Тест основного ассистента:</h3>
|
||
|
|
<input type="text" id="message-input" placeholder="Введите сообщение..." style="width: 300px; padding: 8px;">
|
||
|
|
<button class="button" onclick="testAssistant()">Отправить ассистенту</button>
|
||
|
|
<div id="assistant-result" class="log"></div>
|
||
|
|
|
||
|
|
<h3>3. Логи:</h3>
|
||
|
|
<button class="button" onclick="clearLogs()">Очистить логи</button>
|
||
|
|
<div id="debug-logs" class="log"></div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
function log(message, type = 'info') {
|
||
|
|
const timestamp = new Date().toLocaleTimeString();
|
||
|
|
const logDiv = document.getElementById('debug-logs');
|
||
|
|
const entry = document.createElement('div');
|
||
|
|
entry.className = `log ${type}`;
|
||
|
|
entry.textContent = `[${timestamp}] ${message}`;
|
||
|
|
logDiv.appendChild(entry);
|
||
|
|
logDiv.scrollTop = logDiv.scrollHeight;
|
||
|
|
console.log(`[${type.toUpperCase()}] ${message}`);
|
||
|
|
}
|
||
|
|
|
||
|
|
function clearLogs() {
|
||
|
|
document.getElementById('debug-logs').innerHTML = '';
|
||
|
|
document.getElementById('history-result').innerHTML = '';
|
||
|
|
document.getElementById('assistant-result').innerHTML = '';
|
||
|
|
}
|
||
|
|
|
||
|
|
async function testHistory() {
|
||
|
|
log('Запрос истории чата...', 'info');
|
||
|
|
|
||
|
|
try {
|
||
|
|
const payload = {
|
||
|
|
context: {
|
||
|
|
projectId: "test123",
|
||
|
|
currentModule: "Contacts",
|
||
|
|
currentView: "Detail",
|
||
|
|
userId: "1",
|
||
|
|
userName: "Фёдор",
|
||
|
|
userEmail: "test@example.com",
|
||
|
|
projectName: "Тестовый проект",
|
||
|
|
pageTitle: "CRM Test",
|
||
|
|
currentDate: "19.09.2025",
|
||
|
|
url: window.location.href,
|
||
|
|
timestamp: Date.now()
|
||
|
|
},
|
||
|
|
sessionId: "test-session-" + Date.now()
|
||
|
|
};
|
||
|
|
|
||
|
|
const response = await fetch('/get_chat_history.php', {
|
||
|
|
method: 'POST',
|
||
|
|
headers: {
|
||
|
|
'Content-Type': 'application/json',
|
||
|
|
},
|
||
|
|
body: JSON.stringify(payload)
|
||
|
|
});
|
||
|
|
|
||
|
|
const data = await response.json();
|
||
|
|
|
||
|
|
document.getElementById('history-result').textContent = JSON.stringify(data, null, 2);
|
||
|
|
|
||
|
|
if (data.success) {
|
||
|
|
log(`История получена: ${data.count || 0} сообщений`, 'success');
|
||
|
|
} else {
|
||
|
|
log(`Ошибка получения истории: ${data.error}`, 'error');
|
||
|
|
}
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
log(`Ошибка запроса истории: ${error.message}`, 'error');
|
||
|
|
document.getElementById('history-result').textContent = `Ошибка: ${error.message}`;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
async function testAssistant() {
|
||
|
|
const messageInput = document.getElementById('message-input');
|
||
|
|
const message = messageInput.value.trim();
|
||
|
|
|
||
|
|
if (!message) {
|
||
|
|
log('Введите сообщение для отправки', 'error');
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
log(`Отправка сообщения ассистенту: "${message}"`, 'info');
|
||
|
|
|
||
|
|
try {
|
||
|
|
const payload = {
|
||
|
|
message: message,
|
||
|
|
context: {
|
||
|
|
projectId: "test123",
|
||
|
|
currentModule: "Contacts",
|
||
|
|
currentView: "Detail",
|
||
|
|
userId: "1",
|
||
|
|
userName: "Фёдор",
|
||
|
|
userEmail: "test@example.com",
|
||
|
|
projectName: "Тестовый проект",
|
||
|
|
pageTitle: "CRM Test",
|
||
|
|
currentDate: "19.09.2025",
|
||
|
|
url: window.location.href,
|
||
|
|
timestamp: Date.now()
|
||
|
|
},
|
||
|
|
sessionId: "test-session-" + Date.now()
|
||
|
|
};
|
||
|
|
|
||
|
|
const startTime = Date.now();
|
||
|
|
|
||
|
|
const response = await fetch('/aiassist/n8n_proxy.php', {
|
||
|
|
method: 'POST',
|
||
|
|
headers: {
|
||
|
|
'Content-Type': 'application/json',
|
||
|
|
},
|
||
|
|
body: JSON.stringify(payload)
|
||
|
|
});
|
||
|
|
|
||
|
|
const endTime = Date.now();
|
||
|
|
const duration = endTime - startTime;
|
||
|
|
|
||
|
|
log(`Ответ получен за ${duration}ms`, 'info');
|
||
|
|
|
||
|
|
if (!response.ok) {
|
||
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
||
|
|
}
|
||
|
|
|
||
|
|
const data = await response.json();
|
||
|
|
|
||
|
|
document.getElementById('assistant-result').textContent = JSON.stringify(data, null, 2);
|
||
|
|
|
||
|
|
if (data.error) {
|
||
|
|
log(`Ошибка от ассистента: ${data.error}`, 'error');
|
||
|
|
} else if (data.response) {
|
||
|
|
log(`Ответ ассистента получен (${data.response.length} символов)`, 'success');
|
||
|
|
} else {
|
||
|
|
log('Ответ получен, но нет поля response', 'error');
|
||
|
|
}
|
||
|
|
|
||
|
|
// Очищаем поле ввода
|
||
|
|
messageInput.value = '';
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
log(`Ошибка запроса к ассистенту: ${error.message}`, 'error');
|
||
|
|
document.getElementById('assistant-result').textContent = `Ошибка: ${error.message}`;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Обработчик Enter в поле ввода
|
||
|
|
document.getElementById('message-input').addEventListener('keypress', function(e) {
|
||
|
|
if (e.key === 'Enter') {
|
||
|
|
testAssistant();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
log('Страница загружена, готов к тестированию', 'info');
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|