ajaybolloju commited on
Commit
6e72a31
·
verified ·
1 Parent(s): 219a309

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +27 -22
static/script.js CHANGED
@@ -61,7 +61,9 @@ function clearChat() {
61
 
62
  function displayForm() {
63
  const chatMessages = document.getElementById('chatMessages');
64
- if (!chatMessages) {
 
 
65
  console.error('Chat messages container not found for form!');
66
  return;
67
  }
@@ -206,7 +208,7 @@ function displayCategories() {
206
  { text: 'Can I leave a review for a product?', class: 'blue' },
207
  { text: 'How do I report a product issue?', class: 'blue' }
208
  ]},
209
- { text: 'Other', class: 'green' }
210
  ];
211
 
212
  const chatMessages = document.getElementById('chatMessages');
@@ -229,6 +231,7 @@ function displayCategories() {
229
  addMessage('bot', "Please provide more details about your query so our service agent can assist you.");
230
  displayForm();
231
  } else {
 
232
  displayOptions(category.questions);
233
  }
234
  };
@@ -253,20 +256,17 @@ function handleResponse(userInput) {
253
  return;
254
  }
255
 
256
- // Handle category selection and FAQ responses
257
- if (lastMessage.includes('about tionat and account setup')) {
 
 
 
 
 
258
  return; // Questions are already displayed via displayOptions
259
- } else if (lastMessage.includes('nutritional supplements')) {
260
- return;
261
- } else if (lastMessage.includes('health care products')) {
262
- return;
263
- } else if (lastMessage.includes('personal care and skincare')) {
264
- return;
265
- } else if (lastMessage.includes('returns and customer support')) {
266
- return;
267
- } else if (lastMessage.includes('security and account management')) {
268
- return;
269
- } else if (lastMessage.includes('other')) {
270
  addMessage('bot', "Please provide more details about your query so our service agent can assist you.");
271
  displayForm();
272
  return;
@@ -284,10 +284,10 @@ function handleResponse(userInput) {
284
  } else if (lastMessage.includes('what payment methods do you accept?')) {
285
  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).';
286
  } else if (lastMessage.includes('what is the best supplement for boosting immunity?')) {
287
- 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.';
288
  } else if (lastMessage.includes('are your nutritional supplements vegan-friendly?')) {
289
- botResponse = 'Yes, many of our nutritional supplements are vegan-friendly. Please check the product details for specific information on ingredients and certifications.';
290
- } else if (lastMessage.includes('how do i know which supplement is right for me?')) {
291
  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.';
292
  } else if (lastMessage.includes('are there any side effects of using your supplements?')) {
293
  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.';
@@ -313,7 +313,7 @@ function handleResponse(userInput) {
313
  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.';
314
  } else if (lastMessage.includes('do you offer free shipping?')) {
315
  botResponse = 'Yes, we offer free shipping on orders above a certain amount. Check the shipping details at checkout to confirm eligibility.';
316
- } else if (lastMessage.includes('how do I return a product?')) {
317
  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.';
318
  } else if (lastMessage.includes('how can i contact customer service?')) {
319
  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.';
@@ -332,13 +332,18 @@ function handleResponse(userInput) {
332
  } else if (lastMessage.includes('how do i report a product issue?')) {
333
  botResponse = 'If you receive a defective or damaged product, please contact our customer service immediately for assistance with returns or exchanges.';
334
  } else {
 
335
  botResponse = "I'm sorry, I don't understand your query. Please select a category to explore common questions or choose 'Other' to submit a custom query.";
336
  addMessage('bot', botResponse);
337
- if (!document.querySelector('.option-button')) {
338
- displayCategories();
339
- }
340
  return;
341
  }
342
 
 
 
 
 
 
343
  addMessage('bot', botResponse);
 
344
  }
 
61
 
62
  function displayForm() {
63
  const chatMessages = document.getElementById('chatMessages');
64
+ if (!chat
65
+
66
+ Messages) {
67
  console.error('Chat messages container not found for form!');
68
  return;
69
  }
 
208
  { text: 'Can I leave a review for a product?', class: 'blue' },
209
  { text: 'How do I report a product issue?', class: 'blue' }
210
  ]},
211
+ { text: 'Other', class: 'green', questions: [] }
212
  ];
213
 
214
  const chatMessages = document.getElementById('chatMessages');
 
231
  addMessage('bot', "Please provide more details about your query so our service agent can assist you.");
232
  displayForm();
233
  } else {
234
+ addMessage('bot', `Please select a question from the ${category.text} category:`);
235
  displayOptions(category.questions);
236
  }
237
  };
 
256
  return;
257
  }
258
 
259
+ // Handle category selection
260
+ if (lastMessage === 'about tionat and account setup' ||
261
+ lastMessage === 'nutritional supplements' ||
262
+ lastMessage === 'health care products' ||
263
+ lastMessage === 'personal care and skincare' ||
264
+ lastMessage === 'returns and customer support' ||
265
+ lastMessage === 'security and account management') {
266
  return; // Questions are already displayed via displayOptions
267
+ }
268
+
269
+ if (lastMessage === 'other') {
 
 
 
 
 
 
 
 
270
  addMessage('bot', "Please provide more details about your query so our service agent can assist you.");
271
  displayForm();
272
  return;
 
284
  } else if (lastMessage.includes('what payment methods do you accept?')) {
285
  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).';
286
  } else if (lastMessage.includes('what is the best supplement for boosting immunity?')) {
287
+ botResponse = 'Our Immunity Booster supplements, like Vitamin C, Zinc, and Echinacea, are popular choices for improving immune system health. We recommend consulting with aerverside professional before choosing a supplement.';
288
  } else if (lastMessage.includes('are your nutritional supplements vegan-friendly?')) {
289
+ botResponse = 'Yes, outbreak of our nutritional supplements are vegan-friendly. Please check the product details for specific information on ingredients and certifications.';
290
+ } else if (lastMessage.includes('how do i know which supplement is right bra me?')) {
291
  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.';
292
  } else if (lastMessage.includes('are there any side effects of using your supplements?')) {
293
  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.';
 
313
  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.';
314
  } else if (lastMessage.includes('do you offer free shipping?')) {
315
  botResponse = 'Yes, we offer free shipping on orders above a certain amount. Check the shipping details at checkout to confirm eligibility.';
316
+ } else if (lastMessage.includes('how do i return a product?')) {
317
  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.';
318
  } else if (lastMessage.includes('how can i contact customer service?')) {
319
  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.';
 
332
  } else if (lastMessage.includes('how do i report a product issue?')) {
333
  botResponse = 'If you receive a defective or damaged product, please contact our customer service immediately for assistance with returns or exchanges.';
334
  } else {
335
+ // If the user types something unrelated, redisplay categories
336
  botResponse = "I'm sorry, I don't understand your query. Please select a category to explore common questions or choose 'Other' to submit a custom query.";
337
  addMessage('bot', botResponse);
338
+ displayCategories();
 
 
339
  return;
340
  }
341
 
342
+ // Display the bot's response to the selected FAQ
343
+ addMessage('bot', botResponse);
344
+
345
+ // After answering, redisplay the categories to allow the user to ask another question
346
+ botResponse = "Would you like to explore another category?";
347
  addMessage('bot', botResponse);
348
+ displayCategories();
349
  }