nagasurendra commited on
Commit
d9844b8
·
verified ·
1 Parent(s): b56fede

Update templates/customdish.html

Browse files
Files changed (1) hide show
  1. templates/customdish.html +30 -23
templates/customdish.html CHANGED
@@ -391,35 +391,30 @@
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
- // Simulate sending a message automatically when the page loads
402
  window.onload = function() {
403
- // You can check if the name is in the sessionStorage and decide when to send a message
404
  if (sessionStorage.getItem('user_name')) {
405
- // If user is logged in and name exists in sessionStorage, greet the user
406
- setTimeout(() => {
407
- const userInput = sessionStorage.getItem('user_name'); // Get the user's name from session
408
- addMessage('user', userInput); // Optionally, you can add the user's name to the chat
409
- handleResponse(userInput); // Automatically call handleResponse to continue the conversation
410
- }, 500); // Delay before sending the message automatically
 
 
411
  } else {
412
  // If name is not in session, ask for the name
413
- setTimeout(() => {
414
- const message = "Hi there! I'm Chef Bot! May I know your name?"; // Set the default message
415
- addMessage('bot', message); // Add this message to the chat
416
- }, 500);
417
- }
418
  };
419
-
420
-
421
-
422
-
423
  function addMessage(role, message) {
424
  const chatMessages = document.getElementById('chatMessages');
425
  if (!chatMessages) {
@@ -431,10 +426,22 @@
431
  messageDiv.textContent = message;
432
  chatMessages.appendChild(messageDiv);
433
  chatMessages.scrollTop = chatMessages.scrollHeight;
434
- console.log(`Added ${role} message: ${message}`);
435
  }
436
 
437
- // Modified sendMessage function to be triggered automatically
 
 
 
 
 
 
 
 
 
 
 
 
 
438
  function sendMessage() {
439
  const userInput = document.getElementById('userInput').value.trim();
440
  if (userInput) {
 
391
 
392
  <script>
393
  let currentStep = 'greeting'; // other possible values: 'food_type', 'select_ingredients', 'menu_display', 'customization', 'post_cart'
394
+ let conversation = [];
 
 
 
395
  let selectedIngredients = [];
396
  let selectedMenuItem = null;
397
  let cart = [];
398
+
399
  window.onload = function() {
400
+ // Check if the name is in sessionStorage
401
  if (sessionStorage.getItem('user_name')) {
402
+ // If the user is logged in and name exists in sessionStorage, greet the user
403
+ const userName = sessionStorage.getItem('user_name'); // Get the user's name from session
404
+ conversation.push({ role: 'bot', message: `Nice to meet you, ${userName}! 😊 Let's create your perfect meal! What type of food would you prefer?` });
405
+ displayConversation(); // Function to display the conversation
406
+ displayOptions([
407
+ { text: 'Vegetarian', class: 'green' },
408
+ { text: 'Non-Vegetarian', class: 'red' }
409
+ ]);
410
  } else {
411
  // If name is not in session, ask for the name
412
+ conversation.push({ role: 'bot', message: "Hi there! I'm Chef Bot! May I know your name?" });
413
+ displayConversation(); // Function to display the conversation
414
+ }
 
 
415
  };
416
+
417
+ // Function to add messages to the chat
 
 
418
  function addMessage(role, message) {
419
  const chatMessages = document.getElementById('chatMessages');
420
  if (!chatMessages) {
 
426
  messageDiv.textContent = message;
427
  chatMessages.appendChild(messageDiv);
428
  chatMessages.scrollTop = chatMessages.scrollHeight;
 
429
  }
430
 
431
+ // Function to display all conversation messages
432
+ function displayConversation() {
433
+ const chatMessages = document.getElementById('chatMessages');
434
+ chatMessages.innerHTML = ''; // Clear previous messages
435
+ conversation.forEach(msg => {
436
+ const messageDiv = document.createElement('div');
437
+ messageDiv.className = msg.role === 'bot' ? 'bot-message' : 'user-message';
438
+ messageDiv.textContent = msg.message;
439
+ chatMessages.appendChild(messageDiv);
440
+ });
441
+ chatMessages.scrollTop = chatMessages.scrollHeight; // Scroll to bottom
442
+ }
443
+
444
+ // Modified sendMessage function to be triggered automatically or by the user
445
  function sendMessage() {
446
  const userInput = document.getElementById('userInput').value.trim();
447
  if (userInput) {