Spaces:
No application file
No application file
| let conversation = [ | |
| { role: 'bot', message: "Hi there! I'm Chat Bot! May I know your name?" } | |
| ]; | |
| let selectedIngredients = []; | |
| let selectedMenuItem = null; | |
| let cart = []; | |
| function addMessage(role, message) { | |
| const chatMessages = document.getElementById('chatMessages'); | |
| if (!chatMessages) { | |
| console.error('Chat messages container not found!'); | |
| return; | |
| } | |
| const messageDiv = document.createElement('div'); | |
| messageDiv.className = role === 'bot' ? 'bot-message' : 'user-message'; | |
| messageDiv.textContent = message; | |
| chatMessages.appendChild(messageDiv); | |
| chatMessages.scrollTop = chatMessages.scrollHeight; | |
| console.log(`Added ${role} message: ${message}`); | |
| } | |
| function sendMessage() { | |
| const userInput = document.getElementById('userInput'); | |
| if (!userInput) { | |
| console.error('User input field not found!'); | |
| return; | |
| } | |
| const message = userInput.value.trim(); | |
| if (message) { | |
| addMessage('user', message); | |
| conversation.push({ role: 'user', message: message }); | |
| userInput.value = ''; | |
| setTimeout(() => handleResponse(message), 500); | |
| } else { | |
| console.warn('Empty message!'); | |
| } | |
| } | |
| function handleResponse(userInput) { | |
| const lastMessage = conversation[conversation.length - 1].message.toLowerCase(); | |
| let botResponse = ''; | |
| let options = []; | |
| // Handle name input (first user response after bot's greeting) | |
| if (conversation.length === 2 && conversation[0].role === 'bot' && conversation[0].message.includes('May I know your name?')) { | |
| botResponse = `Nice to meet you, ${userInput}! 😊 How can I assist you today?`; | |
| options = [ | |
| { text: 'What is TioNat?', class: 'blue' }, | |
| { text: 'How do I create an account on TioNat?', class: 'blue' }, | |
| { text: 'How can I track my order?', class: 'blue' }, | |
| { text: 'Do you ship internationally?', class: 'blue' }, | |
| { text: 'What payment methods do you accept?', class: 'blue' }, | |
| { text: 'What is the best supplement for boosting immunity?', class: 'blue' }, | |
| { text: 'Are your nutritional supplements vegan-friendly?', class: 'blue' }, | |
| { text: 'How do I know which supplement is right for me?', class: 'blue' }, | |
| { text: 'Are there any side effects of using your supplements?', class: 'blue' }, | |
| { text: 'Do you offer products for specific health conditions?', class: 'blue' }, | |
| { text: 'How do I use your health care products?', class: 'blue' }, | |
| { text: 'Do your products come with a money-back guarantee?', class: 'blue' }, | |
| { text: 'Are your health care products FDA-approved?', class: 'blue' }, | |
| { text: 'Are your personal care products cruelty-free?', class: 'blue' }, | |
| { text: 'What ingredients do you use in your skincare products?', class: 'blue' }, | |
| { text: 'Can I use your personal care products for sensitive skin?', class: 'blue' }, | |
| { text: 'How do I find the right skincare routine?', class: 'blue' }, | |
| { text: 'Can I modify or cancel my order after placing it?', class: 'blue' }, | |
| { text: 'How long does it take to receive my order?', class: 'blue' }, | |
| { text: 'Do you offer free shipping?', class: 'blue' }, | |
| { text: 'How do I return a product?', class: 'blue' }, | |
| { text: 'How can I contact customer service?', class: 'blue' }, | |
| { text: 'Can I track my return?', class: 'blue' }, | |
| { text: 'How can I get a product recommendation?', class: 'blue' }, | |
| { text: 'How do I reset my password?', class: 'blue' }, | |
| { text: 'Is my payment information secure?', class: 'blue' }, | |
| { text: 'How do I update my account information?', class: 'blue' }, | |
| { text: 'Can I leave a review for a product?', class: 'blue' }, | |
| { text: 'How do I report a product issue?', class: 'blue' } | |
| ]; | |
| } else if (lastMessage.includes('what is tionat?')) { | |
| botResponse = 'TioNat is an e-commerce platform offering a wide range of products in Nutritional Care, Health Care, and Personal Care categories. We aim to improve the quality of life with top-notch, reliable, and scientifically-backed products.'; | |
| } else if (lastMessage.includes('how do i create an account on tionat?')) { | |
| botResponse = 'To create an account on TioNat, simply click on the "Sign Up" button on the top-right corner of our website. Enter your name, email address, and a password. Once registered, you can start shopping!'; | |
| } else if (lastMessage.includes('how can i track my order?')) { | |
| botResponse = 'After placing your order, you will receive a tracking number via email. You can also track your order from your TioNat account under the "Order History" section.'; | |
| } else if (lastMessage.includes('do you ship internationally?')) { | |
| botResponse = 'Yes, we offer international shipping to select countries. You can check if your country is eligible for delivery during the checkout process.'; | |
| } else if (lastMessage.includes('what payment methods do you accept?')) { | |
| botResponse = 'We accept a wide variety of payment methods, including credit/debit cards (Visa, MasterCard, American Express), net banking, PayPal, and cash on delivery (where applicable).'; | |
| } else if (lastMessage.includes('what is the best supplement for boosting immunity?')) { | |
| botResponse = 'Our Immunity Booster supplements, like Vitamin C, Zinc, and Echinacea, are popular choices for improving immune system health. We recommend consulting with a healthcare provider to find the best fit for you.'; | |
| } else if (lastMessage.includes('are your nutritional supplements vegan-friendly?')) { | |
| botResponse = 'Yes, many of our nutritional supplements are vegan-friendly. Please check the product details for specific information on ingredients and certifications.'; | |
| } else if (lastMessage.includes('how do i know which supplement is right for me?')) { | |
| botResponse = 'We recommend consulting with a healthcare professional before choosing a supplement. You can also check our detailed product descriptions and consult with our customer service for recommendations.'; | |
| } else if (lastMessage.includes('are there any side effects of using your supplements?')) { | |
| botResponse = 'All our products are thoroughly tested for safety, but individual reactions may vary. We suggest reading the product description for possible side effects or consulting with a healthcare provider before using any product.'; | |
| } else if (lastMessage.includes('do you offer products for specific health conditions?')) { | |
| botResponse = 'Yes, we offer a variety of health care products for conditions such as joint pain, heart health, digestion issues, and more. Please browse through our Health Care category for detailed information.'; | |
| } else if (lastMessage.includes('how do i use your health care products?')) { | |
| botResponse = 'Each product comes with detailed instructions for use on the packaging. Additionally, you can find user guides and recommendations on our website under each product’s description.'; | |
| } else if (lastMessage.includes('do your products come with a money-back guarantee?')) { | |
| botResponse = 'Yes, we offer a 30-day money-back guarantee on most of our health care products. Please refer to our return policy for specific conditions and guidelines.'; | |
| } else if (lastMessage.includes('are your health care products fda-approved?')) { | |
| botResponse = 'Many of our health care products are manufactured following strict quality guidelines and may be FDA-approved where applicable. You can check the product details for certification information.'; | |
| } else if (lastMessage.includes('are your personal care products cruelty-free?')) { | |
| botResponse = 'Yes, all our personal care products are cruelty-free. We ensure that none of our products are tested on animals, and they are made with sustainable and ethical practices.'; | |
| } else if (lastMessage.includes('what ingredients do you use in your skincare products?')) { | |
| botResponse = 'Our skincare products are formulated with high-quality ingredients, such as natural oils, vitamins, and plant-based extracts. For specific ingredient lists, please refer to the product description on each item page.'; | |
| } else if (lastMessage.includes('can i use your personal care products for sensitive skin?')) { | |
| botResponse = 'We offer products specifically designed for sensitive skin. Check the product descriptions for details on ingredients and suitability for sensitive skin. We also recommend doing a patch test before full application.'; | |
| } else if (lastMessage.includes('how do i find the right skincare routine?')) { | |
| botResponse = 'We suggest starting with a basic routine: cleansing, toning, and moisturizing. For more tailored recommendations, please check out our personalized skincare guides, or reach out to our customer service for advice.'; | |
| } else if (lastMessage.includes('can i modify or cancel my order after placing it?')) { | |
| botResponse = 'Orders can be modified or canceled within 24 hours of placement. Please contact our customer support immediately for any changes.'; | |
| } else if (lastMessage.includes('how long does it take to receive my order?')) { | |
| botResponse = 'Orders typically take 3-7 business days to process and ship, depending on your location. You can check your tracking number for more accurate delivery details.'; | |
| } else if (lastMessage.includes('do you offer free shipping?')) { | |
| botResponse = 'Yes, we offer free shipping on orders above a certain amount. Check the shipping details at checkout to confirm eligibility.'; | |
| } else if (lastMessage.includes('how do i return a product?')) { | |
| botResponse = 'If you are not satisfied with your purchase, you can return most products within 30 days. Please visit our Returns & Exchange page for detailed instructions.'; | |
| } else if (lastMessage.includes('how can i contact customer service?')) { | |
| botResponse = 'You can reach our customer service team via email at support@tionat.com or call us at +1-800-123-4567. We\'re here to assist you with any queries.'; | |
| } else if (lastMessage.includes('can i track my return?')) { | |
| botResponse = 'Yes, once your return is processed, you will receive a tracking number to monitor the status of your return shipment.'; | |
| } else if (lastMessage.includes('how can i get a product recommendation?')) { | |
| botResponse = 'You can check out our product recommendations under each category. If you\'re unsure, feel free to ask our chatbot or reach out to our customer support for personalized advice.'; | |
| } else if (lastMessage.includes('how do i reset my password?')) { | |
| botResponse = 'If you\'ve forgotten your password, click on the "Forgot Password" link on the login page. You will receive an email with instructions on how to reset your password.'; | |
| } else if (lastMessage.includes('is my payment information secure?')) { | |
| botResponse = 'Yes, we use industry-standard encryption (SSL) to protect your payment information. All payments are processed securely through trusted payment gateways.'; | |
| } else if (lastMessage.includes('how do i update my account information?')) { | |
| botResponse = 'You can update your account information by logging into your account and navigating to the "Account Settings" page. From there, you can update your address, payment methods, and personal details.'; | |
| } else if (lastMessage.includes('can i leave a review for a product?')) { | |
| botResponse = 'Yes! After purchasing a product, you can leave a review directly on the product page. We value your feedback and it helps other customers make informed decisions.'; | |
| } else if (lastMessage.includes('how do i report a product issue?')) { | |
| botResponse = 'If you receive a defective or damaged product, please contact our customer service immediately for assistance with returns or exchanges.'; | |
| } else { | |
| // Fallback for unrecognized input | |
| botResponse = "Sorry, I didn't understand that. Could you please clarify or choose an option?"; | |
| if (conversation.length === 2) { | |
| options = [ | |
| { text: 'What is TioNat?', class: 'blue' }, | |
| { text: 'How do I create an account on TioNat?', class: 'blue' }, | |
| { text: 'How can I track my order?', class: 'blue' }, | |
| { text: 'Do you ship internationally?', class: 'blue' }, | |
| { text: 'What payment methods do you accept?', class: 'blue' }, | |
| { text: 'What is the best supplement for boosting immunity?', class: 'blue' }, | |
| { text: 'Are your nutritional supplements vegan-friendly?', class: 'blue' }, | |
| { text: 'How do I know which supplement is right for me?', class: 'blue' }, | |
| { text: 'Are there any side effects of using your supplements?', class: 'blue' }, | |
| { text: 'Do you offer products for specific health conditions?', class: 'blue' }, | |
| { text: 'How do I use your health care products?', class: 'blue' }, | |
| { text: 'Do your products come with a money-back guarantee?', class: 'blue' }, | |
| { text: 'Are your health care products FDA-approved?', class: 'blue' }, | |
| { text: 'Are your personal care products cruelty-free?', class: 'blue' }, | |
| { text: 'What ingredients do you use in your skincare products?', class: 'blue' }, | |
| { text: 'Can I use your personal care products for sensitive skin?', class: 'blue' }, | |
| { text: 'How do I find the right skincare routine?', class: 'blue' }, | |
| { text: 'Can I modify or cancel my order after placing it?', class: 'blue' }, | |
| { text: 'How long does it take to receive my order?', class: 'blue' }, | |
| { text: 'Do you offer free shipping?', class: 'blue' }, | |
| { text: 'How do I return a product?', class: 'blue' }, | |
| { text: 'How can I contact customer service?', class: 'blue' }, | |
| { text: 'Can I track my return?', class: 'blue' }, | |
| { text: 'How can I get a product recommendation?', class: 'blue' }, | |
| { text: 'How do I reset my password?', class: 'blue' }, | |
| { text: 'Is my payment information secure?', class: 'blue' }, | |
| { text: 'How do I update my account information?', class: 'blue' }, | |
| { text: 'Can I leave a review for a product?', class: 'blue' }, | |
| { text: 'How do I report a product issue?', class: 'blue' } | |
| ]; | |
| } | |
| } | |
| addMessage('bot', botResponse); | |
| if (options.length > 0) { | |
| displayOptions(options); | |
| } | |
| } | |
| function displayOptions(options) { | |
| const chatMessages = document.getElementById('chatMessages'); | |
| if (!chatMessages) { | |
| console.error('Chat messages container not found for options!'); | |
| return; | |
| } | |
| // Display each option as a bot message in the chat | |
| options.forEach(opt => { | |
| const messageDiv = document.createElement('div'); | |
| messageDiv.className = 'bot-message'; // This makes the options look like bot messages | |
| const button = document.createElement('button'); | |
| button.textContent = opt.text; | |
| button.className = `option-button ${opt.class}`; | |
| // When an option is clicked, treat it as a user response and trigger the appropriate handler | |
| button.onclick = () => { | |
| addMessage('user', opt.text); | |
| conversation.push({ role: 'user', message: opt.text }); | |
| setTimeout(() => handleResponse(opt.text), 500); | |
| }; | |
| messageDiv.appendChild(button); | |
| chatMessages.appendChild(messageDiv); // Append the button inside a bot message container | |
| }); | |
| // Scroll to the bottom of the chat container | |
| chatMessages.scrollTop = chatMessages.scrollHeight; | |
| } | |