Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +92 -109
templates/index.html
CHANGED
@@ -432,89 +432,100 @@
|
|
432 |
}
|
433 |
|
434 |
function handleResponse(userInput) {
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
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) {
|