nagasurendra commited on
Commit
2bc942c
·
verified ·
1 Parent(s): ba57252

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +30 -9
static/script.js CHANGED
@@ -42,7 +42,7 @@ function handleResponse(userInput) {
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' }
@@ -53,7 +53,7 @@ function handleResponse(userInput) {
53
  botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
54
  fetchIngredients('non-vegetarian');
55
  return;
56
-
57
  }
58
  else if (lastMessage.includes('vegetarian')) {
59
  conversation.push({ role: 'user', message: 'Vegetarian' });
@@ -63,8 +63,8 @@ function handleResponse(userInput) {
63
  return;
64
  } else if (lastMessage.includes('chicken') || lastMessage.includes('beef') || lastMessage.includes('lamb')) {
65
  conversation.push({ role: 'user', message: lastMessage });
66
- console.log(Non-veg option selected: ${lastMessage});
67
- botResponse = Great! Here are some ${lastMessage} ingredients available:;
68
  fetchIngredients(lastMessage.toLowerCase());
69
  return;
70
  } else if (lastMessage.includes('yes') && selectedMenuItem) {
@@ -98,7 +98,7 @@ function fetchIngredients(foodPreference) {
98
  .then(response => response.json())
99
  .then(data => {
100
  if (data.error) {
101
- addMessage('bot', Sorry, there was an error fetching ingredients: ${data.error});
102
  } else {
103
  const ingredients = data.ingredients || [];
104
  addMessage('bot', 'Please select ingredients:');
@@ -107,11 +107,32 @@ function fetchIngredients(foodPreference) {
107
  }
108
  })
109
  .catch(error => {
110
- addMessage('bot', Error: Unable to connect to the ingredient database. ${error.message});
111
  });
112
  }
113
 
114
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  function displayIngredientsList(ingredients) {
117
  const chatMessages = document.getElementById('chatMessages');
@@ -186,7 +207,7 @@ function displayMenuItems(menuItems) {
186
  button.textContent = 'Add to Cart';
187
  button.onclick = () => {
188
  selectedMenuItem = item;
189
- addMessage('bot', World-class selection! Would you like to customize your dish further?);
190
  const options = [
191
  { text: 'Yes', class: 'green' },
192
  { text: 'No', class: 'red' }
@@ -334,7 +355,7 @@ function displayOptions(options) {
334
  options.forEach(opt => {
335
  const button = document.createElement('button');
336
  button.textContent = opt.text;
337
- button.className = option-button ${opt.class};
338
  button.onclick = () => {
339
  addMessage('user', opt.text);
340
  conversation.push({ role: 'user', message: opt.text });
 
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' }
 
53
  botResponse = 'Great choice! 🍽️ Please select a non-vegetarian option:';
54
  fetchIngredients('non-vegetarian');
55
  return;
56
+
57
  }
58
  else if (lastMessage.includes('vegetarian')) {
59
  conversation.push({ role: 'user', message: 'Vegetarian' });
 
63
  return;
64
  } else if (lastMessage.includes('chicken') || lastMessage.includes('beef') || lastMessage.includes('lamb')) {
65
  conversation.push({ role: 'user', message: lastMessage });
66
+ console.log(`Non-veg option selected: ${lastMessage}`);
67
+ botResponse = `Great! Here are some ${lastMessage} ingredients available:`;
68
  fetchIngredients(lastMessage.toLowerCase());
69
  return;
70
  } else if (lastMessage.includes('yes') && selectedMenuItem) {
 
98
  .then(response => response.json())
99
  .then(data => {
100
  if (data.error) {
101
+ addMessage('bot', `Sorry, there was an error fetching ingredients: ${data.error}`);
102
  } else {
103
  const ingredients = data.ingredients || [];
104
  addMessage('bot', 'Please select ingredients:');
 
107
  }
108
  })
109
  .catch(error => {
110
+ addMessage('bot', `Error: Unable to connect to the ingredient database. ${error.message}`);
111
  });
112
  }
113
 
114
+ function fetchMenuItems(category) {
115
+ fetch('/get_menu_items', {
116
+ method: 'POST',
117
+ headers: {
118
+ 'Content-Type': 'application/json',
119
+ },
120
+ body: JSON.stringify({ category: category })
121
+ })
122
+ .then(response => response.json())
123
+ .then(data => {
124
+ if (data.error) {
125
+ addMessage('bot', `Sorry, there was an error fetching menu items: ${data.error}`);
126
+ } else {
127
+ const menuItems = data.menu_items || [];
128
+ addMessage('bot', 'Here are some dishes based on your selection:');
129
+ displayMenuItems(menuItems);
130
+ }
131
+ })
132
+ .catch(error => {
133
+ addMessage('bot', `Error: Unable to connect to the menu database. ${error.message}`);
134
+ });
135
+ }
136
 
137
  function displayIngredientsList(ingredients) {
138
  const chatMessages = document.getElementById('chatMessages');
 
207
  button.textContent = 'Add to Cart';
208
  button.onclick = () => {
209
  selectedMenuItem = item;
210
+ addMessage('bot', `World-class selection! Would you like to customize your dish further?`);
211
  const options = [
212
  { text: 'Yes', class: 'green' },
213
  { text: 'No', class: 'red' }
 
355
  options.forEach(opt => {
356
  const button = document.createElement('button');
357
  button.textContent = opt.text;
358
+ button.className = `option-button ${opt.class}`;
359
  button.onclick = () => {
360
  addMessage('user', opt.text);
361
  conversation.push({ role: 'user', message: opt.text });