Spaces:
Runtime error
Runtime error
Update templates/customdish.html
Browse files- templates/customdish.html +29 -23
templates/customdish.html
CHANGED
@@ -378,17 +378,7 @@
|
|
378 |
</style>
|
379 |
</head>
|
380 |
<body>
|
381 |
-
|
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 |
|
@@ -398,6 +388,27 @@
|
|
398 |
let selectedIngredients = [];
|
399 |
let selectedMenuItem = null;
|
400 |
let cart = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
401 |
|
402 |
function addMessage(role, message) {
|
403 |
const chatMessages = document.getElementById('chatMessages');
|
@@ -413,22 +424,17 @@
|
|
413 |
console.log(`Added ${role} message: ${message}`);
|
414 |
}
|
415 |
|
|
|
416 |
function sendMessage() {
|
417 |
-
const userInput = document.getElementById('userInput');
|
418 |
-
if (
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
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) {
|
|
|
378 |
</style>
|
379 |
</head>
|
380 |
<body>
|
381 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
382 |
<script>
|
383 |
let currentStep = 'greeting'; // other possible values: 'food_type', 'select_ingredients', 'menu_display', 'customization', 'post_cart'
|
384 |
|
|
|
388 |
let selectedIngredients = [];
|
389 |
let selectedMenuItem = null;
|
390 |
let cart = [];
|
391 |
+
// Simulate sending a message automatically when the page loads
|
392 |
+
window.onload = function() {
|
393 |
+
// You can check if the name is in the sessionStorage and decide when to send a message
|
394 |
+
if (sessionStorage.getItem('user_name')) {
|
395 |
+
// If user is logged in and name exists in sessionStorage, greet the user
|
396 |
+
setTimeout(() => {
|
397 |
+
const userInput = sessionStorage.getItem('user_name'); // Get the user's name from session
|
398 |
+
addMessage('user', userInput); // Optionally, you can add the user's name to the chat
|
399 |
+
handleResponse(userInput); // Automatically call handleResponse to continue the conversation
|
400 |
+
}, 500); // Delay before sending the message automatically
|
401 |
+
} else {
|
402 |
+
// If name is not in session, ask for the name
|
403 |
+
setTimeout(() => {
|
404 |
+
const message = "Hi there! I'm Chef Bot! May I know your name?"; // Set the default message
|
405 |
+
addMessage('bot', message); // Add this message to the chat
|
406 |
+
}, 500);
|
407 |
+
}
|
408 |
+
};
|
409 |
+
|
410 |
+
|
411 |
+
|
412 |
|
413 |
function addMessage(role, message) {
|
414 |
const chatMessages = document.getElementById('chatMessages');
|
|
|
424 |
console.log(`Added ${role} message: ${message}`);
|
425 |
}
|
426 |
|
427 |
+
// Modified sendMessage function to be triggered automatically
|
428 |
function sendMessage() {
|
429 |
+
const userInput = document.getElementById('userInput').value.trim();
|
430 |
+
if (userInput) {
|
431 |
+
addMessage('user', userInput);
|
432 |
+
conversation.push({ role: 'user', message: userInput });
|
433 |
+
document.getElementById('userInput').value = ''; // Clear input field
|
434 |
+
setTimeout(() => handleResponse(userInput), 500);
|
|
|
|
|
|
|
|
|
|
|
435 |
} else {
|
436 |
console.warn('Empty message!');
|
437 |
}
|
|
|
438 |
}
|
439 |
|
440 |
function handleResponse(userInput) {
|