Spaces:
Sleeping
Sleeping
Update templates/customdish.html
Browse files- templates/customdish.html +123 -141
templates/customdish.html
CHANGED
@@ -379,154 +379,136 @@
|
|
379 |
</head>
|
380 |
<body>
|
381 |
<div class="chat-container">
|
382 |
-
|
383 |
-
|
384 |
-
|
|
|
|
|
|
|
|
|
|
|
385 |
</div>
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
// Start the conversation directly
|
410 |
-
function startConversation() {
|
411 |
-
if (userName) {
|
412 |
-
addMessage('bot', `Nice to meet you, ${userName}! 😊 Let's create your perfect meal! What type of food would you prefer?`);
|
413 |
-
displayOptions([
|
414 |
-
{ text: 'Vegetarian', class: 'green' },
|
415 |
-
{ text: 'Non-Vegetarian', class: 'red' }
|
416 |
-
]);
|
417 |
-
} else {
|
418 |
-
addMessage('bot', 'Hi! Please log in to continue.');
|
419 |
-
}
|
420 |
-
}
|
421 |
-
|
422 |
-
// Function to add messages to the chat container
|
423 |
-
function addMessage(role, message) {
|
424 |
-
const chatMessages = document.getElementById('chatMessages');
|
425 |
-
if (!chatMessages) {
|
426 |
-
console.error('Chat messages container not found!');
|
427 |
-
return;
|
428 |
-
}
|
429 |
-
const messageDiv = document.createElement('div');
|
430 |
-
messageDiv.className = role === 'bot' ? 'bot-message' : 'user-message';
|
431 |
-
messageDiv.textContent = message;
|
432 |
-
chatMessages.appendChild(messageDiv);
|
433 |
-
chatMessages.scrollTop = chatMessages.scrollHeight;
|
434 |
-
console.log(`Added ${role} message: ${message}`);
|
435 |
-
}
|
436 |
-
|
437 |
-
// Function to send user input
|
438 |
-
function sendMessage() {
|
439 |
-
const userInput = document.getElementById('userInput');
|
440 |
-
if (!userInput) {
|
441 |
-
console.error('User input field not found!');
|
442 |
-
return;
|
443 |
-
}
|
444 |
-
const message = userInput.value.trim();
|
445 |
-
if (message) {
|
446 |
-
addMessage('user', message);
|
447 |
-
conversation.push({ role: 'user', message: message });
|
448 |
-
userInput.value = '';
|
449 |
-
setTimeout(() => handleResponse(message), 500);
|
450 |
-
} else {
|
451 |
-
console.warn('Empty message!');
|
452 |
-
}
|
453 |
-
displayCart();
|
454 |
-
}
|
455 |
-
|
456 |
-
// Handle the response based on the user input
|
457 |
-
function handleResponse(userInput) {
|
458 |
-
const lastMessage = userInput.toLowerCase();
|
459 |
-
let botResponse = '';
|
460 |
-
let options = [];
|
461 |
-
|
462 |
-
if (lastMessage.includes('non-vegetarian')) {
|
463 |
-
conversation.push({ role: 'user', message: 'Non-Vegetarian' });
|
464 |
-
console.log("Food preference selected: Non-Vegetarian");
|
465 |
-
botResponse = `Great choice, ${userName}! 🍽️ Please select a non-vegetarian option:`;
|
466 |
-
fetchIngredients('non-vegetarian');
|
467 |
-
return;
|
468 |
-
} else if (lastMessage.includes('vegetarian')) {
|
469 |
-
conversation.push({ role: 'user', message: 'Vegetarian' });
|
470 |
-
console.log("Food preference selected: Vegetarian");
|
471 |
-
botResponse = `Great choice, ${userName}! 🍽️ Here are some vegetarian ingredients:`;
|
472 |
-
fetchIngredients('vegetarian');
|
473 |
-
return;
|
474 |
-
} else if (lastMessage.includes('chicken') || lastMessage.includes('beef') || lastMessage.includes('lamb')) {
|
475 |
-
conversation.push({ role: 'user', message: lastMessage });
|
476 |
-
console.log(`Non-veg option selected: ${lastMessage}`);
|
477 |
-
botResponse = `Great! Here are some ${lastMessage} ingredients available:`;
|
478 |
-
fetchIngredients(lastMessage.toLowerCase());
|
479 |
-
return;
|
480 |
-
} else if (lastMessage.includes('yes') && selectedMenuItem) {
|
481 |
-
botResponse = 'Here are some ingredients to customize your dish:';
|
482 |
-
handleYesResponse();
|
483 |
-
return;
|
484 |
-
} else if (lastMessage.includes('no') && selectedMenuItem) {
|
485 |
-
// Submit the dish without customization
|
486 |
-
submitCustomizationIngredients();
|
487 |
-
return;
|
488 |
-
} else if (lastMessage.includes('yes') && currentStep === 'post_cart') {
|
489 |
-
// After user says 'yes', ask again for food preference (veg or non-veg)
|
490 |
-
botResponse = `Let's get started again! What type of food would you prefer this time?`;
|
491 |
-
options = [
|
492 |
-
{ text: 'Vegetarian', class: 'green' },
|
493 |
-
{ text: 'Non-Vegetarian', class: 'red' }
|
494 |
-
];
|
495 |
-
currentStep = 'food_type';
|
496 |
-
addMessage('bot', botResponse);
|
497 |
-
displayOptions(options);
|
498 |
-
return;
|
499 |
-
} else if (lastMessage.includes('non-vegetarian') && currentStep === 'food_type') {
|
500 |
-
// Handle non-vegetarian selection
|
501 |
-
conversation.push({ role: 'user', message: 'Non-Vegetarian' });
|
502 |
-
console.log("Food preference selected: Non-Vegetarian");
|
503 |
-
botResponse = `Great choice, ${userName}! 🍽️ Please select a non-vegetarian option:`;
|
504 |
-
fetchIngredients('non-vegetarian');
|
505 |
-
return;
|
506 |
-
} else if (lastMessage.includes('vegetarian') && currentStep === 'food_type') {
|
507 |
-
// Handle vegetarian selection
|
508 |
-
conversation.push({ role: 'user', message: 'Vegetarian' });
|
509 |
-
console.log("Food preference selected: Vegetarian");
|
510 |
-
botResponse = `Great choice, ${userName}! 🍽️ Here are some vegetarian ingredients:`;
|
511 |
-
fetchIngredients('vegetarian');
|
512 |
-
return;
|
513 |
-
} else if (lastMessage.includes('no') && currentStep === 'post_cart') {
|
514 |
-
addMessage('bot', 'Awesome! 🧾 Here’s your final cart:');
|
515 |
-
displayCart(); // Optional: show final cart again
|
516 |
-
addMessage('bot', 'Thank you for your order! 👨🍳🍲');
|
517 |
-
currentStep = 'end';
|
518 |
-
return;
|
519 |
}
|
520 |
|
521 |
-
|
522 |
-
|
523 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
524 |
}
|
525 |
-
|
526 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
527 |
|
528 |
|
529 |
|
|
|
|
|
|
|
|
|
|
|
|
|
530 |
|
531 |
function handleYesResponse() {
|
532 |
if (!selectedMenuItem) {
|
|
|
379 |
</head>
|
380 |
<body>
|
381 |
<div class="chat-container">
|
382 |
+
<div class="chat-header">🍳 Chef Bot</div>
|
383 |
+
<div class="chat-messages" id="chatMessages">
|
384 |
+
<div class="bot-message">Hi there! I'm Chef Bot! May I know your name?</div>
|
385 |
+
</div>
|
386 |
+
<div class="chat-input">
|
387 |
+
<input type="text" id="userInput" placeholder="Type your name or message...">
|
388 |
+
<button onclick="sendMessage()">Send</button>
|
389 |
+
</div>
|
390 |
</div>
|
391 |
+
|
392 |
+
<script>
|
393 |
+
let currentStep = 'greeting'; // other possible values: 'food_type', 'select_ingredients', 'menu_display', 'customization', 'post_cart'
|
394 |
+
|
395 |
+
let conversation = [
|
396 |
+
{ role: 'bot', message: "Hi there! I'm Chef Bot! May I know your name?" }
|
397 |
+
];
|
398 |
+
let selectedIngredients = [];
|
399 |
+
let selectedMenuItem = null;
|
400 |
+
let cart = [];
|
401 |
+
|
402 |
+
function addMessage(role, message) {
|
403 |
+
const chatMessages = document.getElementById('chatMessages');
|
404 |
+
if (!chatMessages) {
|
405 |
+
console.error('Chat messages container not found!');
|
406 |
+
return;
|
407 |
+
}
|
408 |
+
const messageDiv = document.createElement('div');
|
409 |
+
messageDiv.className = role === 'bot' ? 'bot-message' : 'user-message';
|
410 |
+
messageDiv.textContent = message;
|
411 |
+
chatMessages.appendChild(messageDiv);
|
412 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
413 |
+
console.log(`Added ${role} message: ${message}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
414 |
}
|
415 |
|
416 |
+
function sendMessage() {
|
417 |
+
const userInput = document.getElementById('userInput');
|
418 |
+
if (!userInput) {
|
419 |
+
console.error('User input field not found!');
|
420 |
+
return;
|
421 |
+
}
|
422 |
+
const message = userInput.value.trim();
|
423 |
+
if (message) {
|
424 |
+
addMessage('user', message);
|
425 |
+
conversation.push({ role: 'user', message: message });
|
426 |
+
userInput.value = '';
|
427 |
+
setTimeout(() => handleResponse(message), 500);
|
428 |
+
} else {
|
429 |
+
console.warn('Empty message!');
|
430 |
+
}
|
431 |
+
displayCart();
|
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 |
+
botResponse = `Nice to meet you, ${userInput}! 😊 Let's create your perfect meal! What type of food would you prefer?`;
|
441 |
+
options = [
|
442 |
+
{ text: 'Vegetarian', class: 'green' },
|
443 |
+
{ text: 'Non-Vegetarian', class: 'red' }
|
444 |
+
];
|
445 |
+
} else if (lastMessage.includes('non-vegetarian')) {
|
446 |
+
conversation.push({ role: 'user', message: 'Non-Vegetarian' });
|
447 |
+
console.log("Food preference selected: Non-Vegetarian");
|
448 |
+
botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
|
449 |
+
fetchIngredients('non-vegetarian');
|
450 |
+
return;
|
451 |
+
} else if (lastMessage.includes('vegetarian')) {
|
452 |
+
conversation.push({ role: 'user', message: 'Vegetarian' });
|
453 |
+
console.log("Food preference selected: Vegetarian");
|
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 |
+
conversation.push({ role: 'user', message: lastMessage });
|
459 |
+
console.log(`Non-veg option selected: ${lastMessage}`);
|
460 |
+
botResponse = `Great! Here are some ${lastMessage} ingredients available:`;
|
461 |
+
fetchIngredients(lastMessage.toLowerCase());
|
462 |
+
return;
|
463 |
+
} else if (lastMessage.includes('yes') && selectedMenuItem) {
|
464 |
+
botResponse = 'Here are some ingredients to customize your dish:';
|
465 |
+
handleYesResponse();
|
466 |
+
return;
|
467 |
+
} else if (lastMessage.includes('no') && selectedMenuItem) {
|
468 |
+
// Submit the dish without customization
|
469 |
+
submitCustomizationIngredients();
|
470 |
+
return;
|
471 |
+
} else if (lastMessage.includes('yes') && currentStep === 'post_cart') {
|
472 |
+
// After user says 'yes', ask again for food preference (veg or non-veg)
|
473 |
+
botResponse = `Let's get started again! What type of food would you prefer this time?`;
|
474 |
+
options = [
|
475 |
+
{ text: 'Vegetarian', class: 'green' },
|
476 |
+
{ text: 'Non-Vegetarian', class: 'red' }
|
477 |
+
];
|
478 |
+
currentStep = 'food_type';
|
479 |
+
addMessage('bot', botResponse);
|
480 |
+
displayOptions(options);
|
481 |
+
return;
|
482 |
+
} else if (lastMessage.includes('non-vegetarian') && currentStep === 'food_type') {
|
483 |
+
// Handle non-vegetarian selection
|
484 |
+
conversation.push({ role: 'user', message: 'Non-Vegetarian' });
|
485 |
+
console.log("Food preference selected: Non-Vegetarian");
|
486 |
+
botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
|
487 |
+
fetchIngredients('non-vegetarian');
|
488 |
+
return;
|
489 |
+
} else if (lastMessage.includes('vegetarian') && currentStep === 'food_type') {
|
490 |
+
// Handle vegetarian selection
|
491 |
+
conversation.push({ role: 'user', message: 'Vegetarian' });
|
492 |
+
console.log("Food preference selected: Vegetarian");
|
493 |
+
botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
|
494 |
+
fetchIngredients('vegetarian');
|
495 |
+
return;
|
496 |
+
} else if (lastMessage.includes('no') && currentStep === 'post_cart') {
|
497 |
+
addMessage('bot', 'Awesome! 🧾 Here’s your final cart:');
|
498 |
+
displayCart(); // Optional: show final cart again
|
499 |
+
addMessage('bot', 'Thank you for your order! 👨🍳🍲');
|
500 |
+
currentStep = 'end';
|
501 |
+
return;
|
502 |
+
}
|
503 |
|
504 |
|
505 |
|
506 |
+
addMessage('bot', botResponse);
|
507 |
+
if (options.length > 0) {
|
508 |
+
displayOptions(options);
|
509 |
+
}
|
510 |
+
displayCart();
|
511 |
+
}
|
512 |
|
513 |
function handleYesResponse() {
|
514 |
if (!selectedMenuItem) {
|