Spaces:
Running
Running
Update static/script.js
Browse files- static/script.js +191 -81
static/script.js
CHANGED
@@ -29,7 +29,7 @@ function sendMessage() {
|
|
29 |
addMessage('user', message);
|
30 |
conversation.push({ role: 'user', message: message });
|
31 |
selectionBoxVisible = true;
|
32 |
-
|
33 |
} else {
|
34 |
addMessage('bot', 'Hey, don’t be shy! Type something or add some items to get started! 😄');
|
35 |
}
|
@@ -37,6 +37,48 @@ function sendMessage() {
|
|
37 |
updateSelectionBox();
|
38 |
}
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
function updateSelectionBox() {
|
41 |
const chatMessages = document.getElementById('chatMessages');
|
42 |
if (!chatMessages) return;
|
@@ -82,7 +124,7 @@ function updateSelectionBox() {
|
|
82 |
itemContainer.appendChild(img);
|
83 |
|
84 |
const itemSpan = document.createElement('span');
|
85 |
-
itemSpan.textContent = item.name
|
86 |
itemContainer.appendChild(itemSpan);
|
87 |
|
88 |
const removeButton = document.createElement('button');
|
@@ -100,76 +142,72 @@ function updateSelectionBox() {
|
|
100 |
|
101 |
const textInput = document.createElement('input');
|
102 |
textInput.type = 'text';
|
103 |
-
textInput.placeholder = 'Add
|
104 |
textInput.className = 'manual-input';
|
105 |
textInput.addEventListener('keypress', (e) => {
|
106 |
if (e.key === 'Enter' && textInput.value.trim()) {
|
107 |
const itemName = textInput.value.trim();
|
108 |
-
|
109 |
textInput.value = '';
|
110 |
}
|
111 |
});
|
112 |
selectionBox.appendChild(textInput);
|
113 |
|
114 |
if (selectedItems.length > 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
const submitButton = document.createElement('button');
|
116 |
submitButton.textContent = 'Submit to Salesforce';
|
117 |
submitButton.className = 'submit-button';
|
118 |
-
submitButton.onclick =
|
119 |
selectionBox.appendChild(submitButton);
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
}
|
121 |
|
122 |
chatMessages.appendChild(selectionBox);
|
123 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
124 |
-
console.log('Updated selection box with items:', selectedItems.map(item => item.name));
|
125 |
}
|
126 |
|
127 |
-
function
|
128 |
-
const
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
{ text: 'Vegetarian', class: 'green' },
|
135 |
-
{ text: 'Non-Vegetarian', class: 'red' },
|
136 |
-
{ text: 'Both', class: 'gray' }
|
137 |
-
]);
|
138 |
-
} else if (lowerInput === 'vegetarian' || lowerInput === 'non-vegetarian' || lowerInput === 'both') {
|
139 |
-
botResponse = `Nice choice! Let me whip up some ${lowerInput} options for you...`;
|
140 |
-
addMessage('bot', botResponse);
|
141 |
-
fetchMenuItems(lowerInput);
|
142 |
-
return;
|
143 |
-
} else {
|
144 |
-
botResponse = `Looking up details for "${userInput}"...`;
|
145 |
-
addMessage('bot', botResponse);
|
146 |
-
fetchSectorOrMenuItemDetails(userInput);
|
147 |
-
return;
|
148 |
}
|
149 |
-
|
150 |
-
addMessage('bot', botResponse);
|
151 |
-
}
|
152 |
-
|
153 |
-
function fetchMenuItems(dietaryPreference) {
|
154 |
fetch('/get_menu_items', {
|
155 |
method: 'POST',
|
156 |
headers: { 'Content-Type': 'application/json' },
|
157 |
-
body: JSON.stringify(
|
158 |
})
|
159 |
.then(response => response.json())
|
160 |
.then(data => {
|
161 |
if (data.error) {
|
162 |
-
addMessage('bot', `Oops! Trouble fetching
|
163 |
} else if (data.menu_items.length > 0) {
|
|
|
164 |
displayItemsList(data.menu_items, 'menuItemsList', true);
|
165 |
} else {
|
166 |
-
addMessage('bot', `No ${dietaryPreference}
|
167 |
}
|
168 |
-
console.log(`Fetched items for ${dietaryPreference}:`, data.menu_items);
|
169 |
})
|
170 |
.catch(error => {
|
171 |
addMessage('bot', `Yikes! Couldn’t reach Salesforce: ${error.message}. I’ll retry in a sec...`);
|
172 |
-
setTimeout(() => fetchMenuItems(dietaryPreference), 2000);
|
173 |
});
|
174 |
}
|
175 |
|
@@ -197,9 +235,8 @@ function suggestItems(searchTerm) {
|
|
197 |
});
|
198 |
}
|
199 |
|
200 |
-
function
|
201 |
-
|
202 |
-
fetch('/get_menu_item_details', {
|
203 |
method: 'POST',
|
204 |
headers: { 'Content-Type': 'application/json' },
|
205 |
body: JSON.stringify({ item_name: itemName })
|
@@ -207,17 +244,23 @@ function fetchSectorOrMenuItemDetails(itemName) {
|
|
207 |
.then(response => response.json())
|
208 |
.then(data => {
|
209 |
if (data.error) {
|
210 |
-
|
211 |
-
|
212 |
} else {
|
213 |
const details = data.item_details;
|
214 |
-
|
215 |
-
|
|
|
|
|
|
|
|
|
|
|
216 |
}
|
217 |
})
|
218 |
.catch(error => {
|
219 |
-
addMessage('bot', `Trouble fetching "${itemName}": ${error.message}.
|
220 |
-
|
|
|
221 |
});
|
222 |
}
|
223 |
|
@@ -230,11 +273,17 @@ function fetchSectorItemDetails(itemName) {
|
|
230 |
.then(response => response.json())
|
231 |
.then(data => {
|
232 |
if (data.error) {
|
233 |
-
addMessage('bot', `Sorry, I couldn’t find "${itemName}" in
|
234 |
} else {
|
235 |
const details = data.item_details;
|
236 |
-
|
237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
}
|
239 |
})
|
240 |
.catch(error => {
|
@@ -264,7 +313,7 @@ function showDescriptionPopup(item) {
|
|
264 |
content.appendChild(title);
|
265 |
|
266 |
const desc = document.createElement('p');
|
267 |
-
desc.textContent = item.description;
|
268 |
content.appendChild(desc);
|
269 |
|
270 |
if (item.source === 'Menu_Item__c') {
|
@@ -278,7 +327,6 @@ function showDescriptionPopup(item) {
|
|
278 |
{ label: 'Spice Levels', value: item.spice_levels },
|
279 |
{ label: 'Dynamic Dish', value: item.dynamic_dish ? 'Yes' : 'No' }
|
280 |
];
|
281 |
-
|
282 |
fields.forEach(field => {
|
283 |
if (field.value) {
|
284 |
const p = document.createElement('p');
|
@@ -287,6 +335,11 @@ function showDescriptionPopup(item) {
|
|
287 |
content.appendChild(p);
|
288 |
}
|
289 |
});
|
|
|
|
|
|
|
|
|
|
|
290 |
}
|
291 |
|
292 |
const buttonContainer = document.createElement('div');
|
@@ -299,8 +352,9 @@ function showDescriptionPopup(item) {
|
|
299 |
const selectedItem = {
|
300 |
name: item.name,
|
301 |
image_url: item.image_url || '',
|
302 |
-
category: item.category || '
|
303 |
description: item.description || 'No description available',
|
|
|
304 |
source: item.source
|
305 |
};
|
306 |
if (item.source === 'Menu_Item__c') {
|
@@ -354,37 +408,79 @@ function displayItemsList(items, containerId, isDetailed = false) {
|
|
354 |
img.className = 'ingredient-image';
|
355 |
itemDiv.appendChild(img);
|
356 |
|
|
|
|
|
|
|
357 |
const nameDiv = document.createElement('div');
|
358 |
nameDiv.textContent = item.name;
|
359 |
nameDiv.className = 'ingredient-name';
|
360 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
|
362 |
-
if (isDetailed) {
|
363 |
const showDescButton = document.createElement('button');
|
364 |
showDescButton.textContent = 'Show Details';
|
365 |
showDescButton.className = 'show-desc-button';
|
366 |
showDescButton.onclick = () => showDescriptionPopup(item);
|
367 |
itemDiv.appendChild(showDescButton);
|
368 |
-
} else {
|
369 |
-
const addButton = document.createElement('button');
|
370 |
-
addButton.textContent = 'Add';
|
371 |
-
addButton.onclick = () => {
|
372 |
-
const selectedItem = {
|
373 |
-
name: item.name,
|
374 |
-
image_url: item.image_url || '',
|
375 |
-
category: item.category || 'Unknown',
|
376 |
-
description: item.description || 'No description available',
|
377 |
-
source: item.source || 'Unknown'
|
378 |
-
};
|
379 |
-
if (selectedItems.some(existing => existing.name === selectedItem.name)) {
|
380 |
-
addMessage('bot', `"${selectedItem.name}" is already in your selection!`);
|
381 |
-
} else {
|
382 |
-
selectedItems.push(selectedItem);
|
383 |
-
addMessage('bot', `Added "${selectedItem.name}" to your selection!`);
|
384 |
-
updateSelectionBox();
|
385 |
-
}
|
386 |
-
};
|
387 |
-
itemDiv.appendChild(addButton);
|
388 |
}
|
389 |
|
390 |
container.appendChild(itemDiv);
|
@@ -425,7 +521,17 @@ function displayOptions(options) {
|
|
425 |
chatMessages.appendChild(optionsDiv);
|
426 |
}
|
427 |
|
428 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
429 |
if (selectedItems.length === 0) {
|
430 |
addMessage('bot', 'No items to submit yet! Add some tasty picks first! 😊');
|
431 |
return;
|
@@ -433,28 +539,32 @@ function submitToSalesforce() {
|
|
433 |
|
434 |
const itemsToSubmit = selectedItems.map(item => ({
|
435 |
name: item.name,
|
436 |
-
category: item.category || '
|
437 |
-
description: item.description || 'No description available'
|
|
|
|
|
438 |
}));
|
439 |
|
|
|
|
|
440 |
fetch('/submit_items', {
|
441 |
method: 'POST',
|
442 |
headers: { 'Content-Type': 'application/json' },
|
443 |
-
body: JSON.stringify({ items: itemsToSubmit })
|
444 |
})
|
445 |
.then(response => response.json())
|
446 |
.then(data => {
|
447 |
if (data.error) {
|
448 |
addMessage('bot', `Uh-oh! Failed to submit items: ${data.error}. Want to try again?`);
|
449 |
} else {
|
450 |
-
addMessage('bot', `${data.success}! Your culinary choices are now saved. What’s next on the menu?`);
|
451 |
selectedItems = [];
|
452 |
updateSelectionBox();
|
453 |
}
|
454 |
})
|
455 |
.catch(error => {
|
456 |
addMessage('bot', `Error submitting items: ${error.message}. I’ll retry shortly...`);
|
457 |
-
setTimeout(submitToSalesforce, 2000);
|
458 |
});
|
459 |
}
|
460 |
|
@@ -463,7 +573,7 @@ function resetConversation() {
|
|
463 |
conversation = [
|
464 |
{ role: 'bot', message: `Hello! I’m Chef Bot, your culinary assistant! What’s your name?` },
|
465 |
{ role: 'user', message: userName },
|
466 |
-
{ role: 'bot', message: `Great to meet you, ${userName}! 🍳 What kind of food are you craving today
|
467 |
];
|
468 |
selectedItems = [];
|
469 |
selectionBoxVisible = true;
|
|
|
29 |
addMessage('user', message);
|
30 |
conversation.push({ role: 'user', message: message });
|
31 |
selectionBoxVisible = true;
|
32 |
+
handleResponse(message);
|
33 |
} else {
|
34 |
addMessage('bot', 'Hey, don’t be shy! Type something or add some items to get started! 😄');
|
35 |
}
|
|
|
37 |
updateSelectionBox();
|
38 |
}
|
39 |
|
40 |
+
function handleResponse(userInput) {
|
41 |
+
const lowerInput = userInput.toLowerCase();
|
42 |
+
let botResponse = '';
|
43 |
+
|
44 |
+
if (conversation.length === 2) {
|
45 |
+
botResponse = `Great to meet you, ${userInput}! 🍳 What kind of food are you craving today? Or ask me to help customize a dish!`;
|
46 |
+
displayOptions([
|
47 |
+
{ text: 'Vegetarian', class: 'green' },
|
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 => {
|
64 |
+
if (data.error) {
|
65 |
+
addMessage('bot', `Oops! ${data.error}. Let’s try something else!`);
|
66 |
+
} else {
|
67 |
+
addMessage('bot', data.response);
|
68 |
+
if (data.search_term) {
|
69 |
+
fetchMenuItems(null, data.search_term);
|
70 |
+
}
|
71 |
+
}
|
72 |
+
})
|
73 |
+
.catch(error => {
|
74 |
+
addMessage('bot', `Yikes! Couldn’t reach the assistant: ${error.message}. I’ll suggest rice or chicken instead!`);
|
75 |
+
});
|
76 |
+
return;
|
77 |
+
}
|
78 |
+
|
79 |
+
addMessage('bot', botResponse);
|
80 |
+
}
|
81 |
+
|
82 |
function updateSelectionBox() {
|
83 |
const chatMessages = document.getElementById('chatMessages');
|
84 |
if (!chatMessages) return;
|
|
|
124 |
itemContainer.appendChild(img);
|
125 |
|
126 |
const itemSpan = document.createElement('span');
|
127 |
+
itemSpan.textContent = `${item.name} (Qty: ${item.quantity || 1})`;
|
128 |
itemContainer.appendChild(itemSpan);
|
129 |
|
130 |
const removeButton = document.createElement('button');
|
|
|
142 |
|
143 |
const textInput = document.createElement('input');
|
144 |
textInput.type = 'text';
|
145 |
+
textInput.placeholder = 'Add Sector_Detail__c item...';
|
146 |
textInput.className = 'manual-input';
|
147 |
textInput.addEventListener('keypress', (e) => {
|
148 |
if (e.key === 'Enter' && textInput.value.trim()) {
|
149 |
const itemName = textInput.value.trim();
|
150 |
+
fetchSectorItemDetails(itemName);
|
151 |
textInput.value = '';
|
152 |
}
|
153 |
});
|
154 |
selectionBox.appendChild(textInput);
|
155 |
|
156 |
if (selectedItems.length > 0) {
|
157 |
+
const quantityInput = document.createElement('input');
|
158 |
+
quantityInput.type = 'number';
|
159 |
+
quantityInput.min = '1';
|
160 |
+
quantityInput.value = '1';
|
161 |
+
quantityInput.placeholder = 'Quantity';
|
162 |
+
quantityInput.className = 'quantity-input';
|
163 |
+
selectionBox.appendChild(quantityInput);
|
164 |
+
|
165 |
const submitButton = document.createElement('button');
|
166 |
submitButton.textContent = 'Submit to Salesforce';
|
167 |
submitButton.className = 'submit-button';
|
168 |
+
submitButton.onclick = () => promptAndSubmit(quantityInput.value);
|
169 |
selectionBox.appendChild(submitButton);
|
170 |
+
|
171 |
+
const orderNameInput = document.createElement('input');
|
172 |
+
orderNameInput.type = 'text';
|
173 |
+
orderNameInput.placeholder = 'Custom Order Name (optional)';
|
174 |
+
orderNameInput.className = 'order-name-input';
|
175 |
+
selectionBox.appendChild(orderNameInput);
|
176 |
}
|
177 |
|
178 |
chatMessages.appendChild(selectionBox);
|
179 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
180 |
+
console.log('Updated selection box with items:', selectedItems.map(item => ({ name: item.name, category: item.category })));
|
181 |
}
|
182 |
|
183 |
+
function fetchMenuItems(dietaryPreference, searchTerm = '') {
|
184 |
+
const payload = {};
|
185 |
+
if (dietaryPreference) {
|
186 |
+
payload.dietary_preference = dietaryPreference;
|
187 |
+
}
|
188 |
+
if (searchTerm) {
|
189 |
+
payload.search_term = searchTerm;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
}
|
|
|
|
|
|
|
|
|
|
|
191 |
fetch('/get_menu_items', {
|
192 |
method: 'POST',
|
193 |
headers: { 'Content-Type': 'application/json' },
|
194 |
+
body: JSON.stringify(payload)
|
195 |
})
|
196 |
.then(response => response.json())
|
197 |
.then(data => {
|
198 |
if (data.error) {
|
199 |
+
addMessage('bot', `Oops! Trouble fetching items: ${data.error}. Try again or contact your admin if it persists.`);
|
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 searching for something like "paneer" or "chicken"!`);
|
205 |
}
|
206 |
+
console.log(`Fetched items for ${searchTerm || dietaryPreference}:`, data.menu_items);
|
207 |
})
|
208 |
.catch(error => {
|
209 |
addMessage('bot', `Yikes! Couldn’t reach Salesforce: ${error.message}. I’ll retry in a sec...`);
|
210 |
+
setTimeout(() => fetchMenuItems(dietaryPreference, searchTerm), 2000);
|
211 |
});
|
212 |
}
|
213 |
|
|
|
235 |
});
|
236 |
}
|
237 |
|
238 |
+
function fetchItemDetails(itemName) {
|
239 |
+
fetch('/get_item_details', {
|
|
|
240 |
method: 'POST',
|
241 |
headers: { 'Content-Type': 'application/json' },
|
242 |
body: JSON.stringify({ item_name: itemName })
|
|
|
244 |
.then(response => response.json())
|
245 |
.then(data => {
|
246 |
if (data.error) {
|
247 |
+
addMessage('bot', `Couldn’t find "${itemName}" in Ingredient_Object__c. Add it manually in the box below!`);
|
248 |
+
updateSelectionBox();
|
249 |
} else {
|
250 |
const details = data.item_details;
|
251 |
+
if (selectedItems.some(item => item.name === details.name)) {
|
252 |
+
addMessage('bot', `"${details.name}" is already in your selection!`);
|
253 |
+
} else {
|
254 |
+
selectedItems.push({ ...details, quantity: 1 });
|
255 |
+
addMessage('bot', `Added "${itemName}" to your selection! Check the box below.`);
|
256 |
+
updateSelectionBox();
|
257 |
+
}
|
258 |
}
|
259 |
})
|
260 |
.catch(error => {
|
261 |
+
addMessage('bot', `Trouble fetching "${itemName}": ${error.message}. Add it manually or I’ll retry...`);
|
262 |
+
updateSelectionBox();
|
263 |
+
setTimeout(() => fetchItemDetails(itemName), 2000);
|
264 |
});
|
265 |
}
|
266 |
|
|
|
273 |
.then(response => response.json())
|
274 |
.then(data => {
|
275 |
if (data.error) {
|
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! Category: ${details.category || 'Not specified'}. Check the box below.`);
|
285 |
+
updateSelectionBox();
|
286 |
+
}
|
287 |
}
|
288 |
})
|
289 |
.catch(error => {
|
|
|
313 |
content.appendChild(title);
|
314 |
|
315 |
const desc = document.createElement('p');
|
316 |
+
desc.textContent = item.description || 'No description available';
|
317 |
content.appendChild(desc);
|
318 |
|
319 |
if (item.source === 'Menu_Item__c') {
|
|
|
327 |
{ label: 'Spice Levels', value: item.spice_levels },
|
328 |
{ label: 'Dynamic Dish', value: item.dynamic_dish ? 'Yes' : 'No' }
|
329 |
];
|
|
|
330 |
fields.forEach(field => {
|
331 |
if (field.value) {
|
332 |
const p = document.createElement('p');
|
|
|
335 |
content.appendChild(p);
|
336 |
}
|
337 |
});
|
338 |
+
} else {
|
339 |
+
const category = document.createElement('p');
|
340 |
+
const categoryValue = item.category || 'Not specified';
|
341 |
+
category.textContent = `Category: ${categoryValue}`;
|
342 |
+
content.appendChild(category);
|
343 |
}
|
344 |
|
345 |
const buttonContainer = document.createElement('div');
|
|
|
352 |
const selectedItem = {
|
353 |
name: item.name,
|
354 |
image_url: item.image_url || '',
|
355 |
+
category: item.category || 'Not specified',
|
356 |
description: item.description || 'No description available',
|
357 |
+
quantity: 1,
|
358 |
source: item.source
|
359 |
};
|
360 |
if (item.source === 'Menu_Item__c') {
|
|
|
408 |
img.className = 'ingredient-image';
|
409 |
itemDiv.appendChild(img);
|
410 |
|
411 |
+
const contentDiv = document.createElement('div');
|
412 |
+
contentDiv.className = 'ingredient-content';
|
413 |
+
|
414 |
const nameDiv = document.createElement('div');
|
415 |
nameDiv.textContent = item.name;
|
416 |
nameDiv.className = 'ingredient-name';
|
417 |
+
contentDiv.appendChild(nameDiv);
|
418 |
+
|
419 |
+
if (item.source === 'Menu_Item__c' && isDetailed) {
|
420 |
+
const fields = [
|
421 |
+
{ label: 'Price', value: item.price ? `$${item.price.toFixed(2)}` : 'N/A' },
|
422 |
+
{ label: 'Veg/Non-Veg', value: item.veg_nonveg },
|
423 |
+
{ label: 'Spice Level', value: item.spice_levels },
|
424 |
+
{ label: 'Category', value: item.category },
|
425 |
+
{ label: 'Ingredients', value: item.ingredients },
|
426 |
+
{ label: 'Nutritional Info', value: item.nutritional_info },
|
427 |
+
{ label: 'Sector', value: item.sector },
|
428 |
+
{ label: 'Dynamic Dish', value: item.dynamic_dish ? 'Yes' : 'No' }
|
429 |
+
];
|
430 |
+
fields.forEach(field => {
|
431 |
+
if (field.value) {
|
432 |
+
const p = document.createElement('p');
|
433 |
+
p.className = 'menu-item-field';
|
434 |
+
p.innerHTML = `<strong>${field.label}:</strong> ${field.value}`;
|
435 |
+
contentDiv.appendChild(p);
|
436 |
+
}
|
437 |
+
});
|
438 |
+
} else if (item.source === 'Sector_Detail__c' && isDetailed) {
|
439 |
+
const desc = document.createElement('p');
|
440 |
+
desc.className = 'menu-item-field';
|
441 |
+
desc.innerHTML = `<strong>Description:</strong> ${item.description}`;
|
442 |
+
contentDiv.appendChild(desc);
|
443 |
+
}
|
444 |
+
|
445 |
+
itemDiv.appendChild(contentDiv);
|
446 |
+
|
447 |
+
const addButton = document.createElement('button');
|
448 |
+
addButton.textContent = 'Add';
|
449 |
+
addButton.className = 'show-desc-button';
|
450 |
+
addButton.onclick = () => {
|
451 |
+
const selectedItem = {
|
452 |
+
name: item.name,
|
453 |
+
image_url: item.image_url || '',
|
454 |
+
category: item.category || 'Not specified',
|
455 |
+
description: item.description || 'No description available',
|
456 |
+
quantity: 1,
|
457 |
+
source: item.source
|
458 |
+
};
|
459 |
+
if (item.source === 'Menu_Item__c') {
|
460 |
+
selectedItem.ingredients = item.ingredients;
|
461 |
+
selectedItem.nutritional_info = item.nutritional_info;
|
462 |
+
selectedItem.price = item.price;
|
463 |
+
selectedItem.sector = item.sector;
|
464 |
+
selectedItem.spice_levels = item.spice_levels;
|
465 |
+
selectedItem.veg_nonveg = item.veg_nonveg;
|
466 |
+
selectedItem.dynamic_dish = item.dynamic_dish;
|
467 |
+
}
|
468 |
+
if (selectedItems.some(existing => existing.name === selectedItem.name)) {
|
469 |
+
addMessage('bot', `"${selectedItem.name}" is already in your selection!`);
|
470 |
+
} else {
|
471 |
+
selectedItems.push(selectedItem);
|
472 |
+
addMessage('bot', `Added "${selectedItem.name}" to your selection! Check the box below.`);
|
473 |
+
updateSelectionBox();
|
474 |
+
}
|
475 |
+
};
|
476 |
+
itemDiv.appendChild(addButton);
|
477 |
|
478 |
+
if (item.source === 'Sector_Detail__c' && isDetailed) {
|
479 |
const showDescButton = document.createElement('button');
|
480 |
showDescButton.textContent = 'Show Details';
|
481 |
showDescButton.className = 'show-desc-button';
|
482 |
showDescButton.onclick = () => showDescriptionPopup(item);
|
483 |
itemDiv.appendChild(showDescButton);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
484 |
}
|
485 |
|
486 |
container.appendChild(itemDiv);
|
|
|
521 |
chatMessages.appendChild(optionsDiv);
|
522 |
}
|
523 |
|
524 |
+
function promptAndSubmit(quantity) {
|
525 |
+
const orderNameInput = document.querySelector('.order-name-input');
|
526 |
+
const customOrderName = orderNameInput ? orderNameInput.value.trim() : '';
|
527 |
+
if (confirm(`Submit ${selectedItems.length} items with quantity ${quantity}?`)) {
|
528 |
+
submitToSalesforce(customOrderName, quantity);
|
529 |
+
} else {
|
530 |
+
addMessage('bot', 'Submission cancelled. Add more items or try again!');
|
531 |
+
}
|
532 |
+
}
|
533 |
+
|
534 |
+
function submitToSalesforce(customOrderName, quantity) {
|
535 |
if (selectedItems.length === 0) {
|
536 |
addMessage('bot', 'No items to submit yet! Add some tasty picks first! 😊');
|
537 |
return;
|
|
|
539 |
|
540 |
const itemsToSubmit = selectedItems.map(item => ({
|
541 |
name: item.name,
|
542 |
+
category: item.category || 'Not specified',
|
543 |
+
description: item.description || 'No description available',
|
544 |
+
image_url: item.image_url || '',
|
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' },
|
553 |
+
body: JSON.stringify({ items: itemsToSubmit, custom_order_name: customOrderName })
|
554 |
})
|
555 |
.then(response => response.json())
|
556 |
.then(data => {
|
557 |
if (data.error) {
|
558 |
addMessage('bot', `Uh-oh! Failed to submit items: ${data.error}. Want to try again?`);
|
559 |
} else {
|
560 |
+
addMessage('bot', `${data.success}! Your culinary choices are now saved under Ingredient_Name__c: ${data.ingredient_name}. What’s next on the menu?`);
|
561 |
selectedItems = [];
|
562 |
updateSelectionBox();
|
563 |
}
|
564 |
})
|
565 |
.catch(error => {
|
566 |
addMessage('bot', `Error submitting items: ${error.message}. I’ll retry shortly...`);
|
567 |
+
setTimeout(() => submitToSalesforce(customOrderName, quantity), 2000);
|
568 |
});
|
569 |
}
|
570 |
|
|
|
573 |
conversation = [
|
574 |
{ role: 'bot', message: `Hello! I’m Chef Bot, your culinary assistant! What’s your name?` },
|
575 |
{ role: 'user', message: userName },
|
576 |
+
{ role: 'bot', message: `Great to meet you, ${userName}! 🍳 What kind of food are you craving today? Or ask me to help customize a dish!` }
|
577 |
];
|
578 |
selectedItems = [];
|
579 |
selectionBoxVisible = true;
|