nagasurendra commited on
Commit
94143ed
·
verified ·
1 Parent(s): c28ed90

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +92 -109
templates/index.html CHANGED
@@ -432,89 +432,100 @@
432
  }
433
 
434
  function handleResponse(userInput) {
435
- const lastMessage = conversation[conversation.length - 1].message.toLowerCase();
436
- let botResponse = '';
437
- let options = [];
438
-
439
- if (conversation.length === 2) { // After name input
440
- currentStep = 'food_type';
441
- botResponse = `Nice to meet you, ${userInput}! 😊 Let's create your perfect meal! What type of food would you prefer?`;
442
- options = [
443
- { text: 'Vegetarian', class: 'green' },
444
- { text: 'Non-Vegetarian', class: 'red' }
445
- ];
446
- } else if (lastMessage.includes('non-vegetarian')) {
447
- currentStep = 'select_ingredients';
448
-
449
- conversation.push({ role: 'user', message: 'Non-Vegetarian' });
450
- console.log("Food preference selected: Non-Vegetarian");
451
- botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
452
- fetchIngredients('non-vegetarian');
453
- return;
454
- } else if (lastMessage.includes('vegetarian')) {
455
- currentStep = 'select_ingredients';
456
-
457
- conversation.push({ role: 'user', message: 'Vegetarian' });
458
- console.log("Food preference selected: Vegetarian");
459
- botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
460
- fetchIngredients('vegetarian');
461
- return;
462
- } else if (lastMessage.includes('chicken') || lastMessage.includes('beef') || lastMessage.includes('lamb')) {
463
- conversation.push({ role: 'user', message: lastMessage });
464
- console.log(`Non-veg option selected: ${lastMessage}`);
465
- botResponse = `Great! Here are some ${lastMessage} ingredients available:`;
466
- fetchIngredients(lastMessage.toLowerCase());
467
- return;
468
- } else if (lastMessage.includes('yes') && selectedMenuItem) {
469
- botResponse = 'Here are some ingredients to customize your dish:';
470
- handleYesResponse();
471
- return;
472
- } else if (lastMessage.includes('no') && selectedMenuItem) {
473
- // Submit the dish without customization
474
- submitCustomizationIngredients();
475
- return;
476
- } else if (lastMessage.includes('yes') && currentStep === 'post_cart') {
477
- // After user says 'yes', ask again for food preference (veg or non-veg)
478
- botResponse = `Let's get started again! What type of food would you prefer this time?`;
479
- options = [
480
- { text: 'Vegetarian', class: 'green' },
481
- { text: 'Non-Vegetarian', class: 'red' }
482
- ];
483
- currentStep = 'food_type';
484
- addMessage('bot', botResponse);
485
- displayOptions(options);
486
- return;
487
- } else if (lastMessage.includes('non-vegetarian') && currentStep === 'food_type') {
488
- // Handle non-vegetarian selection
489
- conversation.push({ role: 'user', message: 'Non-Vegetarian' });
490
- console.log("Food preference selected: Non-Vegetarian");
491
- botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
492
- fetchIngredients('non-vegetarian');
493
- return;
494
- } else if (lastMessage.includes('vegetarian') && currentStep === 'food_type') {
495
- // Handle vegetarian selection
496
- conversation.push({ role: 'user', message: 'Vegetarian' });
497
- console.log("Food preference selected: Vegetarian");
498
- botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
499
- fetchIngredients('vegetarian');
500
- return;
501
- } else if (lastMessage.includes('no') && currentStep === 'post_cart') {
502
- addMessage('bot', 'Awesome! 🧾 Here’s your final cart:');
503
- displayCart(); // Optional: show final cart again
504
- addMessage('bot', 'Thank you for your order! 👨‍🍳🍲');
505
- currentStep = 'end';
506
- return;
507
- }
508
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509
 
510
 
511
- addMessage('bot', botResponse);
512
- if (options.length > 0) {
513
- displayOptions(options);
514
- }
515
- displayCart();
516
- }
517
-
518
  function handleYesResponse() {
519
  if (!selectedMenuItem) {
520
  addMessage('bot', 'No dish selected. Please choose a dish first.');
@@ -1013,35 +1024,7 @@
1013
  console.log('Back button added');
1014
  }
1015
 
1016
- function resetToPreviousStep() {
1017
- console.log('Resetting to previous step. Current step:', currentStep);
1018
- // Based on the currentStep, go back to the previous step
1019
- if (currentStep === 'food_type') {
1020
- currentStep = 'greeting';
1021
- conversation.push({ role: 'bot', message: "Hi there! I'm Chef Bot! May I know your name?" });
1022
- console.log('Step changed to greeting. Conversation updated.');
1023
- } else if (currentStep === 'select_ingredients') {
1024
- currentStep = 'food_type';
1025
- conversation.push({ role: 'bot', message: 'What type of food would you prefer?' });
1026
- console.log('Step changed to food_type. Conversation updated.');
1027
- } else if (currentStep === 'customization') {
1028
- currentStep = 'menu_display';
1029
- console.log('Step changed to menu_display.');
1030
- fetchMenuItems({ ingredient_names: ingredientNames });
1031
- // You can add logic here to show the menu items again if needed
1032
- } else if (currentStep === 'post_cart') {
1033
- currentStep = 'food_type';
1034
- conversation.push({ role: 'bot', message: 'What type of food would you prefer?' });
1035
- console.log('Step changed to food_type after post_cart. Conversation updated.');
1036
- } else {
1037
- console.error('Unexpected currentStep value:', currentStep);
1038
- }
1039
 
1040
- // Ensure the bot message is updated according to the previous step
1041
- console.log('Updating bot message based on previous step');
1042
- setTimeout(() => handleResponse(conversation[conversation.length - 1].message), 500);
1043
- }
1044
-
1045
 
1046
 
1047
  document.getElementById('userInput').addEventListener('keypress', function(e) {
 
432
  }
433
 
434
  function handleResponse(userInput) {
435
+ const lastMessage = conversation[conversation.length - 1].message.toLowerCase();
436
+ let botResponse = '';
437
+ let options = [];
438
+
439
+ // Check for previous states and handle accordingly
440
+ if (conversation.length === 2) { // After name input
441
+ currentStep = 'food_type';
442
+ botResponse = `Nice to meet you, ${userInput}! 😊 Let's create your perfect meal! What type of food would you prefer?`;
443
+ options = [
444
+ { text: 'Vegetarian', class: 'green' },
445
+ { text: 'Non-Vegetarian', class: 'red' }
446
+ ];
447
+ } else if (lastMessage.includes('non-vegetarian')) {
448
+ currentStep = 'select_ingredients';
449
+ botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
450
+ fetchIngredients('non-vegetarian');
451
+ return;
452
+ } else if (lastMessage.includes('vegetarian')) {
453
+ currentStep = 'select_ingredients';
454
+ botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
455
+ fetchIngredients('vegetarian');
456
+ return;
457
+ } else if (lastMessage.includes('chicken') || lastMessage.includes('beef') || lastMessage.includes('lamb')) {
458
+ currentStep = 'select_ingredients';
459
+ botResponse = `Great! Here are some ${lastMessage} ingredients available:`;
460
+ fetchIngredients(lastMessage.toLowerCase());
461
+ return;
462
+ } else if (lastMessage.includes('yes') && selectedMenuItem) {
463
+ botResponse = 'Here are some ingredients to customize your dish:';
464
+ handleYesResponse();
465
+ return;
466
+ } else if (lastMessage.includes('no') && selectedMenuItem) {
467
+ // Submit the dish without customization
468
+ submitCustomizationIngredients();
469
+ return;
470
+ } else if (lastMessage.includes('yes') && currentStep === 'post_cart') {
471
+ // After user says 'yes', ask again for food preference (veg or non-veg)
472
+ botResponse = `Let's get started again! What type of food would you prefer this time?`;
473
+ options = [
474
+ { text: 'Vegetarian', class: 'green' },
475
+ { text: 'Non-Vegetarian', class: 'red' }
476
+ ];
477
+ currentStep = 'food_type';
478
+ addMessage('bot', botResponse);
479
+ displayOptions(options);
480
+ return;
481
+ } else if (lastMessage.includes('no') && currentStep === 'post_cart') {
482
+ addMessage('bot', 'Awesome! 🧾 Here’s your final cart:');
483
+ displayCart(); // Optional: show final cart again
484
+ addMessage('bot', 'Thank you for your order! 👨‍🍳🍲');
485
+ currentStep = 'end'; // Step after cart
486
+ return;
487
+ } else if (currentStep === 'customization') {
488
+ currentStep = 'menu_display'; // Reverting to menu display after customization
489
+ console.log('Step changed to menu_display.');
490
+ fetchMenuItems({ ingredient_names: ingredientNames });
491
+ return;
492
+ }
493
+
494
+ addMessage('bot', botResponse);
495
+ if (options.length > 0) {
496
+ displayOptions(options);
497
+ }
498
+ displayCart();
499
+ }
500
+
501
+ function resetToPreviousStep() {
502
+ console.log('Resetting to previous step. Current step:', currentStep);
503
+ // Based on the currentStep, go back to the previous step
504
+ if (currentStep === 'food_type') {
505
+ currentStep = 'greeting';
506
+ conversation.push({ role: 'bot', message: "Hi there! I'm Chef Bot! May I know your name?" });
507
+ console.log('Step changed to greeting. Conversation updated.');
508
+ } else if (currentStep === 'select_ingredients') {
509
+ currentStep = 'food_type';
510
+ conversation.push({ role: 'bot', message: 'What type of food would you prefer?' });
511
+ console.log('Step changed to food_type. Conversation updated.');
512
+ } else if (currentStep === 'customization') {
513
+ currentStep = 'menu_display';
514
+ console.log('Step changed to menu_display.');
515
+ fetchMenuItems({ ingredient_names: ingredientNames });
516
+ } else if (currentStep === 'post_cart') {
517
+ currentStep = 'food_type';
518
+ conversation.push({ role: 'bot', message: 'What type of food would you prefer?' });
519
+ console.log('Step changed to food_type after post_cart. Conversation updated.');
520
+ } else {
521
+ console.error('Unexpected currentStep value:', currentStep);
522
+ }
523
+
524
+ // Ensure the bot message is updated according to the previous step
525
+ setTimeout(() => handleResponse(conversation[conversation.length - 1].message), 500);
526
+ }
527
 
528
 
 
 
 
 
 
 
 
529
  function handleYesResponse() {
530
  if (!selectedMenuItem) {
531
  addMessage('bot', 'No dish selected. Please choose a dish first.');
 
1024
  console.log('Back button added');
1025
  }
1026
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1027
 
 
 
 
 
 
1028
 
1029
 
1030
  document.getElementById('userInput').addEventListener('keypress', function(e) {