API key working, CORS working, SocketIO working (but no JWT), Chat client v1, Session implemented (server side)
This commit is contained in:
66
eveai_chat/static/eve_ai_chat.html
Normal file
66
eveai_chat/static/eve_ai_chat.html
Normal file
@@ -0,0 +1,66 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Chat Client</title>
|
||||
<script src="https://cdn.socket.io/4.0.0/socket.io.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Chat Client</h1>
|
||||
<button onclick="registerClient()">Register Client</button>
|
||||
<div>
|
||||
<input type="text" id="message" placeholder="Enter your message">
|
||||
<button onclick="sendMessage()">Send Message</button>
|
||||
</div>
|
||||
<div id="messages"></div>
|
||||
|
||||
<script>
|
||||
let socket;
|
||||
|
||||
async function registerClient() {
|
||||
const tenantId = '1';
|
||||
const apiKey = 'EveAI-CHAT-8553-7987-2800-9115-6454';
|
||||
|
||||
const response = await fetch('http://127.0.0.1:5001/chat/register_client', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ tenant_id: tenantId, api_key: apiKey })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
const token = data.token;
|
||||
|
||||
socket = io('http://127.0.0.1:5001/chat', {
|
||||
auth: {
|
||||
token: `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('connect', () => {
|
||||
console.log('Connected to server');
|
||||
});
|
||||
|
||||
socket.on('response', (msg) => {
|
||||
const messagesDiv = document.getElementById('messages');
|
||||
const messageElement = document.createElement('div');
|
||||
messageElement.innerText = `Response: ${msg.data}`;
|
||||
messagesDiv.appendChild(messageElement);
|
||||
});
|
||||
} else {
|
||||
console.error('Registration failed');
|
||||
}
|
||||
}
|
||||
|
||||
function sendMessage() {
|
||||
const message = document.getElementById('message').value;
|
||||
if (socket) {
|
||||
socket.emit('message', { content: message });
|
||||
} else {
|
||||
console.error('Socket not connected');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
20
eveai_chat/static/eveai_chat.html
Normal file
20
eveai_chat/static/eveai_chat.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Chat Client</title>
|
||||
<link rel="stylesheet" href="css/eveai-chat-style.css">
|
||||
<script src="js/eveai-sdk.js" defer></script>
|
||||
<script src="js/eveai-chat-widget.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="chat-container"></div>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const eveAI = new EveAI('tenant-id', 'EVEAI-CHAT-xxxx-xxxx-xxxx-xxxx-xxxx');
|
||||
eveAI.initializeChat('chat-container');
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user