Version 1 of chatbot frontend

This commit is contained in:
2025-04-02 02:11:58 +01:00
commit e9894b7fa7
5 changed files with 398 additions and 0 deletions

142
snippet.js Normal file
View File

@@ -0,0 +1,142 @@
// snippet.js
const chatHTML = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat with n8n</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
background-color: #f4f4f9;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.chat-container {
width: 100%;
max-width: 600px; /* Maximum width for larger screens */
border: 1px solid #ccc;
border-radius: 8px;
overflow: hidden;
display: flex;
flex-direction: column;
height: 100vh;
}
.avatar-container {
display: flex;
align-items: center;
padding: 10px;
background-color: #f4f4f9;
}
.avatar-container img {
margin-right: 0; /* Remove space between the avatar and text */
}
#chat-messages {
flex-grow: 1;
padding: 10px;
overflow-y: auto;
background-color: white;
}
.user-message {
background-color: #d4edda; /* Green background for user messages */
margin-bottom: 10px;
padding: 8px;
border-radius: 5px;
display: flex;
align-items: center;
justify-content: flex-end;
margin-left: 100px;
}
.bot-message {
background-color: #cce5ff; /* Blue background for bot messages */
margin-bottom: 10px;
padding: 8px;
border-radius: 5px;
display: flex;
align-items: center;
justify-content: flex-start;
margin-right: 100px;
}
input[type="text"] {
width: calc(100% - 22px);
padding: 10px;
border: none;
border-top: 1px solid #ccc;
}
button {
padding: 10px;
border: none;
background-color: #004085; /* Deep blue background for the send button */
color: white;
cursor: pointer;
border-radius: 0 0 8px 8px;
}
button:hover {
background-color: #002a5c; /* Darker deep blue on hover */
}
</style>
</head>
<body>
<div class="chat-container">
<div class="avatar-container">
<img src="bot-avatar.png" alt="Bot Avatar" class="bot-avatar">
<h2>Chat with Paul</h2>
</div>
<div id="chat-messages"></div>
<input type="text" id="user-input" placeholder="Type a message...">
<button onclick="sendMessage()">Send</button>
</div>
<script>
function sendMessage() {
const userInput = document.getElementById('user-input');
const chatMessages = document.getElementById('chat-messages');
if (userInput.value.trim() === '') return;
// Create user message
const userMessage = document.createElement('div');
userMessage.classList.add('user-message');
userMessage.textContent = userInput.value;
chatMessages.appendChild(userMessage);
// Clear input field
userInput.value = '';
// Simulate bot response (for demonstration purposes)
setTimeout(() => {
const botMessage = document.createElement('div');
botMessage.classList.add('bot-message');
botMessage.textContent = 'This is a bot response.';
chatMessages.appendChild(botMessage);
}, 1000);
// Scroll to bottom
chatMessages.scrollTop = chatMessages.scrollHeight;
}
</script>
</body>
</html>
`;
function injectChat() {
const container = document.createElement('div');
container.innerHTML = chatHTML;
document.body.appendChild(container);
}
// Inject the chat when the script is loaded
injectChat();