Spaces:
Running
Running
Update static/script.js
Browse files- static/script.js +13 -17
static/script.js
CHANGED
@@ -61,26 +61,22 @@ function handleResponse(userInput) {
|
|
61 |
}
|
62 |
|
63 |
function fetchMenuItems(dietaryPreference) {
|
64 |
-
fetch('/get_menu_items', {
|
|
|
|
|
|
|
|
|
65 |
.then(response => response.json())
|
66 |
.then(data => {
|
67 |
if (data.error) {
|
68 |
-
addMessage('bot', `Oops! Couldn’t fetch
|
|
|
|
|
|
|
69 |
} else {
|
70 |
-
|
71 |
-
if (dietaryPreference === 'both') return true;
|
72 |
-
return dietaryPreference === 'vegetarian'
|
73 |
-
? item.category === 'Veg'
|
74 |
-
: item.category === 'Non-Veg';
|
75 |
-
});
|
76 |
-
if (filteredItems.length > 0) {
|
77 |
-
addMessage('bot', `Here are some ${dietaryPreference} menu items:`);
|
78 |
-
displayItemsList(filteredItems, 'menuItemsList');
|
79 |
-
} else {
|
80 |
-
addMessage('bot', `No ${dietaryPreference} items found. Try searching for something specific!`);
|
81 |
-
}
|
82 |
-
console.log(`Fetched menu items for ${dietaryPreference}:`, filteredItems);
|
83 |
}
|
|
|
84 |
})
|
85 |
.catch(error => {
|
86 |
addMessage('bot', `Error connecting to Salesforce: ${error.message}. Retrying...`);
|
@@ -102,7 +98,7 @@ function suggestItems(searchTerm) {
|
|
102 |
addMessage('bot', `Found these suggestions for "${searchTerm}":`);
|
103 |
displayItemsList(data.suggestions, 'suggestionsList');
|
104 |
} else {
|
105 |
-
addMessage('bot', `No matches for "${searchTerm}". Try "chicken" or "
|
106 |
}
|
107 |
console.log(`Suggestions for ${searchTerm}:`, data.suggestions);
|
108 |
})
|
@@ -121,7 +117,7 @@ function fetchItemDetails(itemName) {
|
|
121 |
.then(response => response.json())
|
122 |
.then(data => {
|
123 |
if (data.error) {
|
124 |
-
addMessage('bot', `Sorry, couldn’t get details for "${itemName}": ${data.error}. Check the name
|
125 |
} else {
|
126 |
const details = data.item_details;
|
127 |
selectedItems.push(details);
|
|
|
61 |
}
|
62 |
|
63 |
function fetchMenuItems(dietaryPreference) {
|
64 |
+
fetch('/get_menu_items', {
|
65 |
+
method: 'POST',
|
66 |
+
headers: { 'Content-Type': 'application/json' },
|
67 |
+
body: JSON.stringify({ dietary_preference: dietaryPreference })
|
68 |
+
})
|
69 |
.then(response => response.json())
|
70 |
.then(data => {
|
71 |
if (data.error) {
|
72 |
+
addMessage('bot', `Oops! Couldn’t fetch ${dietaryPreference} items: ${data.error}. Try again?`);
|
73 |
+
} else if (data.menu_items.length > 0) {
|
74 |
+
addMessage('bot', `Here are some ${dietaryPreference} menu items:`);
|
75 |
+
displayItemsList(data.menu_items, 'menuItemsList');
|
76 |
} else {
|
77 |
+
addMessage('bot', `No ${dietaryPreference} items found. Try searching for something specific!`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
}
|
79 |
+
console.log(`Fetched menu items for ${dietaryPreference}:`, data.menu_items);
|
80 |
})
|
81 |
.catch(error => {
|
82 |
addMessage('bot', `Error connecting to Salesforce: ${error.message}. Retrying...`);
|
|
|
98 |
addMessage('bot', `Found these suggestions for "${searchTerm}":`);
|
99 |
displayItemsList(data.suggestions, 'suggestionsList');
|
100 |
} else {
|
101 |
+
addMessage('bot', `No matches for "${searchTerm}". Try "chicken" or "paneer"?`);
|
102 |
}
|
103 |
console.log(`Suggestions for ${searchTerm}:`, data.suggestions);
|
104 |
})
|
|
|
117 |
.then(response => response.json())
|
118 |
.then(data => {
|
119 |
if (data.error) {
|
120 |
+
addMessage('bot', `Sorry, couldn’t get details for "${itemName}": ${data.error}. Check the name or try another item!`);
|
121 |
} else {
|
122 |
const details = data.item_details;
|
123 |
selectedItems.push(details);
|