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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>SmartlyQ Chat</title>
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<style>
|
7 |
+
:root {
|
8 |
+
--primary-color: #4F46E5;
|
9 |
+
--primary-hover: #4338CA;
|
10 |
+
--bg-color: #F9FAFB;
|
11 |
+
--user-msg-bg: #EEF2FF;
|
12 |
+
--bot-msg-bg: #ffffff;
|
13 |
+
--text-primary: #111827;
|
14 |
+
--text-secondary: #6B7280;
|
15 |
+
}
|
16 |
+
|
17 |
+
* {
|
18 |
+
box-sizing: border-box;
|
19 |
+
margin: 0;
|
20 |
+
padding: 0;
|
21 |
+
}
|
22 |
+
|
23 |
+
body {
|
24 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
25 |
+
margin: 0;
|
26 |
+
background-color: var(--bg-color);
|
27 |
+
height: 100vh;
|
28 |
+
display: flex;
|
29 |
+
flex-direction: column;
|
30 |
+
}
|
31 |
+
|
32 |
+
.header {
|
33 |
+
background: white;
|
34 |
+
padding: 1rem;
|
35 |
+
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
36 |
+
text-align: center;
|
37 |
+
position: sticky;
|
38 |
+
top: 0;
|
39 |
+
z-index: 10;
|
40 |
+
}
|
41 |
+
|
42 |
+
.header h1 {
|
43 |
+
font-size: 1.5rem;
|
44 |
+
color: var(--text-primary);
|
45 |
+
font-weight: 600;
|
46 |
+
}
|
47 |
+
|
48 |
+
#chat-container {
|
49 |
+
flex: 1;
|
50 |
+
padding: 1.5rem;
|
51 |
+
overflow-y: auto;
|
52 |
+
scroll-behavior: smooth;
|
53 |
+
background: var(--bg-color);
|
54 |
+
}
|
55 |
+
|
56 |
+
.message {
|
57 |
+
margin: 1rem 0;
|
58 |
+
max-width: 80%;
|
59 |
+
animation: fadeIn 0.3s ease-in-out;
|
60 |
+
}
|
61 |
+
|
62 |
+
@keyframes fadeIn {
|
63 |
+
from { opacity: 0; transform: translateY(10px); }
|
64 |
+
to { opacity: 1; transform: translateY(0); }
|
65 |
+
}
|
66 |
+
|
67 |
+
.message-content {
|
68 |
+
padding: 1rem;
|
69 |
+
border-radius: 1rem;
|
70 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
71 |
+
line-height: 1.5;
|
72 |
+
}
|
73 |
+
|
74 |
+
.message-timestamp {
|
75 |
+
font-size: 0.75rem;
|
76 |
+
color: var(--text-secondary);
|
77 |
+
margin-top: 0.25rem;
|
78 |
+
margin-left: 0.5rem;
|
79 |
+
}
|
80 |
+
|
81 |
+
.user-message {
|
82 |
+
margin-left: auto;
|
83 |
+
}
|
84 |
+
|
85 |
+
.bot-message {
|
86 |
+
margin-right: auto;
|
87 |
+
}
|
88 |
+
|
89 |
+
.user-message .message-content {
|
90 |
+
background: var(--user-msg-bg);
|
91 |
+
color: var(--text-primary);
|
92 |
+
}
|
93 |
+
|
94 |
+
.bot-message .message-content {
|
95 |
+
background: var(--bot-msg-bg);
|
96 |
+
color: var(--text-primary);
|
97 |
+
}
|
98 |
+
|
99 |
+
#input-container {
|
100 |
+
background: white;
|
101 |
+
padding: 1rem;
|
102 |
+
box-shadow: 0 -1px 3px rgba(0,0,0,0.1);
|
103 |
+
position: sticky;
|
104 |
+
bottom: 0;
|
105 |
+
display: flex;
|
106 |
+
gap: 0.75rem;
|
107 |
+
align-items: center;
|
108 |
+
}
|
109 |
+
|
110 |
+
#query-input {
|
111 |
+
flex: 1;
|
112 |
+
padding: 0.75rem 1rem;
|
113 |
+
border: 2px solid #E5E7EB;
|
114 |
+
border-radius: 0.75rem;
|
115 |
+
font-size: 1rem;
|
116 |
+
transition: border-color 0.2s ease;
|
117 |
+
outline: none;
|
118 |
+
}
|
119 |
+
|
120 |
+
#query-input:focus {
|
121 |
+
border-color: var(--primary-color);
|
122 |
+
}
|
123 |
+
|
124 |
+
#send-button {
|
125 |
+
padding: 0.75rem 1.5rem;
|
126 |
+
background-color: var(--primary-color);
|
127 |
+
color: white;
|
128 |
+
border: none;
|
129 |
+
border-radius: 0.75rem;
|
130 |
+
cursor: pointer;
|
131 |
+
font-weight: 600;
|
132 |
+
transition: background-color 0.2s ease, transform 0.1s ease;
|
133 |
+
}
|
134 |
+
|
135 |
+
#send-button:hover {
|
136 |
+
background-color: var(--primary-hover);
|
137 |
+
}
|
138 |
+
|
139 |
+
#send-button:active {
|
140 |
+
transform: scale(0.98);
|
141 |
+
}
|
142 |
+
|
143 |
+
#send-button:disabled {
|
144 |
+
opacity: 0.7;
|
145 |
+
cursor: not-allowed;
|
146 |
+
}
|
147 |
+
|
148 |
+
.typing-indicator {
|
149 |
+
display: flex;
|
150 |
+
gap: 0.5rem;
|
151 |
+
padding: 1rem;
|
152 |
+
background: var(--bot-msg-bg);
|
153 |
+
border-radius: 1rem;
|
154 |
+
width: fit-content;
|
155 |
+
margin: 1rem 0;
|
156 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
157 |
+
}
|
158 |
+
|
159 |
+
.typing-dot {
|
160 |
+
width: 8px;
|
161 |
+
height: 8px;
|
162 |
+
background: var(--text-secondary);
|
163 |
+
border-radius: 50%;
|
164 |
+
animation: typingAnimation 1.4s infinite;
|
165 |
+
}
|
166 |
+
|
167 |
+
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
|
168 |
+
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
|
169 |
+
|
170 |
+
@keyframes typingAnimation {
|
171 |
+
0%, 60%, 100% { transform: translateY(0); }
|
172 |
+
30% { transform: translateY(-4px); }
|
173 |
+
}
|
174 |
+
|
175 |
+
@media (max-width: 640px) {
|
176 |
+
.message {
|
177 |
+
max-width: 90%;
|
178 |
+
}
|
179 |
+
|
180 |
+
#input-container {
|
181 |
+
padding: 0.75rem;
|
182 |
+
}
|
183 |
+
|
184 |
+
#send-button {
|
185 |
+
padding: 0.75rem 1rem;
|
186 |
+
}
|
187 |
+
}
|
188 |
+
</style>
|
189 |
+
</head>
|
190 |
+
<body>
|
191 |
+
<div class="header">
|
192 |
+
<h1>SmartlyQ Assistant</h1>
|
193 |
+
</div>
|
194 |
+
<div id="chat-container"></div>
|
195 |
+
<div id="input-container">
|
196 |
+
<input type="text" id="query-input" placeholder="Type your message...">
|
197 |
+
<button id="send-button">Send</button>
|
198 |
+
</div>
|
199 |
+
|
200 |
+
<script>
|
201 |
+
const urlParams = new URLSearchParams(window.location.search);
|
202 |
+
const botId = urlParams.get('botid');
|
203 |
+
const chatContainer = document.getElementById('chat-container');
|
204 |
+
const queryInput = document.getElementById('query-input');
|
205 |
+
const sendButton = document.getElementById('send-button');
|
206 |
+
|
207 |
+
function getTimestamp() {
|
208 |
+
return new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
209 |
+
}
|
210 |
+
|
211 |
+
function createTypingIndicator() {
|
212 |
+
const indicator = document.createElement('div');
|
213 |
+
indicator.className = 'typing-indicator';
|
214 |
+
indicator.innerHTML = `
|
215 |
+
<div class="typing-dot"></div>
|
216 |
+
<div class="typing-dot"></div>
|
217 |
+
<div class="typing-dot"></div>
|
218 |
+
`;
|
219 |
+
return indicator;
|
220 |
+
}
|
221 |
+
|
222 |
+
function addMessage(text, isUser) {
|
223 |
+
const messageDiv = document.createElement('div');
|
224 |
+
messageDiv.className = `message ${isUser ? 'user-message' : 'bot-message'}`;
|
225 |
+
|
226 |
+
const messageContent = document.createElement('div');
|
227 |
+
messageContent.className = 'message-content';
|
228 |
+
messageContent.textContent = text;
|
229 |
+
|
230 |
+
const timestamp = document.createElement('div');
|
231 |
+
timestamp.className = 'message-timestamp';
|
232 |
+
timestamp.textContent = getTimestamp();
|
233 |
+
|
234 |
+
messageDiv.appendChild(messageContent);
|
235 |
+
messageDiv.appendChild(timestamp);
|
236 |
+
chatContainer.appendChild(messageDiv);
|
237 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
238 |
+
}
|
239 |
+
|
240 |
+
async function sendQuery() {
|
241 |
+
const query = queryInput.value.trim();
|
242 |
+
if (!query) return;
|
243 |
+
|
244 |
+
addMessage(query, true);
|
245 |
+
queryInput.value = '';
|
246 |
+
queryInput.disabled = true;
|
247 |
+
sendButton.disabled = true;
|
248 |
+
|
249 |
+
// Add typing indicator
|
250 |
+
const typingIndicator = createTypingIndicator();
|
251 |
+
chatContainer.appendChild(typingIndicator);
|
252 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
253 |
+
|
254 |
+
try {
|
255 |
+
const formData = new FormData();
|
256 |
+
formData.append('botid', botId);
|
257 |
+
formData.append('query', query);
|
258 |
+
|
259 |
+
const response = await fetch('/query', {
|
260 |
+
method: 'POST',
|
261 |
+
body: formData
|
262 |
+
});
|
263 |
+
|
264 |
+
const data = await response.json();
|
265 |
+
// Remove typing indicator
|
266 |
+
typingIndicator.remove();
|
267 |
+
|
268 |
+
if (data.error) {
|
269 |
+
addMessage(`Error: ${data.error}`, false);
|
270 |
+
} else {
|
271 |
+
addMessage(data.response, false);
|
272 |
+
}
|
273 |
+
} catch (error) {
|
274 |
+
// Remove typing indicator
|
275 |
+
typingIndicator.remove();
|
276 |
+
addMessage('Sorry, there was an error processing your request.', false);
|
277 |
+
}
|
278 |
+
|
279 |
+
queryInput.disabled = false;
|
280 |
+
sendButton.disabled = false;
|
281 |
+
queryInput.focus();
|
282 |
+
}
|
283 |
+
|
284 |
+
// Add welcome message
|
285 |
+
window.addEventListener('load', () => {
|
286 |
+
addMessage("👋 Hi! I'm your SmartlyQ Assistant. How can I help you today?", false);
|
287 |
+
});
|
288 |
+
|
289 |
+
sendButton.addEventListener('click', sendQuery);
|
290 |
+
queryInput.addEventListener('keypress', (e) => {
|
291 |
+
if (e.key === 'Enter') sendQuery();
|
292 |
+
});
|
293 |
+
</script>
|
294 |
+
</body>
|
295 |
+
</html>
|