Files
crm.clientright.ru/test_n8n_integration.html

139 lines
6.4 KiB
HTML
Raw Permalink 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.

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Тест интеграции с n8n</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
.test-section { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
.success { background-color: #d4edda; border-color: #c3e6cb; }
.error { background-color: #f8d7da; border-color: #f5c6cb; }
.info { background-color: #d1ecf1; border-color: #bee5eb; }
button { padding: 10px 20px; margin: 5px; cursor: pointer; }
pre { background: #f8f9fa; padding: 10px; border-radius: 3px; overflow-x: auto; }
</style>
</head>
<body>
<h1>🧪 Тест интеграции с n8n</h1>
<div class="test-section info">
<h3>📋 Информация</h3>
<p><strong>n8n Webhook URL:</strong> https://n8n.clientright.pro/webhook/0b20bf1e-7cda-4dc8-899e-a7c3be4096c0</p>
<p><strong>Proxy URL:</strong> https://crm.clientright.ru/aiassist/n8n_proxy.php</p>
</div>
<div class="test-section">
<h3>🔗 Тест 1: Прямое подключение к n8n</h3>
<button onclick="testDirectN8N()">Тест прямого подключения</button>
<div id="direct-result"></div>
</div>
<div class="test-section">
<h3>🔄 Тест 2: Через proxy</h3>
<button onclick="testProxyN8N()">Тест через proxy</button>
<div id="proxy-result"></div>
</div>
<div class="test-section">
<h3>📊 Тест 3: С полным контекстом CRM</h3>
<button onclick="testFullContext()">Тест с контекстом</button>
<div id="context-result"></div>
</div>
<script>
async function testDirectN8N() {
const resultDiv = document.getElementById('direct-result');
resultDiv.innerHTML = '<p>⏳ Тестируем прямое подключение...</p>';
try {
const response = await fetch('https://n8n.clientright.pro/webhook/0b20bf1e-7cda-4dc8-899e-a7c3be4096c0', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
message: 'Тест прямого подключения',
context: { test: true },
sessionId: 'direct-test-' + Date.now()
})
});
if (response.ok) {
const data = await response.json();
resultDiv.innerHTML = `<div class="success"><h4>✅ Успешно!</h4><pre>${JSON.stringify(data, null, 2)}</pre></div>`;
} else {
resultDiv.innerHTML = `<div class="error"><h4>❌ Ошибка HTTP ${response.status}</h4><p>${await response.text()}</p></div>`;
}
} catch (error) {
resultDiv.innerHTML = `<div class="error"><h4>❌ Ошибка подключения</h4><p>${error.message}</p></div>`;
}
}
async function testProxyN8N() {
const resultDiv = document.getElementById('proxy-result');
resultDiv.innerHTML = '<p>⏳ Тестируем через proxy...</p>';
try {
const response = await fetch('/aiassist/n8n_proxy.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
message: 'Тест через proxy',
context: { test: true },
sessionId: 'proxy-test-' + Date.now()
})
});
if (response.ok) {
const data = await response.json();
resultDiv.innerHTML = `<div class="success"><h4>✅ Успешно!</h4><pre>${JSON.stringify(data, null, 2)}</pre></div>`;
} else {
resultDiv.innerHTML = `<div class="error"><h4>❌ Ошибка HTTP ${response.status}</h4><p>${await response.text()}</p></div>`;
}
} catch (error) {
resultDiv.innerHTML = `<div class="error"><h4>❌ Ошибка подключения</h4><p>${error.message}</p></div>`;
}
}
async function testFullContext() {
const resultDiv = document.getElementById('context-result');
resultDiv.innerHTML = '<p>⏳ Тестируем с полным контекстом...</p>';
const fullContext = {
projectId: '391604',
module: 'Project',
view: 'Detail',
userId: '8',
userName: 'Фёдор',
userEmail: 'user@example.com',
projectName: 'Тестовый проект',
pageTitle: 'Тестовая страница',
currentDate: new Date().toISOString().split('T')[0],
url: window.location.href,
timestamp: new Date().toISOString()
};
try {
const response = await fetch('/aiassist/n8n_proxy.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
message: 'Привет! Это тест с полным контекстом CRM',
context: fullContext,
sessionId: 'context-test-' + Date.now()
})
});
if (response.ok) {
const data = await response.json();
resultDiv.innerHTML = `<div class="success"><h4>✅ Успешно!</h4><pre>${JSON.stringify(data, null, 2)}</pre></div>`;
} else {
resultDiv.innerHTML = `<div class="error"><h4>❌ Ошибка HTTP ${response.status}</h4><p>${await response.text()}</p></div>`;
}
} catch (error) {
resultDiv.innerHTML = `<div class="error"><h4>❌ Ошибка подключения</h4><p>${error.message}</p></div>`;
}
}
</script>
</body>
</html>