Spaces:
Running
Running
Update static/index.html
Browse files- static/index.html +63 -60
static/index.html
CHANGED
|
@@ -114,9 +114,6 @@
|
|
| 114 |
<i class="fas fa-arrow-left"></i>
|
| 115 |
</button>
|
| 116 |
<div id="chat-history" class="mb-3"></div>
|
| 117 |
-
<div id="loading" class="spinner-border text-primary" role="status">
|
| 118 |
-
<span class="sr-only">Loading...</span>
|
| 119 |
-
</div>
|
| 120 |
<div class="input-group mb-2">
|
| 121 |
<textarea id="user-input" class="form-control" rows="2" placeholder="Type your message..." aria-label="Message input"></textarea>
|
| 122 |
<div class="input-group-append">
|
|
@@ -125,6 +122,7 @@
|
|
| 125 |
</button>
|
| 126 |
</div>
|
| 127 |
</div>
|
|
|
|
| 128 |
</div>
|
| 129 |
<script>
|
| 130 |
let chatHistoryArray = [];
|
|
@@ -138,39 +136,38 @@
|
|
| 138 |
document.getElementById("close-button").addEventListener("click", closeChat);
|
| 139 |
|
| 140 |
async function sendMessage() {
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
}
|
| 174 |
|
| 175 |
async function closeChat() {
|
| 176 |
const userId = document.getElementById("user-id").value;
|
|
@@ -189,30 +186,36 @@
|
|
| 189 |
window.top.location.href = 'https://redfernstech.com/chat-bot-test/'; // Or use chatContainer.remove(); to completely remove it
|
| 190 |
}
|
| 191 |
}
|
| 192 |
-
|
| 193 |
function addMessage(sender, message, className) {
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
function showTypingIndicator() {
|
| 218 |
const chatHistory = document.getElementById("chat-history");
|
|
@@ -232,4 +235,4 @@
|
|
| 232 |
}
|
| 233 |
</script>
|
| 234 |
</body>
|
| 235 |
-
</html>
|
|
|
|
| 114 |
<i class="fas fa-arrow-left"></i>
|
| 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">
|
|
|
|
| 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 = [];
|
|
|
|
| 136 |
document.getElementById("close-button").addEventListener("click", closeChat);
|
| 137 |
|
| 138 |
async function sendMessage() {
|
| 139 |
+
const input = document.getElementById("user-input");
|
| 140 |
+
const userId = document.getElementById("user-id").value;
|
| 141 |
+
const message = input.value.trim();
|
| 142 |
+
if (message === "") {
|
| 143 |
+
return;
|
| 144 |
+
}
|
| 145 |
+
addMessage("User", message, "user-message");
|
| 146 |
+
chatHistoryArray.push({ userId, sender: "User", message });
|
| 147 |
+
input.value = "";
|
| 148 |
+
showTypingIndicator();
|
| 149 |
+
try {
|
| 150 |
+
const response = await fetch("/chat/", {
|
| 151 |
+
method: "POST",
|
| 152 |
+
headers: {
|
| 153 |
+
"Content-Type": "application/json"
|
| 154 |
+
},
|
| 155 |
+
body: JSON.stringify({ message })
|
| 156 |
+
});
|
| 157 |
+
if (!response.ok) {
|
| 158 |
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
| 159 |
+
}
|
| 160 |
+
const data = await response.json();
|
| 161 |
+
addMessage("Bot", data.response, "bot-message");
|
| 162 |
+
chatHistoryArray.push({ userId, sender: "Bot", message: data.response });
|
| 163 |
+
} catch (error) {
|
| 164 |
+
console.error('Error:', error);
|
| 165 |
+
addMessage("Bot", "Sorry, something went wrong.", "bot-message");
|
| 166 |
+
} finally {
|
| 167 |
+
hideTypingIndicator();
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
|
|
|
|
| 171 |
|
| 172 |
async function closeChat() {
|
| 173 |
const userId = document.getElementById("user-id").value;
|
|
|
|
| 186 |
window.top.location.href = 'https://redfernstech.com/chat-bot-test/'; // Or use chatContainer.remove(); to completely remove it
|
| 187 |
}
|
| 188 |
}
|
|
|
|
| 189 |
function addMessage(sender, message, className) {
|
| 190 |
+
const chatHistory = document.getElementById("chat-history");
|
| 191 |
+
const messageElement = document.createElement("div");
|
| 192 |
+
messageElement.className = `message ${className}`;
|
| 193 |
+
// Check if the message contains a URL
|
| 194 |
+
const linkRegex = /(https?:\/\/[^\s]+)/g;
|
| 195 |
+
const formattedMessage = message.replace(linkRegex, function(url) {
|
| 196 |
+
let linkText;
|
| 197 |
+
if (url === "https://appexchange.salesforce.com/appxListingDetail?listingId=cf4b19d4-8667-49f7-83b0-d2bc4032527b") {
|
| 198 |
+
linkText = "Visit this link to check out the Product Filter App.";
|
| 199 |
+
} else if (url === "https://appexchange.salesforce.com/appxListingDetail?listingId=e671f4fe-92fb-4760-99e5-7a5df5754cfe") {
|
| 200 |
+
linkText = "Visit this link to check out the Mass Approvals App.";
|
| 201 |
+
} else if (url === "https://appexchange.salesforce.com/appxListingDetail?listingId=3473ffd3-d530-462f-828f-d2c69f80d89d") {
|
| 202 |
+
linkText = "Visit this link to check out the Thumbnail Viewer App.";
|
| 203 |
+
} else if (url === "https://appexchange.salesforce.com/appxListingDetail?listingId=6d605bd9-de3c-49d3-9fa4-ec3caabd5d63") {
|
| 204 |
+
linkText = "Visit this link to check out the Currency Conversion App.";
|
| 205 |
+
} else if (url === "https://redfernstech.com/careers/") {
|
| 206 |
+
linkText = "Visit this link to check out the careers.";
|
| 207 |
+
} else {
|
| 208 |
+
linkText = "Visit this link."; // Fallback for other URLs
|
| 209 |
+
}
|
| 210 |
+
return `<a href="${url}" target="_blank">${linkText}</a>`;
|
| 211 |
+
});
|
| 212 |
+
messageElement.innerHTML = `<span class="${sender.toLowerCase()}-icon">
|
| 213 |
+
${sender === "User" ? '<i class="fas fa-user"></i>' : '<img src="https://raw.githubusercontent.com/SRINIVASULU-2003/srinu/refs/heads/main/static/bot.jpeg" alt="Bot" style="width: 20px; height: 20px; border-radius: 50%;">'}
|
| 214 |
+
</span>${formattedMessage}<div class="timestamp">${new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}</div>`;
|
| 215 |
+
chatHistory.appendChild(messageElement);
|
| 216 |
+
chatHistory.scrollTop = chatHistory.scrollHeight; // Scroll to bottom
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
|
| 220 |
function showTypingIndicator() {
|
| 221 |
const chatHistory = document.getElementById("chat-history");
|
|
|
|
| 235 |
}
|
| 236 |
</script>
|
| 237 |
</body>
|
| 238 |
+
</html>
|