Files
crm.clientright.ru/test_crm_integration.html

286 lines
11 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>Тест интеграции CRM с Typebot</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
border-radius: 10px;
padding: 20px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.test-section {
background: #e3f2fd;
padding: 15px;
border-radius: 8px;
margin: 15px 0;
}
.result {
background: #f3e5f5;
padding: 10px;
border-radius: 5px;
margin: 10px 0;
white-space: pre-wrap;
font-family: monospace;
font-size: 12px;
}
.error {
background: #ffebee;
color: #c62828;
}
.success {
background: #e8f5e8;
color: #2e7d32;
}
button {
background: #2196f3;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
margin: 5px;
}
button:hover {
background: #1976d2;
}
input[type="text"] {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
margin: 5px 0;
}
</style>
</head>
<body>
<div class="container">
<h1>🧪 Тест интеграции CRM с Typebot</h1>
<div class="test-section">
<h3>1. Тест прокси Typebot</h3>
<input type="text" id="testMessage" placeholder="Введите тестовое сообщение..." value="Привет, это тест из CRM">
<button onclick="testProxy()">Тестировать прокси</button>
<div id="proxyResult" class="result"></div>
</div>
<div class="test-section">
<h3>2. Тест прямого обращения к Typebot</h3>
<button onclick="testDirectTypebot()">Тестировать прямое обращение</button>
<div id="directResult" class="result"></div>
</div>
<div class="test-section">
<h3>3. Тест CORS</h3>
<button onclick="testCORS()">Тестировать CORS</button>
<div id="corsResult" class="result"></div>
</div>
<div class="test-section">
<h3>4. Симуляция CRM контекста</h3>
<button onclick="testCRMContext()">Тестировать с CRM контекстом</button>
<div id="crmResult" class="result"></div>
</div>
<div class="test-section">
<h3>5. Полный тест интеграции</h3>
<button onclick="testFullIntegration()">Полный тест</button>
<div id="fullResult" class="result"></div>
</div>
</div>
<script>
const PROXY_URL = '/aiassist/typebot_proxy.php';
const TYPEBOT_URL = 'https://bot.klientprav.tech/api/v1/typebots/my-typebot-lezm06l/startChat';
function showResult(elementId, content, isError = false) {
const element = document.getElementById(elementId);
element.textContent = content;
element.className = `result ${isError ? 'error' : 'success'}`;
}
async function testProxy() {
const message = document.getElementById('testMessage').value;
showResult('proxyResult', 'Тестирование прокси...');
try {
const response = await fetch(PROXY_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
action: 'startChat',
message: message,
context: {
projectId: 'test-123',
module: 'Accounts',
view: 'Detail',
userId: '1'
}
})
});
const result = await response.json();
if (result.success) {
showResult('proxyResult', `✅ Прокси работает!\n\nОтвет:\n${JSON.stringify(result.data, null, 2)}`);
} else {
showResult('proxyResult', `❌ Ошибка прокси:\n${result.error}`, true);
}
} catch (error) {
showResult('proxyResult', `❌ Ошибка сети:\n${error.message}`, true);
}
}
async function testDirectTypebot() {
showResult('directResult', 'Тестирование прямого обращения...');
try {
const response = await fetch(TYPEBOT_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: {
type: 'text',
text: 'Тест прямого обращения'
},
prefilledVariables: {
projectId: 'test-123',
module: 'Accounts',
view: 'Detail',
userId: '1'
}
})
});
if (response.ok) {
const result = await response.json();
showResult('directResult', `✅ Прямое обращение работает!\n\nОтвет:\n${JSON.stringify(result, null, 2)}`);
} else {
showResult('directResult', `❌ Ошибка прямого обращения:\nHTTP ${response.status}: ${response.statusText}`, true);
}
} catch (error) {
showResult('directResult', `❌ CORS ошибка (ожидаемо):\n${error.message}`, true);
}
}
async function testCORS() {
showResult('corsResult', 'Тестирование CORS...');
try {
// Пробуем запрос к внешнему домену
const response = await fetch('https://httpbin.org/get');
const result = await response.json();
showResult('corsResult', `✅ CORS работает для httpbin.org\n\nОтвет:\n${JSON.stringify(result, null, 2)}`);
} catch (error) {
showResult('corsResult', `❌ CORS ошибка:\n${error.message}`, true);
}
}
async function testCRMContext() {
showResult('crmResult', 'Тестирование с CRM контекстом...');
try {
const response = await fetch(PROXY_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
action: 'startChat',
message: 'Покажи информацию о проекте',
context: {
projectId: 'PROJ-2024-001',
module: 'Project',
view: 'Detail',
userId: 'admin',
userName: 'Администратор',
currentUrl: window.location.href,
timestamp: new Date().toISOString()
}
})
});
const result = await response.json();
if (result.success) {
showResult('crmResult', `✅ CRM контекст работает!\n\nОтвет:\n${JSON.stringify(result.data, null, 2)}`);
} else {
showResult('crmResult', `❌ Ошибка с CRM контекстом:\n${result.error}`, true);
}
} catch (error) {
showResult('crmResult', `❌ Ошибка сети:\n${error.message}`, true);
}
}
async function testFullIntegration() {
showResult('fullResult', 'Полный тест интеграции...');
let results = [];
// Тест 1: Прокси
try {
const proxyResponse = await fetch(PROXY_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
action: 'startChat',
message: 'Полный тест интеграции',
context: { projectId: 'full-test', module: 'Test', view: 'Test', userId: 'test' }
})
});
const proxyResult = await proxyResponse.json();
results.push(`✅ Прокси: ${proxyResult.success ? 'OK' : 'ERROR'}`);
if (proxyResult.success && proxyResult.data.sessionId) {
// Тест 2: Продолжение сессии
const continueResponse = await fetch(PROXY_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
action: 'continueChat',
sessionId: proxyResult.data.sessionId,
message: 'Второе сообщение в сессии'
})
});
const continueResult = await continueResponse.json();
results.push(`✅ Продолжение сессии: ${continueResult.success ? 'OK' : 'ERROR'}`);
}
} catch (error) {
results.push(`❌ Прокси: ${error.message}`);
}
// Тест 3: Проверка доступности Typebot
try {
const typebotResponse = await fetch('https://bot.klientprav.tech/api/v1/typebots/my-typebot-lezm06l');
results.push(`✅ Typebot доступен: ${typebotResponse.ok ? 'OK' : 'ERROR'}`);
} catch (error) {
results.push(`❌ Typebot недоступен: ${error.message}`);
}
showResult('fullResult', `Результаты полного теста:\n\n${results.join('\n')}`);
}
// Автоматический тест при загрузке
window.onload = function() {
console.log('Тест интеграции CRM загружен');
setTimeout(testProxy, 1000);
};
</script>
</body>
</html>