Spaces:
Running
Running
Update static/script.js
Browse files- static/script.js +16 -27
static/script.js
CHANGED
@@ -48,16 +48,16 @@ function handleResponse(userInput) {
|
|
48 |
{ text: 'Non-Vegetarian', class: 'red' },
|
49 |
{ text: 'Both', class: 'gray' }
|
50 |
]);
|
|
|
51 |
} else if (lowerInput === 'vegetarian' || lowerInput === 'non-vegetarian' || lowerInput === 'both') {
|
52 |
botResponse = `Nice choice! Let me whip up some ${lowerInput} options for you...`;
|
53 |
addMessage('bot', botResponse);
|
54 |
fetchMenuItems(lowerInput);
|
55 |
-
return;
|
56 |
} else {
|
57 |
fetch('/chat', {
|
58 |
method: 'POST',
|
59 |
headers: { 'Content-Type': 'application/json' },
|
60 |
-
body: JSON.stringify({ message: userInput })
|
61 |
})
|
62 |
.then(response => response.json())
|
63 |
.then(data => {
|
@@ -65,18 +65,15 @@ function handleResponse(userInput) {
|
|
65 |
addMessage('bot', `Oops! ${data.error}. Let’s try something else!`);
|
66 |
} else {
|
67 |
addMessage('bot', data.response);
|
68 |
-
if
|
69 |
-
|
70 |
-
}
|
71 |
}
|
72 |
})
|
73 |
.catch(error => {
|
74 |
-
addMessage('bot', `Yikes! Couldn’t reach the assistant: ${error.message}.
|
|
|
75 |
});
|
76 |
-
return;
|
77 |
}
|
78 |
-
|
79 |
-
addMessage('bot', botResponse);
|
80 |
}
|
81 |
|
82 |
function updateSelectionBox() {
|
@@ -182,12 +179,8 @@ function updateSelectionBox() {
|
|
182 |
|
183 |
function fetchMenuItems(dietaryPreference, searchTerm = '') {
|
184 |
const payload = {};
|
185 |
-
if (dietaryPreference)
|
186 |
-
|
187 |
-
}
|
188 |
-
if (searchTerm) {
|
189 |
-
payload.search_term = searchTerm;
|
190 |
-
}
|
191 |
fetch('/get_menu_items', {
|
192 |
method: 'POST',
|
193 |
headers: { 'Content-Type': 'application/json' },
|
@@ -196,12 +189,12 @@ function fetchMenuItems(dietaryPreference, searchTerm = '') {
|
|
196 |
.then(response => response.json())
|
197 |
.then(data => {
|
198 |
if (data.error) {
|
199 |
-
addMessage('bot', `Oops! Trouble fetching items: ${data.error}. Try again or
|
200 |
} else if (data.menu_items.length > 0) {
|
201 |
addMessage('bot', `Found ${data.menu_items.length} item${data.menu_items.length > 1 ? 's' : ''} for "${searchTerm || dietaryPreference}"!`);
|
202 |
displayItemsList(data.menu_items, 'menuItemsList', true);
|
203 |
} else {
|
204 |
-
addMessage('bot', `No items found for "${searchTerm || dietaryPreference}". Try
|
205 |
}
|
206 |
console.log(`Fetched items for ${searchTerm || dietaryPreference}:`, data.menu_items);
|
207 |
})
|
@@ -276,12 +269,11 @@ function fetchSectorItemDetails(itemName) {
|
|
276 |
addMessage('bot', `Sorry, I couldn’t find "${itemName}" in Sector_Detail__c. Try another item!`);
|
277 |
} else {
|
278 |
const details = data.item_details;
|
279 |
-
console.log(`Fetched details for ${itemName} from Sector_Detail__c:`, details);
|
280 |
if (selectedItems.some(item => item.name === details.name)) {
|
281 |
addMessage('bot', `"${details.name}" is already in your selection!`);
|
282 |
} else {
|
283 |
selectedItems.push({ ...details, quantity: 1 });
|
284 |
-
addMessage('bot', `Added "${details.name}" to your selection from Sector_Detail__c!
|
285 |
updateSelectionBox();
|
286 |
}
|
287 |
}
|
@@ -337,8 +329,7 @@ function showDescriptionPopup(item) {
|
|
337 |
});
|
338 |
} else {
|
339 |
const category = document.createElement('p');
|
340 |
-
|
341 |
-
category.textContent = `Category: ${categoryValue}`;
|
342 |
content.appendChild(category);
|
343 |
}
|
344 |
|
@@ -354,8 +345,8 @@ function showDescriptionPopup(item) {
|
|
354 |
image_url: item.image_url || '',
|
355 |
category: item.category || 'Not specified',
|
356 |
description: item.description || 'No description available',
|
357 |
-
|
358 |
-
|
359 |
};
|
360 |
if (item.source === 'Menu_Item__c') {
|
361 |
selectedItem.ingredients = item.ingredients;
|
@@ -453,8 +444,8 @@ function displayItemsList(items, containerId, isDetailed = false) {
|
|
453 |
image_url: item.image_url || '',
|
454 |
category: item.category || 'Not specified',
|
455 |
description: item.description || 'No description available',
|
456 |
-
|
457 |
-
|
458 |
};
|
459 |
if (item.source === 'Menu_Item__c') {
|
460 |
selectedItem.ingredients = item.ingredients;
|
@@ -545,8 +536,6 @@ function submitToSalesforce(customOrderName, quantity) {
|
|
545 |
quantity: parseInt(quantity) || 1
|
546 |
}));
|
547 |
|
548 |
-
console.log('Submitting to Salesforce with single Ingredient_Name__c:', itemsToSubmit);
|
549 |
-
|
550 |
fetch('/submit_items', {
|
551 |
method: 'POST',
|
552 |
headers: { 'Content-Type': 'application/json' },
|
|
|
48 |
{ text: 'Non-Vegetarian', class: 'red' },
|
49 |
{ text: 'Both', class: 'gray' }
|
50 |
]);
|
51 |
+
addMessage('bot', botResponse);
|
52 |
} else if (lowerInput === 'vegetarian' || lowerInput === 'non-vegetarian' || lowerInput === 'both') {
|
53 |
botResponse = `Nice choice! Let me whip up some ${lowerInput} options for you...`;
|
54 |
addMessage('bot', botResponse);
|
55 |
fetchMenuItems(lowerInput);
|
|
|
56 |
} else {
|
57 |
fetch('/chat', {
|
58 |
method: 'POST',
|
59 |
headers: { 'Content-Type': 'application/json' },
|
60 |
+
body: JSON.stringify({ message: userInput, session_id: 'default' })
|
61 |
})
|
62 |
.then(response => response.json())
|
63 |
.then(data => {
|
|
|
65 |
addMessage('bot', `Oops! ${data.error}. Let’s try something else!`);
|
66 |
} else {
|
67 |
addMessage('bot', data.response);
|
68 |
+
// Check if the input might be a menu item or ingredient
|
69 |
+
fetchMenuItems(null, userInput);
|
|
|
70 |
}
|
71 |
})
|
72 |
.catch(error => {
|
73 |
+
addMessage('bot', `Yikes! Couldn’t reach the assistant: ${error.message}. Try searching for 'chicken' or 'paneer'!`);
|
74 |
+
fetchMenuItems(null, userInput);
|
75 |
});
|
|
|
76 |
}
|
|
|
|
|
77 |
}
|
78 |
|
79 |
function updateSelectionBox() {
|
|
|
179 |
|
180 |
function fetchMenuItems(dietaryPreference, searchTerm = '') {
|
181 |
const payload = {};
|
182 |
+
if (dietaryPreference) payload.dietary_preference = dietaryPreference;
|
183 |
+
if (searchTerm) payload.search_term = searchTerm;
|
|
|
|
|
|
|
|
|
184 |
fetch('/get_menu_items', {
|
185 |
method: 'POST',
|
186 |
headers: { 'Content-Type': 'application/json' },
|
|
|
189 |
.then(response => response.json())
|
190 |
.then(data => {
|
191 |
if (data.error) {
|
192 |
+
addMessage('bot', `Oops! Trouble fetching items: ${data.error}. Try again or search something specific.`);
|
193 |
} else if (data.menu_items.length > 0) {
|
194 |
addMessage('bot', `Found ${data.menu_items.length} item${data.menu_items.length > 1 ? 's' : ''} for "${searchTerm || dietaryPreference}"!`);
|
195 |
displayItemsList(data.menu_items, 'menuItemsList', true);
|
196 |
} else {
|
197 |
+
addMessage('bot', `No items found for "${searchTerm || dietaryPreference}". Try something like "paneer" or "chicken"!`);
|
198 |
}
|
199 |
console.log(`Fetched items for ${searchTerm || dietaryPreference}:`, data.menu_items);
|
200 |
})
|
|
|
269 |
addMessage('bot', `Sorry, I couldn’t find "${itemName}" in Sector_Detail__c. Try another item!`);
|
270 |
} else {
|
271 |
const details = data.item_details;
|
|
|
272 |
if (selectedItems.some(item => item.name === details.name)) {
|
273 |
addMessage('bot', `"${details.name}" is already in your selection!`);
|
274 |
} else {
|
275 |
selectedItems.push({ ...details, quantity: 1 });
|
276 |
+
addMessage('bot', `Added "${details.name}" to your selection from Sector_Detail__c! Check the box below.`);
|
277 |
updateSelectionBox();
|
278 |
}
|
279 |
}
|
|
|
329 |
});
|
330 |
} else {
|
331 |
const category = document.createElement('p');
|
332 |
+
category.textContent = `Category: ${item.category || 'Not specified'}`;
|
|
|
333 |
content.appendChild(category);
|
334 |
}
|
335 |
|
|
|
345 |
image_url: item.image_url || '',
|
346 |
category: item.category || 'Not specified',
|
347 |
description: item.description || 'No description available',
|
348 |
+
source: item.source,
|
349 |
+
quantity: 1
|
350 |
};
|
351 |
if (item.source === 'Menu_Item__c') {
|
352 |
selectedItem.ingredients = item.ingredients;
|
|
|
444 |
image_url: item.image_url || '',
|
445 |
category: item.category || 'Not specified',
|
446 |
description: item.description || 'No description available',
|
447 |
+
source: item.source,
|
448 |
+
quantity: 1
|
449 |
};
|
450 |
if (item.source === 'Menu_Item__c') {
|
451 |
selectedItem.ingredients = item.ingredients;
|
|
|
536 |
quantity: parseInt(quantity) || 1
|
537 |
}));
|
538 |
|
|
|
|
|
539 |
fetch('/submit_items', {
|
540 |
method: 'POST',
|
541 |
headers: { 'Content-Type': 'application/json' },
|