Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +41 -7
static/script.js
CHANGED
|
@@ -16,6 +16,30 @@ function addMessage(role, message) {
|
|
| 16 |
console.log(`Added ${role} message: ${message}`);
|
| 17 |
}
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
function sendMessage() {
|
| 20 |
const userInput = document.getElementById('userInput');
|
| 21 |
if (!userInput) {
|
|
@@ -33,20 +57,24 @@ function sendMessage() {
|
|
| 33 |
}
|
| 34 |
}
|
| 35 |
|
| 36 |
-
function
|
|
|
|
| 37 |
let botResponse = '';
|
| 38 |
|
| 39 |
-
// FAQ handling logic
|
| 40 |
-
if (
|
| 41 |
botResponse = "You can email us at support@company.com.";
|
| 42 |
-
} else if (
|
| 43 |
botResponse = "We are open from 9 AM to 6 PM, Monday to Friday.";
|
| 44 |
-
} else if (
|
| 45 |
botResponse = "Click on 'Forgot Password' on the login page.";
|
| 46 |
-
} else if (
|
| 47 |
botResponse = "You can cancel your subscription by visiting the 'Account Settings' page and selecting 'Cancel Subscription'.";
|
| 48 |
-
} else if (
|
| 49 |
botResponse = "We offer seasonal discounts and promotions. Keep an eye on our website or subscribe to our newsletter for updates.";
|
|
|
|
|
|
|
|
|
|
| 50 |
}
|
| 51 |
|
| 52 |
addMessage('bot', botResponse);
|
|
@@ -58,4 +86,10 @@ document.getElementById('userInput').addEventListener('keypress', function(e) {
|
|
| 58 |
}
|
| 59 |
});
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
console.log('Script loaded successfully');
|
|
|
|
| 16 |
console.log(`Added ${role} message: ${message}`);
|
| 17 |
}
|
| 18 |
|
| 19 |
+
function showFAQOptions() {
|
| 20 |
+
const faqContainer = document.getElementById('faqList');
|
| 21 |
+
faqContainer.style.display = 'block'; // Show the FAQ list once the greeting is sent
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
function handleFAQClick(faq) {
|
| 25 |
+
let botResponse = '';
|
| 26 |
+
|
| 27 |
+
// FAQ handling logic based on the clicked question
|
| 28 |
+
if (faq === 'contact_support') {
|
| 29 |
+
botResponse = "You can email us at support@company.com.";
|
| 30 |
+
} else if (faq === 'business_hours') {
|
| 31 |
+
botResponse = "We are open from 9 AM to 6 PM, Monday to Friday.";
|
| 32 |
+
} else if (faq === 'reset_password') {
|
| 33 |
+
botResponse = "Click on 'Forgot Password' on the login page.";
|
| 34 |
+
} else if (faq === 'cancel_subscription') {
|
| 35 |
+
botResponse = "You can cancel your subscription by visiting the 'Account Settings' page and selecting 'Cancel Subscription'.";
|
| 36 |
+
} else if (faq === 'discounts') {
|
| 37 |
+
botResponse = "We offer seasonal discounts and promotions. Keep an eye on our website or subscribe to our newsletter for updates.";
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
addMessage('bot', botResponse);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
function sendMessage() {
|
| 44 |
const userInput = document.getElementById('userInput');
|
| 45 |
if (!userInput) {
|
|
|
|
| 57 |
}
|
| 58 |
}
|
| 59 |
|
| 60 |
+
function handleResponse(userInput) {
|
| 61 |
+
const lastMessage = conversation[conversation.length - 1].message.toLowerCase();
|
| 62 |
let botResponse = '';
|
| 63 |
|
| 64 |
+
// FAQ handling logic
|
| 65 |
+
if (lastMessage.includes("how do i contact customer support")) {
|
| 66 |
botResponse = "You can email us at support@company.com.";
|
| 67 |
+
} else if (lastMessage.includes("what are your business hours")) {
|
| 68 |
botResponse = "We are open from 9 AM to 6 PM, Monday to Friday.";
|
| 69 |
+
} else if (lastMessage.includes("how do i reset my password")) {
|
| 70 |
botResponse = "Click on 'Forgot Password' on the login page.";
|
| 71 |
+
} else if (lastMessage.includes("how do i cancel my subscription")) {
|
| 72 |
botResponse = "You can cancel your subscription by visiting the 'Account Settings' page and selecting 'Cancel Subscription'.";
|
| 73 |
+
} else if (lastMessage.includes("are there any discounts available")) {
|
| 74 |
botResponse = "We offer seasonal discounts and promotions. Keep an eye on our website or subscribe to our newsletter for updates.";
|
| 75 |
+
} else {
|
| 76 |
+
// Fallback for unrecognized input
|
| 77 |
+
botResponse = "Sorry, I didn't understand that. Could you please clarify or ask a different question?";
|
| 78 |
}
|
| 79 |
|
| 80 |
addMessage('bot', botResponse);
|
|
|
|
| 86 |
}
|
| 87 |
});
|
| 88 |
|
| 89 |
+
// Show FAQ options after the greeting message
|
| 90 |
+
window.onload = () => {
|
| 91 |
+
addMessage('bot', "Hi there! I'm your assistant! How can I help you today?");
|
| 92 |
+
showFAQOptions();
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
console.log('Script loaded successfully');
|