jithenderchoudary commited on
Commit
191996c
·
verified ·
1 Parent(s): ec691fc

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +47 -10
static/script.js CHANGED
@@ -1,9 +1,6 @@
1
  let conversation = [
2
  { role: 'bot', message: "Hi there! I'm Chat Bot! May I know your name?" }
3
  ];
4
- let selectedIngredients = [];
5
- let selectedMenuItem = null;
6
- let cart = [];
7
  let userName = ''; // To store the user's name
8
 
9
  function addMessage(role, message) {
@@ -43,7 +40,11 @@ function displayForm() {
43
  console.error('Chat messages container not found for form!');
44
  return;
45
  }
46
-
 
 
 
 
47
  const formDiv = document.createElement('div');
48
  formDiv.className = 'bot-message';
49
  formDiv.innerHTML = `
@@ -166,7 +167,7 @@ function handleResponse(userInput) {
166
  { text: 'How do I update my account information?', class: 'blue' },
167
  { text: 'Can I leave a review for a product?', class: 'blue' },
168
  { text: 'How do I report a product issue?', class: 'blue' },
169
- { text: 'Other', class: 'green' } // Added "Other" option
170
  ];
171
  } else if (lastMessage.includes('what is tionat?')) {
172
  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.';
@@ -208,7 +209,7 @@ function handleResponse(userInput) {
208
  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.';
209
  } else if (lastMessage.includes('do you offer free shipping?')) {
210
  botResponse = 'Yes, we offer free shipping on orders above a certain amount. Check the shipping details at checkout to confirm eligibility.';
211
- } else if (lastMessage.includes('how do i return a product?')) {
212
  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.';
213
  } else if (lastMessage.includes('how can i contact customer service?')) {
214
  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.';
@@ -232,11 +233,47 @@ function handleResponse(userInput) {
232
  displayForm();
233
  return; // Stop further processing since we're showing the form
234
  } else {
235
- // Fallback for unrecognized input
236
- botResponse = "Sorry, I didn't understand that. Let's register your query so our service agent can assist you.";
237
  addMessage('bot', botResponse);
238
- displayForm();
239
- return; // Stop further processing since we're showing the form
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  }
241
 
242
  addMessage('bot', botResponse);
 
1
  let conversation = [
2
  { role: 'bot', message: "Hi there! I'm Chat Bot! May I know your name?" }
3
  ];
 
 
 
4
  let userName = ''; // To store the user's name
5
 
6
  function addMessage(role, message) {
 
40
  console.error('Chat messages container not found for form!');
41
  return;
42
  }
43
+ // Prevent duplicate forms
44
+ if (chatMessages.querySelector('.registration-form')) {
45
+ console.log('Form already exists, skipping display.');
46
+ return;
47
+ }
48
  const formDiv = document.createElement('div');
49
  formDiv.className = 'bot-message';
50
  formDiv.innerHTML = `
 
167
  { text: 'How do I update my account information?', class: 'blue' },
168
  { text: 'Can I leave a review for a product?', class: 'blue' },
169
  { text: 'How do I report a product issue?', class: 'blue' },
170
+ { text: 'Other', class: 'green' }
171
  ];
172
  } else if (lastMessage.includes('what is tionat?')) {
173
  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.';
 
209
  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.';
210
  } else if (lastMessage.includes('do you offer free shipping?')) {
211
  botResponse = 'Yes, we offer free shipping on orders above a certain amount. Check the shipping details at checkout to confirm eligibility.';
212
+ } else if (lastMessage.includes('how do I return a product?')) {
213
  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.';
214
  } else if (lastMessage.includes('how can i contact customer service?')) {
215
  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.';
 
233
  displayForm();
234
  return; // Stop further processing since we're showing the form
235
  } else {
236
+ // Instead of showing the form, guide the user to select "Other"
237
+ botResponse = "I'm sorry, I don't understand your query. Please select the 'Other' option to proceed.";
238
  addMessage('bot', botResponse);
239
+
240
+ // Redisplay the FAQ options if they aren't already visible
241
+ if (conversation.length > 2 && !document.querySelector('.option-button')) {
242
+ options = [
243
+ { text: 'What is TioNat?', class: 'blue' },
244
+ { text: 'How do I create an account on TioNat?', class: 'blue' },
245
+ { text: 'How can I track my order?', class: 'blue' },
246
+ { text: 'Do you ship internationally?', class: 'blue' },
247
+ { text: 'What payment methods do you accept?', class: 'blue' },
248
+ { text: 'What is the best supplement for boosting immunity?', class: 'blue' },
249
+ { text: 'Are your nutritional supplements vegan-friendly?', class: 'blue' },
250
+ { text: 'How do I know which supplement is right for me?', class: 'blue' },
251
+ { text: 'Are there any side effects of using your supplements?', class: 'blue' },
252
+ { text: 'Do you offer products for specific health conditions?', class: 'blue' },
253
+ { text: 'How do I use your health care products?', class: 'blue' },
254
+ { text: 'Do your products come with a money-back guarantee?', class: 'blue' },
255
+ { text: 'Are your health care products FDA-approved?', class: 'blue' },
256
+ { text: 'Are your personal care products cruelty-free?', class: 'blue' },
257
+ { text: 'What ingredients do you use in your skincare products?', class: 'blue' },
258
+ { text: 'Can I use your personal care products for sensitive skin?', class: 'blue' },
259
+ { text: 'How do I find the right skincare routine?', class: 'blue' },
260
+ { text: 'Can I modify or cancel my order after placing it?', class: 'blue' },
261
+ { text: 'How long does it take to receive my order?', class: 'blue' },
262
+ { text: 'Do you offer free shipping?', class: 'blue' },
263
+ { text: 'How do I return a product?', class: 'blue' },
264
+ { text: 'How can I contact customer service?', class: 'blue' },
265
+ { text: 'Can I track my return?', class: 'blue' },
266
+ { text: 'How can I get a product recommendation?', class: 'blue' },
267
+ { text: 'How do I reset my password?', class: 'blue' },
268
+ { text: 'Is my payment information secure?', class: 'blue' },
269
+ { text: 'How do I update my account information?', class: 'blue' },
270
+ { text: 'Can I leave a review for a product?', class: 'blue' },
271
+ { text: 'How do I report a product issue?', class: 'blue' },
272
+ { text: 'Other', class: 'green' }
273
+ ];
274
+ displayOptions(options);
275
+ }
276
+ return; // Stop further processing
277
  }
278
 
279
  addMessage('bot', botResponse);