Spaces:
Sleeping
Sleeping
Update static/index.html
Browse files- static/index.html +145 -139
static/index.html
CHANGED
@@ -7,100 +7,129 @@
|
|
7 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
8 |
<style>
|
9 |
body {
|
10 |
-
font-family:
|
11 |
-
background-color: #
|
12 |
margin: 0;
|
13 |
padding: 0;
|
14 |
}
|
|
|
15 |
#chat-container {
|
16 |
max-width: 500px;
|
17 |
-
position: relative;
|
18 |
margin: auto;
|
19 |
-
padding:
|
20 |
-
border-radius:
|
21 |
-
background-color: #
|
22 |
-
box-shadow: 0
|
|
|
23 |
}
|
|
|
24 |
#chat-history {
|
25 |
-
height:
|
26 |
overflow-y: auto;
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.1);
|
33 |
}
|
|
|
34 |
.message {
|
35 |
-
|
36 |
-
|
37 |
-
margin: 5px 0;
|
38 |
border-radius: 20px;
|
39 |
-
|
40 |
-
|
|
|
41 |
cursor: pointer;
|
42 |
transition: background-color 0.3s;
|
43 |
}
|
|
|
44 |
.user-message {
|
45 |
-
background: linear-gradient(135deg, #
|
46 |
-
color: #
|
47 |
margin-left: auto;
|
48 |
-
border-radius:
|
49 |
}
|
|
|
50 |
.bot-message {
|
51 |
-
background: linear-gradient(135deg, #
|
52 |
-
color: #
|
53 |
margin-right: auto;
|
54 |
-
border-radius:
|
55 |
}
|
|
|
56 |
.user-icon, .bot-icon {
|
57 |
-
margin-right:
|
58 |
-
font-size: 1.
|
59 |
}
|
|
|
60 |
#loading {
|
61 |
display: none;
|
62 |
-
margin:
|
63 |
text-align: center;
|
|
|
64 |
}
|
|
|
65 |
#user-input {
|
66 |
-
border: 1px solid #
|
67 |
-
border-radius:
|
68 |
-
resize: none;
|
|
|
|
|
|
|
69 |
}
|
|
|
70 |
#user-input:focus {
|
71 |
border-color: #007bff;
|
72 |
outline: none;
|
73 |
}
|
74 |
-
|
|
|
75 |
background-color: #007bff;
|
76 |
color: white;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
}
|
|
|
78 |
.btn-close {
|
79 |
-
position: absolute;
|
80 |
-
top:
|
81 |
-
right:
|
82 |
-
background-color: #dc3545;
|
83 |
color: white;
|
84 |
-
border: none;
|
85 |
-
border-radius: 50%;
|
86 |
-
width: 30px;
|
87 |
-
height: 30px;
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
92 |
}
|
|
|
93 |
.btn-close:hover {
|
94 |
-
background-color: #c82333;
|
95 |
}
|
|
|
96 |
.typing-indicator {
|
97 |
font-style: italic;
|
98 |
-
color: #
|
99 |
-
margin:
|
100 |
}
|
|
|
101 |
.timestamp {
|
102 |
font-size: 0.75em;
|
103 |
-
color: #
|
104 |
display: none;
|
105 |
margin-top: 5px;
|
106 |
}
|
@@ -110,138 +139,115 @@
|
|
110 |
<body>
|
111 |
<div id="chat-container" class="rounded p-4 shadow">
|
112 |
<input type="hidden" id="user-id" value="{{ user_id }}">
|
113 |
-
|
114 |
-
<i class="fas fa-
|
115 |
</button>
|
116 |
<div id="chat-history" class="mb-3"></div>
|
117 |
<div class="input-group mb-2">
|
118 |
<textarea id="user-input" class="form-control" rows="2" placeholder="Type your message..." aria-label="Message input"></textarea>
|
119 |
<div class="input-group-append">
|
120 |
-
<button id="send-button" class="btn
|
121 |
<i class="fas fa-paper-plane"></i>
|
122 |
</button>
|
123 |
</div>
|
124 |
</div>
|
125 |
<small class="form-text text-muted">Press Shift + Enter for a new line</small>
|
126 |
-
</div>
|
|
|
127 |
<script>
|
128 |
let chatHistoryArray = [];
|
129 |
document.getElementById("send-button").addEventListener("click", sendMessage);
|
130 |
document.getElementById("user-input").addEventListener("keypress", function(event) {
|
131 |
-
if (event.key === "Enter" && !event.shiftKey) {
|
132 |
-
event.preventDefault();
|
133 |
sendMessage();
|
134 |
}
|
135 |
});
|
136 |
document.getElementById("close-button").addEventListener("click", closeChat);
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
});
|
141 |
-
|
142 |
-
function sendInitialBotMessage() {
|
143 |
-
const userId = document.getElementById("user-id").value;
|
144 |
-
const initialMessage = "Hello! How can I assist you today?"; // Initial bot message
|
145 |
-
|
146 |
-
addMessage("Bot", initialMessage, "bot-message"); // Display the initial bot message
|
147 |
-
chatHistoryArray.push({ userId, sender: "Bot", message: initialMessage }); // Save to chat history
|
148 |
-
}
|
149 |
-
|
150 |
-
async function sendMessage() {
|
151 |
-
const input = document.getElementById("user-input");
|
152 |
-
const userId = document.getElementById("user-id").value;
|
153 |
-
const message = input.value.trim();
|
154 |
-
if (message === "") {
|
155 |
-
return;
|
156 |
-
}
|
157 |
-
addMessage("User", message, "user-message");
|
158 |
-
chatHistoryArray.push({ userId, sender: "User", message });
|
159 |
-
input.value = "";
|
160 |
-
showTypingIndicator();
|
161 |
-
try {
|
162 |
-
const response = await fetch("/chat/", {
|
163 |
-
method: "POST",
|
164 |
-
headers: {
|
165 |
-
"Content-Type": "application/json"
|
166 |
-
},
|
167 |
-
body: JSON.stringify({ message })
|
168 |
});
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
async function closeChat() {
|
183 |
const userId = document.getElementById("user-id").value;
|
184 |
try {
|
185 |
await fetch("/hist/", {
|
186 |
method: "POST",
|
187 |
-
headers: {
|
188 |
-
"Content-Type": "application/json"
|
189 |
-
},
|
190 |
body: JSON.stringify({ history: chatHistoryArray, userId })
|
191 |
});
|
192 |
} catch (error) {
|
193 |
console.error('Error sending chat history on close:', error);
|
194 |
} finally {
|
195 |
-
|
196 |
}
|
197 |
}
|
|
|
198 |
function addMessage(sender, message, className) {
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
}
|
213 |
-
|
214 |
-
} else if (url === "https://redfernstech.com/careers/") {
|
215 |
-
linkText = "Click here";
|
216 |
-
} else {
|
217 |
-
linkText = "Visit this link."; // Fallback for other URLs
|
218 |
-
}
|
219 |
-
return `<a href="${url}" target="_blank">${linkText}</a>`;
|
220 |
-
});
|
221 |
-
messageElement.innerHTML = `<span class="${sender.toLowerCase()}-icon">
|
222 |
-
${sender === "User" ? '<i class="fas fa-user"></i>' : '<img src="https://i.ibb.co/khk6Ywx/bot.jpg" alt="Bot" style="width: 20px; height: 20px; border-radius: 50%;">'}
|
223 |
-
</span>${formattedMessage}<div class="timestamp">${new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}</div>`;
|
224 |
-
chatHistory.appendChild(messageElement);
|
225 |
-
chatHistory.scrollTop = chatHistory.scrollHeight; // Scroll to bottom
|
226 |
-
}
|
227 |
-
|
228 |
-
|
229 |
function showTypingIndicator() {
|
230 |
const chatHistory = document.getElementById("chat-history");
|
231 |
const typingIndicator = document.createElement("div");
|
232 |
typingIndicator.className = "typing-indicator";
|
233 |
typingIndicator.id = "typing-indicator";
|
234 |
-
typingIndicator.innerText = "
|
235 |
chatHistory.appendChild(typingIndicator);
|
236 |
-
chatHistory.scrollTop = chatHistory.scrollHeight;
|
237 |
}
|
238 |
-
|
239 |
function hideTypingIndicator() {
|
240 |
const typingIndicator = document.getElementById("typing-indicator");
|
241 |
-
if (typingIndicator)
|
242 |
-
typingIndicator.remove();
|
243 |
-
}
|
244 |
}
|
245 |
</script>
|
246 |
</body>
|
247 |
-
</html>
|
|
|
7 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
|
8 |
<style>
|
9 |
body {
|
10 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
11 |
+
background-color: #f4f7fb;
|
12 |
margin: 0;
|
13 |
padding: 0;
|
14 |
}
|
15 |
+
|
16 |
#chat-container {
|
17 |
max-width: 500px;
|
|
|
18 |
margin: auto;
|
19 |
+
padding: 25px;
|
20 |
+
border-radius: 15px;
|
21 |
+
background-color: #fff;
|
22 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
|
23 |
+
position: relative;
|
24 |
}
|
25 |
+
|
26 |
#chat-history {
|
27 |
+
height: 400px;
|
28 |
overflow-y: auto;
|
29 |
+
padding: 15px;
|
30 |
+
background: linear-gradient(135deg, #f3f4f8 0%, #d3e0f0 100%);
|
31 |
+
border-radius: 15px;
|
32 |
+
box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1);
|
33 |
+
margin-bottom: 15px;
|
|
|
34 |
}
|
35 |
+
|
36 |
.message {
|
37 |
+
padding: 12px 15px;
|
38 |
+
margin: 10px 0;
|
|
|
39 |
border-radius: 20px;
|
40 |
+
font-size: 0.9em;
|
41 |
+
line-height: 1.4em;
|
42 |
+
position: relative;
|
43 |
cursor: pointer;
|
44 |
transition: background-color 0.3s;
|
45 |
}
|
46 |
+
|
47 |
.user-message {
|
48 |
+
background: linear-gradient(135deg, #c9e6f5 0%, #91c9e6 100%);
|
49 |
+
color: #006c8e;
|
50 |
margin-left: auto;
|
51 |
+
border-radius: 20px 20px 0 20px;
|
52 |
}
|
53 |
+
|
54 |
.bot-message {
|
55 |
+
background: linear-gradient(135deg, #fce0e0 0%, #f9b2b2 100%);
|
56 |
+
color: #8b3e40;
|
57 |
margin-right: auto;
|
58 |
+
border-radius: 20px 20px 20px 0;
|
59 |
}
|
60 |
+
|
61 |
.user-icon, .bot-icon {
|
62 |
+
margin-right: 10px;
|
63 |
+
font-size: 1.2em;
|
64 |
}
|
65 |
+
|
66 |
#loading {
|
67 |
display: none;
|
68 |
+
margin: 15px 0;
|
69 |
text-align: center;
|
70 |
+
font-size: 1.2em;
|
71 |
}
|
72 |
+
|
73 |
#user-input {
|
74 |
+
border: 1px solid #ddd;
|
75 |
+
border-radius: 8px;
|
76 |
+
resize: none;
|
77 |
+
padding: 12px;
|
78 |
+
font-size: 1em;
|
79 |
+
width: calc(100% - 48px);
|
80 |
}
|
81 |
+
|
82 |
#user-input:focus {
|
83 |
border-color: #007bff;
|
84 |
outline: none;
|
85 |
}
|
86 |
+
|
87 |
+
.btn-send {
|
88 |
background-color: #007bff;
|
89 |
color: white;
|
90 |
+
border-radius: 8px;
|
91 |
+
padding: 10px 15px;
|
92 |
+
border: none;
|
93 |
+
cursor: pointer;
|
94 |
+
font-size: 1.1em;
|
95 |
+
transition: background-color 0.3s;
|
96 |
+
}
|
97 |
+
|
98 |
+
.btn-send:hover {
|
99 |
+
background-color: #0056b3;
|
100 |
}
|
101 |
+
|
102 |
.btn-close {
|
103 |
+
position: absolute;
|
104 |
+
top: 12px;
|
105 |
+
right: 12px;
|
106 |
+
background-color: #dc3545;
|
107 |
color: white;
|
108 |
+
border: none;
|
109 |
+
border-radius: 50%;
|
110 |
+
width: 30px;
|
111 |
+
height: 30px;
|
112 |
+
font-size: 1.2em;
|
113 |
+
display: flex;
|
114 |
+
align-items: center;
|
115 |
+
justify-content: center;
|
116 |
+
cursor: pointer;
|
117 |
+
transition: background-color 0.3s;
|
118 |
}
|
119 |
+
|
120 |
.btn-close:hover {
|
121 |
+
background-color: #c82333;
|
122 |
}
|
123 |
+
|
124 |
.typing-indicator {
|
125 |
font-style: italic;
|
126 |
+
color: #888;
|
127 |
+
margin-top: 10px;
|
128 |
}
|
129 |
+
|
130 |
.timestamp {
|
131 |
font-size: 0.75em;
|
132 |
+
color: #999;
|
133 |
display: none;
|
134 |
margin-top: 5px;
|
135 |
}
|
|
|
139 |
<body>
|
140 |
<div id="chat-container" class="rounded p-4 shadow">
|
141 |
<input type="hidden" id="user-id" value="{{ user_id }}">
|
142 |
+
<button type="button" id="close-button" class="btn-close" aria-label="Close chat">
|
143 |
+
<i class="fas fa-times"></i>
|
144 |
</button>
|
145 |
<div id="chat-history" class="mb-3"></div>
|
146 |
<div class="input-group mb-2">
|
147 |
<textarea id="user-input" class="form-control" rows="2" placeholder="Type your message..." aria-label="Message input"></textarea>
|
148 |
<div class="input-group-append">
|
149 |
+
<button id="send-button" class="btn-send" aria-label="Send message">
|
150 |
<i class="fas fa-paper-plane"></i>
|
151 |
</button>
|
152 |
</div>
|
153 |
</div>
|
154 |
<small class="form-text text-muted">Press Shift + Enter for a new line</small>
|
155 |
+
</div>
|
156 |
+
|
157 |
<script>
|
158 |
let chatHistoryArray = [];
|
159 |
document.getElementById("send-button").addEventListener("click", sendMessage);
|
160 |
document.getElementById("user-input").addEventListener("keypress", function(event) {
|
161 |
+
if (event.key === "Enter" && !event.shiftKey) {
|
162 |
+
event.preventDefault();
|
163 |
sendMessage();
|
164 |
}
|
165 |
});
|
166 |
document.getElementById("close-button").addEventListener("click", closeChat);
|
167 |
+
|
168 |
+
window.addEventListener('DOMContentLoaded', () => {
|
169 |
+
sendInitialBotMessage();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
});
|
171 |
+
|
172 |
+
function sendInitialBotMessage() {
|
173 |
+
const userId = document.getElementById("user-id").value;
|
174 |
+
const initialMessage = "Hello! How can I assist you today?";
|
175 |
+
addMessage("Bot", initialMessage, "bot-message");
|
176 |
+
chatHistoryArray.push({ userId, sender: "Bot", message: initialMessage });
|
177 |
+
}
|
178 |
+
|
179 |
+
async function sendMessage() {
|
180 |
+
const input = document.getElementById("user-input");
|
181 |
+
const userId = document.getElementById("user-id").value;
|
182 |
+
const message = input.value.trim();
|
183 |
+
if (message === "") return;
|
184 |
+
addMessage("User", message, "user-message");
|
185 |
+
chatHistoryArray.push({ userId, sender: "User", message });
|
186 |
+
input.value = "";
|
187 |
+
showTypingIndicator();
|
188 |
+
try {
|
189 |
+
const response = await fetch("/chat/", {
|
190 |
+
method: "POST",
|
191 |
+
headers: { "Content-Type": "application/json" },
|
192 |
+
body: JSON.stringify({ message })
|
193 |
+
});
|
194 |
+
if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
|
195 |
+
const data = await response.json();
|
196 |
+
addMessage("Bot", data.response, "bot-message");
|
197 |
+
chatHistoryArray.push({ userId, sender: "Bot", message: data.response });
|
198 |
+
} catch (error) {
|
199 |
+
console.error('Error:', error);
|
200 |
+
addMessage("Bot", "Sorry, something went wrong.", "bot-message");
|
201 |
+
} finally {
|
202 |
+
hideTypingIndicator();
|
203 |
+
}
|
204 |
+
}
|
205 |
+
|
206 |
async function closeChat() {
|
207 |
const userId = document.getElementById("user-id").value;
|
208 |
try {
|
209 |
await fetch("/hist/", {
|
210 |
method: "POST",
|
211 |
+
headers: { "Content-Type": "application/json" },
|
|
|
|
|
212 |
body: JSON.stringify({ history: chatHistoryArray, userId })
|
213 |
});
|
214 |
} catch (error) {
|
215 |
console.error('Error sending chat history on close:', error);
|
216 |
} finally {
|
217 |
+
window.top.location.href = 'https://redfernstech.com/';
|
218 |
}
|
219 |
}
|
220 |
+
|
221 |
function addMessage(sender, message, className) {
|
222 |
+
const chatHistory = document.getElementById("chat-history");
|
223 |
+
const messageElement = document.createElement("div");
|
224 |
+
messageElement.className = `message ${className}`;
|
225 |
+
const linkRegex = /(https?:\/\/[^\s]+)/g;
|
226 |
+
const formattedMessage = message.replace(linkRegex, function(url) {
|
227 |
+
let linkText = url.includes("salesforce") ? "Click here" : "Visit this link.";
|
228 |
+
return `<a href="${url}" target="_blank">${linkText}</a>`;
|
229 |
+
});
|
230 |
+
messageElement.innerHTML = `<span class="${sender.toLowerCase()}-icon">
|
231 |
+
${sender === "User" ? '<i class="fas fa-user"></i>' : '<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTa1q4s76cKilDcBElngWUNlMagmp18HjhF5A&s" alt="Bot" style="width: 20px; height: 20px; border-radius: 50%;">'}
|
232 |
+
</span>${formattedMessage}<div class="timestamp">${new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}</div>`;
|
233 |
+
chatHistory.appendChild(messageElement);
|
234 |
+
chatHistory.scrollTop = chatHistory.scrollHeight;
|
235 |
+
}
|
236 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
function showTypingIndicator() {
|
238 |
const chatHistory = document.getElementById("chat-history");
|
239 |
const typingIndicator = document.createElement("div");
|
240 |
typingIndicator.className = "typing-indicator";
|
241 |
typingIndicator.id = "typing-indicator";
|
242 |
+
typingIndicator.innerText = "Bot is typing...";
|
243 |
chatHistory.appendChild(typingIndicator);
|
244 |
+
chatHistory.scrollTop = chatHistory.scrollHeight;
|
245 |
}
|
246 |
+
|
247 |
function hideTypingIndicator() {
|
248 |
const typingIndicator = document.getElementById("typing-indicator");
|
249 |
+
if (typingIndicator) typingIndicator.remove();
|
|
|
|
|
250 |
}
|
251 |
</script>
|
252 |
</body>
|
253 |
+
</html>
|