Files
crm.clientright.ru/test_typebot_integration.html

159 lines
6.4 KiB
HTML
Raw Permalink Normal View History

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Тест Typebot интеграции</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
.test-section { margin: 20px 0; padding: 15px; border: 1px solid #ddd; }
.result { background: #f5f5f5; padding: 10px; margin: 10px 0; }
button { padding: 10px 20px; margin: 5px; }
input { padding: 8px; width: 300px; }
</style>
</head>
<body>
<h1>Тест интеграции Typebot с CRM</h1>
<div class="test-section">
<h3>1. Тест startChat</h3>
<input type="text" id="startMessage" placeholder="Введите сообщение для начала чата" value="привет">
<button onclick="testStartChat()">Начать чат</button>
<div id="startResult" class="result"></div>
</div>
<div class="test-section">
<h3>2. Тест continueChat</h3>
<input type="text" id="continueMessage" placeholder="Введите сообщение для продолжения" value="как дела?">
<button onclick="testContinueChat()">Продолжить чат</button>
<div id="continueResult" class="result"></div>
</div>
<div class="test-section">
<h3>3. Тест с контекстом CRM</h3>
<input type="text" id="contextMessage" placeholder="Введите сообщение с контекстом" value="покажи клиентов">
<button onclick="testWithContext()">Тест с контекстом</button>
<div id="contextResult" class="result"></div>
</div>
<script>
let sessionId = null;
async function testStartChat() {
const message = document.getElementById('startMessage').value;
const resultDiv = document.getElementById('startResult');
try {
const response = await fetch('https://bot.klientprav.tech/api/v1/typebots/my-typebot-lezm06l/startChat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: {
type: "text",
text: message
},
prefilledVariables: {
"projectId": "test-123",
"module": "Accounts",
"view": "DetailView",
"userId": "test-user"
}
})
});
const data = await response.json();
sessionId = data.sessionId;
resultDiv.innerHTML = `
<strong>Успешно!</strong><br>
Session ID: ${sessionId}<br>
Messages: ${JSON.stringify(data.messages, null, 2)}<br>
Full response: <pre>${JSON.stringify(data, null, 2)}</pre>
`;
} catch (error) {
resultDiv.innerHTML = `<strong>Ошибка:</strong> ${error.message}`;
}
}
async function testContinueChat() {
if (!sessionId) {
document.getElementById('continueResult').innerHTML = '<strong>Ошибка:</strong> Сначала начните чат';
return;
}
const message = document.getElementById('continueMessage').value;
const resultDiv = document.getElementById('continueResult');
try {
const response = await fetch(`https://bot.klientprav.tech/api/v1/sessions/${sessionId}/continueChat`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: message
})
});
const data = await response.json();
resultDiv.innerHTML = `
<strong>Успешно!</strong><br>
Messages: ${JSON.stringify(data.messages, null, 2)}<br>
Client Side Actions: ${JSON.stringify(data.clientSideActions, null, 2)}<br>
Full response: <pre>${JSON.stringify(data, null, 2)}</pre>
`;
} catch (error) {
resultDiv.innerHTML = `<strong>Ошибка:</strong> ${error.message}`;
}
}
async function testWithContext() {
const message = document.getElementById('contextMessage').value;
const resultDiv = document.getElementById('contextResult');
try {
const response = await fetch('https://bot.klientprav.tech/api/v1/typebots/my-typebot-lezm06l/startChat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: {
type: "text",
text: message
},
prefilledVariables: {
"projectId": "CRM-RECORD-456",
"module": "Contacts",
"view": "ListView",
"userId": "admin",
"userRole": "Administrator",
"currentPage": "Contacts"
}
})
});
const data = await response.json();
resultDiv.innerHTML = `
<strong>Успешно!</strong><br>
Session ID: ${data.sessionId}<br>
Messages: ${JSON.stringify(data.messages, null, 2)}<br>
Full response: <pre>${JSON.stringify(data, null, 2)}</pre>
`;
} catch (error) {
resultDiv.innerHTML = `<strong>Ошибка:</strong> ${error.message}`;
}
}
</script>
</body>
</html>