Yaswanth56 commited on
Commit
d1b90c5
·
verified ·
1 Parent(s): fb5c95b

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +12 -5
static/script.js CHANGED
@@ -41,26 +41,24 @@ function handleResponse(userInput) {
41
  let botResponse = '';
42
  let options = [];
43
 
44
- if (conversation.length === 2) { // After name input
 
45
  botResponse = `Nice to meet you, ${userInput}! 😊 Let's create your perfect meal! What type of food would you prefer?`;
46
  options = [
47
  { text: 'Vegetarian', class: 'green' },
48
  { text: 'Non-Vegetarian', class: 'red' }
49
  ];
50
  } else if (lastMessage.includes('non-vegetarian')) {
51
- conversation.push({ role: 'user', message: 'Non-Vegetarian' });
52
  console.log("Food preference selected: Non-Vegetarian");
53
  botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
54
  fetchIngredients('non-vegetarian');
55
  return;
56
  } else if (lastMessage.includes('vegetarian')) {
57
- conversation.push({ role: 'user', message: 'Vegetarian' });
58
  console.log("Food preference selected: Vegetarian");
59
  botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
60
  fetchIngredients('vegetarian');
61
  return;
62
  } else if (lastMessage.includes('chicken') || lastMessage.includes('beef') || lastMessage.includes('lamb')) {
63
- conversation.push({ role: 'user', message: lastMessage });
64
  console.log(`Non-veg option selected: ${lastMessage}`);
65
  botResponse = `Great! Here are some ${lastMessage} ingredients available:`;
66
  fetchIngredients(lastMessage.toLowerCase());
@@ -77,6 +75,15 @@ function handleResponse(userInput) {
77
  { text: 'No', class: 'red' }
78
  ];
79
  selectedMenuItem = null;
 
 
 
 
 
 
 
 
 
80
  }
81
 
82
  addMessage('bot', botResponse);
@@ -305,7 +312,7 @@ function displayCustomizationInput() {
305
  return;
306
  }
307
 
308
- let customizationArea = document.query|:querySelector('.customization-input');
309
  if (!customizationArea) {
310
  customizationArea = document.createElement('div');
311
  customizationArea.className = 'customization-input';
 
41
  let botResponse = '';
42
  let options = [];
43
 
44
+ // Handle name input (first user response after bot's greeting)
45
+ if (conversation.length === 2 && conversation[0].role === 'bot' && conversation[0].message.includes('May I know your name?')) {
46
  botResponse = `Nice to meet you, ${userInput}! 😊 Let's create your perfect meal! What type of food would you prefer?`;
47
  options = [
48
  { text: 'Vegetarian', class: 'green' },
49
  { text: 'Non-Vegetarian', class: 'red' }
50
  ];
51
  } else if (lastMessage.includes('non-vegetarian')) {
 
52
  console.log("Food preference selected: Non-Vegetarian");
53
  botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
54
  fetchIngredients('non-vegetarian');
55
  return;
56
  } else if (lastMessage.includes('vegetarian')) {
 
57
  console.log("Food preference selected: Vegetarian");
58
  botResponse = 'Great choice! 🍽️ Here are some vegetarian ingredients:';
59
  fetchIngredients('vegetarian');
60
  return;
61
  } else if (lastMessage.includes('chicken') || lastMessage.includes('beef') || lastMessage.includes('lamb')) {
 
62
  console.log(`Non-veg option selected: ${lastMessage}`);
63
  botResponse = `Great! Here are some ${lastMessage} ingredients available:`;
64
  fetchIngredients(lastMessage.toLowerCase());
 
75
  { text: 'No', class: 'red' }
76
  ];
77
  selectedMenuItem = null;
78
+ } else {
79
+ // Fallback for unrecognized input
80
+ botResponse = "Sorry, I didn't understand that. Could you please clarify or choose an option?";
81
+ if (conversation.length === 2) {
82
+ options = [
83
+ { text: 'Vegetarian', class: 'green' },
84
+ { text: 'Non-Vegetarian', class: 'red' }
85
+ ];
86
+ }
87
  }
88
 
89
  addMessage('bot', botResponse);
 
312
  return;
313
  }
314
 
315
+ let customizationArea = document.querySelector('.customization-input');
316
  if (!customizationArea) {
317
  customizationArea = document.createElement('div');
318
  customizationArea.className = 'customization-input';