Spaces:
Sleeping
Sleeping
Update templates/chef-bot.html
Browse files- templates/chef-bot.html +264 -226
templates/chef-bot.html
CHANGED
|
@@ -225,7 +225,7 @@
|
|
| 225 |
.option-button.gray { background-color: #616161; }
|
| 226 |
.option-button:active { opacity: 0.9; }
|
| 227 |
|
| 228 |
-
.selection-box
|
| 229 |
background-color: #e1f5fe;
|
| 230 |
padding: 8px;
|
| 231 |
border: 1px solid #0288d1;
|
|
@@ -238,7 +238,7 @@
|
|
| 238 |
gap: 5px;
|
| 239 |
}
|
| 240 |
|
| 241 |
-
.selection-box span
|
| 242 |
background-color: #bbdefb;
|
| 243 |
padding: 3px 8px;
|
| 244 |
border-radius: 5px;
|
|
@@ -262,7 +262,7 @@
|
|
| 262 |
margin-right: 5px;
|
| 263 |
}
|
| 264 |
|
| 265 |
-
.submit-button
|
| 266 |
padding: 6px 10px;
|
| 267 |
background-color: #0288d1;
|
| 268 |
color: white;
|
|
@@ -273,7 +273,7 @@
|
|
| 273 |
min-width: 60px;
|
| 274 |
}
|
| 275 |
|
| 276 |
-
.submit-button:active
|
| 277 |
background-color: #0277bd;
|
| 278 |
}
|
| 279 |
|
|
@@ -292,7 +292,7 @@
|
|
| 292 |
background-color: #b71c1c;
|
| 293 |
}
|
| 294 |
|
| 295 |
-
.manual-input, .
|
| 296 |
padding: 4px;
|
| 297 |
border: 1px solid #0288d1;
|
| 298 |
border-radius: 5px;
|
|
@@ -316,51 +316,101 @@
|
|
| 316 |
width: 100px;
|
| 317 |
}
|
| 318 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
@media (max-width: 480px) {
|
| 320 |
-
.chat-header {
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
.chat-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
.
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
.
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
.
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
.
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
.
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
.
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
.
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
}
|
| 365 |
</style>
|
| 366 |
</head>
|
|
@@ -368,20 +418,19 @@
|
|
| 368 |
<div class="chat-container">
|
| 369 |
<div class="chat-header">🍳 Chef Bot</div>
|
| 370 |
<div class="chat-messages" id="chatMessages">
|
| 371 |
-
<div class="bot-message">Hello! I’m Chef Bot
|
| 372 |
</div>
|
| 373 |
<div class="chat-input">
|
| 374 |
-
<input type="text" id="userInput" placeholder="Type
|
| 375 |
<button onclick="sendMessage()">Send</button>
|
| 376 |
</div>
|
| 377 |
</div>
|
| 378 |
|
| 379 |
<script>
|
| 380 |
let conversation = [
|
| 381 |
-
{ role: 'bot', message: 'Hello! I’m Chef Bot
|
| 382 |
];
|
| 383 |
let selectedItems = [];
|
| 384 |
-
let submittedItems = [];
|
| 385 |
let selectionBoxVisible = false;
|
| 386 |
|
| 387 |
function addMessage(role, message) {
|
|
@@ -415,27 +464,18 @@
|
|
| 415 |
}
|
| 416 |
userInput.value = '';
|
| 417 |
updateSelectionBox();
|
| 418 |
-
updateSubmissionBox();
|
| 419 |
}
|
| 420 |
|
| 421 |
function handleResponse(userInput) {
|
| 422 |
const lowerInput = userInput.toLowerCase();
|
| 423 |
let botResponse = '';
|
| 424 |
|
| 425 |
-
if (
|
| 426 |
-
botResponse = `
|
| 427 |
-
displayOptions([
|
| 428 |
-
{ text: 'Vegetarian', class: 'green' },
|
| 429 |
-
{ text: 'Non-Vegetarian', class: 'red' },
|
| 430 |
-
{ text: 'Both', class: 'gray' }
|
| 431 |
-
]);
|
| 432 |
-
addMessage('bot', botResponse);
|
| 433 |
-
} else if (lowerInput === 'vegetarian' || lowerInput === 'non-vegetarian' || lowerInput === 'both') {
|
| 434 |
-
botResponse = `Fetching ${lowerInput} items from Sector_Detail__c...`;
|
| 435 |
addMessage('bot', botResponse);
|
| 436 |
fetchMenuItems(lowerInput);
|
| 437 |
} else {
|
| 438 |
-
botResponse = `Looking for "${userInput}"
|
| 439 |
addMessage('bot', botResponse);
|
| 440 |
fetchMenuItems(null, userInput);
|
| 441 |
}
|
|
@@ -448,32 +488,63 @@
|
|
| 448 |
const existingBox = document.querySelector('.selection-box');
|
| 449 |
if (existingBox) existingBox.remove();
|
| 450 |
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 471 |
|
| 472 |
-
|
|
|
|
|
|
|
|
|
|
| 473 |
if (selectedItems.length > 0) {
|
|
|
|
|
|
|
|
|
|
| 474 |
const label = document.createElement('span');
|
| 475 |
-
label.textContent = 'Selected:';
|
| 476 |
-
|
| 477 |
|
| 478 |
selectedItems.forEach((item, index) => {
|
| 479 |
const itemContainer = document.createElement('div');
|
|
@@ -495,18 +566,18 @@
|
|
| 495 |
itemSpan.textContent = `${itemName} (Qty: ${item.quantity || 1})`;
|
| 496 |
contentDiv.appendChild(itemSpan);
|
| 497 |
|
| 498 |
-
const
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
if (e.key === 'Enter' &&
|
| 504 |
-
const ingredientName =
|
| 505 |
fetchSectorItemDetails(ingredientName, index);
|
| 506 |
-
|
| 507 |
}
|
| 508 |
});
|
| 509 |
-
contentDiv.appendChild(
|
| 510 |
|
| 511 |
itemContainer.appendChild(contentDiv);
|
| 512 |
|
|
@@ -520,20 +591,69 @@
|
|
| 520 |
};
|
| 521 |
itemContainer.appendChild(removeButton);
|
| 522 |
|
| 523 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 524 |
});
|
| 525 |
|
| 526 |
-
|
| 527 |
-
bothButton.textContent = 'Both';
|
| 528 |
-
bothButton.className = 'both-button';
|
| 529 |
-
bothButton.onclick = () => fetchBothItems();
|
| 530 |
-
selectionBox.appendChild(bothButton);
|
| 531 |
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 537 |
|
| 538 |
const quantityInput = document.createElement('input');
|
| 539 |
quantityInput.type = 'number';
|
|
@@ -541,75 +661,32 @@
|
|
| 541 |
quantityInput.value = '1';
|
| 542 |
quantityInput.placeholder = 'Qty';
|
| 543 |
quantityInput.className = 'quantity-input';
|
| 544 |
-
|
| 545 |
|
| 546 |
const orderNameInput = document.createElement('input');
|
| 547 |
orderNameInput.type = 'text';
|
| 548 |
orderNameInput.placeholder = 'Order Name';
|
| 549 |
orderNameInput.className = 'order-name-input';
|
| 550 |
-
|
| 551 |
-
}
|
| 552 |
-
|
| 553 |
-
chatMessages.appendChild(selectionBox);
|
| 554 |
-
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 555 |
-
console.log('Updated selection box:', selectedItems.map(item => ({ name: item.name, additionalIngredients: item.additionalIngredients })));
|
| 556 |
-
}
|
| 557 |
-
|
| 558 |
-
function updateSubmissionBox() {
|
| 559 |
-
const chatMessages = document.getElementById('chatMessages');
|
| 560 |
-
if (!chatMessages) return;
|
| 561 |
-
|
| 562 |
-
const existingBox = document.querySelector('.submission-box');
|
| 563 |
-
if (existingBox) existingBox.remove();
|
| 564 |
-
|
| 565 |
-
if (submittedItems.length === 0) return;
|
| 566 |
-
|
| 567 |
-
const submissionBox = document.createElement('div');
|
| 568 |
-
submissionBox.className = 'submission-box';
|
| 569 |
-
|
| 570 |
-
const label = document.createElement('span');
|
| 571 |
-
label.textContent = 'Submitted Items:';
|
| 572 |
-
submissionBox.appendChild(label);
|
| 573 |
-
|
| 574 |
-
submittedItems.forEach(item => {
|
| 575 |
-
const itemContainer = document.createElement('div');
|
| 576 |
-
itemContainer.className = 'selected-item';
|
| 577 |
-
|
| 578 |
-
const img = document.createElement('img');
|
| 579 |
-
img.src = item.image_url || 'https://via.placeholder.com/30';
|
| 580 |
-
img.alt = item.name;
|
| 581 |
-
img.className = 'selected-item-image';
|
| 582 |
-
itemContainer.appendChild(img);
|
| 583 |
|
| 584 |
-
const
|
| 585 |
-
|
|
|
|
|
|
|
|
|
|
| 586 |
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
: item.name;
|
| 590 |
-
const itemSpan = document.createElement('span');
|
| 591 |
-
itemSpan.textContent = `${itemName} (Qty: ${item.quantity || 1})`;
|
| 592 |
-
contentDiv.appendChild(itemSpan);
|
| 593 |
-
|
| 594 |
-
const descElement = document.createElement('p');
|
| 595 |
-
descElement.className = 'item-description';
|
| 596 |
-
descElement.textContent = item.description || 'No description available';
|
| 597 |
-
contentDiv.appendChild(descElement);
|
| 598 |
-
|
| 599 |
-
itemContainer.appendChild(contentDiv);
|
| 600 |
-
submissionBox.appendChild(itemContainer);
|
| 601 |
-
});
|
| 602 |
|
| 603 |
-
chatMessages.appendChild(submissionBox);
|
| 604 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 605 |
-
console.log('Updated
|
| 606 |
}
|
| 607 |
|
| 608 |
function fetchMenuItems(dietaryPreference = '', searchTerm = '') {
|
| 609 |
const payload = {};
|
| 610 |
if (dietaryPreference) payload.dietary_preference = dietaryPreference;
|
| 611 |
if (searchTerm) payload.search_term = searchTerm;
|
| 612 |
-
fetch(
|
| 613 |
method: 'POST',
|
| 614 |
headers: { 'Content-Type': 'application/json' },
|
| 615 |
body: JSON.stringify(payload)
|
|
@@ -632,27 +709,29 @@
|
|
| 632 |
});
|
| 633 |
}
|
| 634 |
|
| 635 |
-
function
|
| 636 |
-
fetch('/
|
| 637 |
method: 'POST',
|
| 638 |
headers: { 'Content-Type': 'application/json' },
|
| 639 |
-
body: JSON.stringify({})
|
| 640 |
})
|
| 641 |
.then(response => response.json())
|
| 642 |
.then(data => {
|
| 643 |
if (data.error) {
|
| 644 |
addMessage('bot', `Error: ${data.error}. Try again!`);
|
| 645 |
-
} else if (data.menu_items.length > 0) {
|
| 646 |
-
addMessage('bot', `--- Found ${data.menu_items.length} 'Both' items from Sector_Detail__c ---`);
|
| 647 |
-
displayItemsList(data.menu_items);
|
| 648 |
} else {
|
| 649 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 650 |
}
|
| 651 |
-
console.log('Fetched Both items:', data.menu_items);
|
| 652 |
})
|
| 653 |
.catch(error => {
|
| 654 |
addMessage('bot', `Connection issue: ${error.message}. Retrying...`);
|
| 655 |
-
setTimeout(
|
| 656 |
});
|
| 657 |
}
|
| 658 |
|
|
@@ -669,6 +748,7 @@
|
|
| 669 |
} else {
|
| 670 |
const details = data.item_details;
|
| 671 |
if (itemIndex !== null) {
|
|
|
|
| 672 |
if (!selectedItems[itemIndex].additionalIngredients) {
|
| 673 |
selectedItems[itemIndex].additionalIngredients = [];
|
| 674 |
}
|
|
@@ -680,6 +760,7 @@
|
|
| 680 |
addMessage('bot', `"${details.name}" already added to "${selectedItems[itemIndex].name}"!`);
|
| 681 |
}
|
| 682 |
} else {
|
|
|
|
| 683 |
if (selectedItems.some(item => item.name === details.name && !item.additionalIngredients)) {
|
| 684 |
addMessage('bot', `"${details.name}" already selected!`);
|
| 685 |
} else {
|
|
@@ -727,13 +808,8 @@
|
|
| 727 |
|
| 728 |
const fields = [
|
| 729 |
{ label: 'Price', value: item.price ? `$${item.price.toFixed(2)}` : 'N/A' },
|
| 730 |
-
{ label: 'Veg/Non-Veg', value: item.veg_nonveg },
|
| 731 |
-
{ label: '
|
| 732 |
-
{ label: 'Category', value: item.category },
|
| 733 |
-
{ label: 'Ingredients', value: item.ingredients },
|
| 734 |
-
{ label: 'Nutrition', value: item.nutritional_info },
|
| 735 |
-
{ label: 'Sector', value: item.sector },
|
| 736 |
-
{ label: 'Dynamic', value: item.dynamic_dish ? 'Yes' : 'No' }
|
| 737 |
];
|
| 738 |
fields.forEach(field => {
|
| 739 |
if (field.value) {
|
|
@@ -756,17 +832,10 @@
|
|
| 756 |
const selectedItem = {
|
| 757 |
name: item.name,
|
| 758 |
image_url: item.image_url || '',
|
| 759 |
-
category: item.category || 'Not specified',
|
| 760 |
description: item.description || 'No description available',
|
| 761 |
source: item.source,
|
| 762 |
quantity: 1,
|
| 763 |
-
ingredients: item.ingredients,
|
| 764 |
-
nutritional_info: item.nutritional_info,
|
| 765 |
-
price: item.price,
|
| 766 |
-
sector: item.sector,
|
| 767 |
-
spice_levels: item.spice_levels,
|
| 768 |
-
veg_nonveg: item.veg_nonveg,
|
| 769 |
-
dynamic_dish: item.dynamic_dish,
|
| 770 |
additionalIngredients: []
|
| 771 |
};
|
| 772 |
if (selectedItems.some(existing => existing.name === selectedItem.name && !existing.additionalIngredients)) {
|
|
@@ -787,51 +856,20 @@
|
|
| 787 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 788 |
}
|
| 789 |
|
| 790 |
-
function
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
}
|
| 796 |
-
const optionsDiv = document.createElement('div');
|
| 797 |
-
optionsDiv.className = 'options-container';
|
| 798 |
-
|
| 799 |
-
options.forEach(opt => {
|
| 800 |
-
const button = document.createElement('button');
|
| 801 |
-
button.textContent = opt.text;
|
| 802 |
-
button.className = `option-button ${opt.class}`;
|
| 803 |
-
button.onclick = () => {
|
| 804 |
-
addMessage('user', opt.text);
|
| 805 |
-
conversation.push({ role: 'user', message: opt.text });
|
| 806 |
-
selectionBoxVisible = true;
|
| 807 |
-
handleResponse(opt.text);
|
| 808 |
-
updateSelectionBox();
|
| 809 |
-
};
|
| 810 |
-
optionsDiv.appendChild(button);
|
| 811 |
-
});
|
| 812 |
-
|
| 813 |
-
chatMessages.appendChild(optionsDiv);
|
| 814 |
}
|
| 815 |
|
| 816 |
-
function
|
| 817 |
-
const orderNameInput = document.querySelector('.order-name-input');
|
| 818 |
-
const quantityInput = document.querySelector('.quantity-input');
|
| 819 |
-
const customOrderName = orderNameInput ? orderNameInput.value.trim() : '';
|
| 820 |
-
const quantity = quantityInput ? parseInt(quantityInput.value) || 1 : 1;
|
| 821 |
-
|
| 822 |
if (selectedItems.length === 0) {
|
| 823 |
addMessage('bot', 'No items selected! Add some dishes! 😊');
|
| 824 |
return;
|
| 825 |
}
|
| 826 |
|
| 827 |
-
if (confirm(`Submit ${selectedItems.length} items (Qty: ${quantity})?`)) {
|
| 828 |
-
submitToSalesforce(customOrderName, quantity);
|
| 829 |
-
} else {
|
| 830 |
-
addMessage('bot', 'Cancelled. Add more items?');
|
| 831 |
-
}
|
| 832 |
-
}
|
| 833 |
-
|
| 834 |
-
function submitToSalesforce(customOrderName, quantity) {
|
| 835 |
const itemsToSubmit = selectedItems.map(item => ({
|
| 836 |
name: item.additionalIngredients && item.additionalIngredients.length > 0
|
| 837 |
? `${item.name} with ${item.additionalIngredients.join(', ')}`
|
|
@@ -839,7 +877,7 @@
|
|
| 839 |
category: item.category || 'Not specified',
|
| 840 |
description: item.description || 'No description available',
|
| 841 |
image_url: item.image_url || '',
|
| 842 |
-
quantity: quantity,
|
| 843 |
additionalIngredients: item.additionalIngredients || []
|
| 844 |
}));
|
| 845 |
|
|
@@ -854,10 +892,8 @@
|
|
| 854 |
addMessage('bot', `Submission failed: ${data.error}. Try again?`);
|
| 855 |
} else {
|
| 856 |
addMessage('bot', `Submitted ${data.ingredient_name}! What's next?`);
|
| 857 |
-
submittedItems = [...itemsToSubmit];
|
| 858 |
selectedItems = [];
|
| 859 |
updateSelectionBox();
|
| 860 |
-
updateSubmissionBox();
|
| 861 |
}
|
| 862 |
})
|
| 863 |
.catch(error => {
|
|
@@ -870,6 +906,8 @@
|
|
| 870 |
if (e.key === 'Enter') sendMessage();
|
| 871 |
});
|
| 872 |
|
|
|
|
|
|
|
| 873 |
console.log('Chef Bot script loaded!');
|
| 874 |
</script>
|
| 875 |
</body>
|
|
|
|
| 225 |
.option-button.gray { background-color: #616161; }
|
| 226 |
.option-button:active { opacity: 0.9; }
|
| 227 |
|
| 228 |
+
.selection-box {
|
| 229 |
background-color: #e1f5fe;
|
| 230 |
padding: 8px;
|
| 231 |
border: 1px solid #0288d1;
|
|
|
|
| 238 |
gap: 5px;
|
| 239 |
}
|
| 240 |
|
| 241 |
+
.selection-box span {
|
| 242 |
background-color: #bbdefb;
|
| 243 |
padding: 3px 8px;
|
| 244 |
border-radius: 5px;
|
|
|
|
| 262 |
margin-right: 5px;
|
| 263 |
}
|
| 264 |
|
| 265 |
+
.submit-button {
|
| 266 |
padding: 6px 10px;
|
| 267 |
background-color: #0288d1;
|
| 268 |
color: white;
|
|
|
|
| 273 |
min-width: 60px;
|
| 274 |
}
|
| 275 |
|
| 276 |
+
.submit-button:active {
|
| 277 |
background-color: #0277bd;
|
| 278 |
}
|
| 279 |
|
|
|
|
| 292 |
background-color: #b71c1c;
|
| 293 |
}
|
| 294 |
|
| 295 |
+
.manual-input, .custom-input, .submit-input {
|
| 296 |
padding: 4px;
|
| 297 |
border: 1px solid #0288d1;
|
| 298 |
border-radius: 5px;
|
|
|
|
| 316 |
width: 100px;
|
| 317 |
}
|
| 318 |
|
| 319 |
+
.sector-buttons {
|
| 320 |
+
display: flex;
|
| 321 |
+
gap: 5px;
|
| 322 |
+
margin: 5px 0;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
@media (max-width: 480px) {
|
| 326 |
+
.chat-header {
|
| 327 |
+
font-size: 14px;
|
| 328 |
+
padding: 6px;
|
| 329 |
+
}
|
| 330 |
+
.chat-messages {
|
| 331 |
+
padding: 3px;
|
| 332 |
+
}
|
| 333 |
+
.bot-message, .user-message {
|
| 334 |
+
font-size: 11px;
|
| 335 |
+
padding: 6px;
|
| 336 |
+
margin: 3px 0;
|
| 337 |
+
}
|
| 338 |
+
.chat-input input {
|
| 339 |
+
font-size: 11px;
|
| 340 |
+
min-height: 30px;
|
| 341 |
+
padding: 5px;
|
| 342 |
+
}
|
| 343 |
+
.chat-input button {
|
| 344 |
+
font-size: 11px;
|
| 345 |
+
min-height: 30px;
|
| 346 |
+
padding: 5px 8px;
|
| 347 |
+
min-width: 50px;
|
| 348 |
+
}
|
| 349 |
+
.items-grid {
|
| 350 |
+
flex-direction: column;
|
| 351 |
+
overflow-x: hidden;
|
| 352 |
+
gap: 6px;
|
| 353 |
+
padding: 6px;
|
| 354 |
+
}
|
| 355 |
+
.item-card {
|
| 356 |
+
width: 100%;
|
| 357 |
+
flex: 0 0 auto;
|
| 358 |
+
max-width: 120px;
|
| 359 |
+
}
|
| 360 |
+
.item-image {
|
| 361 |
+
height: 80px;
|
| 362 |
+
}
|
| 363 |
+
.item-name {
|
| 364 |
+
font-size: 10px;
|
| 365 |
+
}
|
| 366 |
+
.item-field, .item-description {
|
| 367 |
+
font-size: 9px;
|
| 368 |
+
}
|
| 369 |
+
.show-button, .add-button {
|
| 370 |
+
font-size: 9px;
|
| 371 |
+
padding: 3px;
|
| 372 |
+
min-width: 35px;
|
| 373 |
+
}
|
| 374 |
+
.option-button {
|
| 375 |
+
font-size: 11px;
|
| 376 |
+
padding: 5px 8px;
|
| 377 |
+
min-width: 50px;
|
| 378 |
+
}
|
| 379 |
+
.selection-box {
|
| 380 |
+
padding: 6px;
|
| 381 |
+
gap: 3px;
|
| 382 |
+
}
|
| 383 |
+
.selection-box span {
|
| 384 |
+
font-size: 11px;
|
| 385 |
+
padding: 2px 6px;
|
| 386 |
+
}
|
| 387 |
+
.selected-item {
|
| 388 |
+
font-size: 10px;
|
| 389 |
+
padding: 2px 6px;
|
| 390 |
+
}
|
| 391 |
+
.selected-item-image {
|
| 392 |
+
width: 20px;
|
| 393 |
+
height: 20px;
|
| 394 |
+
}
|
| 395 |
+
.submit-button {
|
| 396 |
+
font-size: 11px;
|
| 397 |
+
padding: 5px 8px;
|
| 398 |
+
min-width: 50px;
|
| 399 |
+
}
|
| 400 |
+
.remove-button {
|
| 401 |
+
font-size: 9px;
|
| 402 |
+
padding: 2px 5px;
|
| 403 |
+
}
|
| 404 |
+
.manual-input, .custom-input, .submit-input, .order-name-input {
|
| 405 |
+
width: 80px;
|
| 406 |
+
font-size: 11px;
|
| 407 |
+
padding: 3px;
|
| 408 |
+
}
|
| 409 |
+
.quantity-input {
|
| 410 |
+
width: 40px;
|
| 411 |
+
font-size: 11px;
|
| 412 |
+
padding: 3px;
|
| 413 |
+
}
|
| 414 |
}
|
| 415 |
</style>
|
| 416 |
</head>
|
|
|
|
| 418 |
<div class="chat-container">
|
| 419 |
<div class="chat-header">🍳 Chef Bot</div>
|
| 420 |
<div class="chat-messages" id="chatMessages">
|
| 421 |
+
<div class="bot-message">Hello! I’m Chef Bot! Choose a preference or type a dish below!</div>
|
| 422 |
</div>
|
| 423 |
<div class="chat-input">
|
| 424 |
+
<input type="text" id="userInput" placeholder="Type dish or preference...">
|
| 425 |
<button onclick="sendMessage()">Send</button>
|
| 426 |
</div>
|
| 427 |
</div>
|
| 428 |
|
| 429 |
<script>
|
| 430 |
let conversation = [
|
| 431 |
+
{ role: 'bot', message: 'Hello! I’m Chef Bot! Choose a preference or type a dish below!' }
|
| 432 |
];
|
| 433 |
let selectedItems = [];
|
|
|
|
| 434 |
let selectionBoxVisible = false;
|
| 435 |
|
| 436 |
function addMessage(role, message) {
|
|
|
|
| 464 |
}
|
| 465 |
userInput.value = '';
|
| 466 |
updateSelectionBox();
|
|
|
|
| 467 |
}
|
| 468 |
|
| 469 |
function handleResponse(userInput) {
|
| 470 |
const lowerInput = userInput.toLowerCase();
|
| 471 |
let botResponse = '';
|
| 472 |
|
| 473 |
+
if (lowerInput === 'vegetarian' || lowerInput === 'non-vegetarian') {
|
| 474 |
+
botResponse = `Fetching ${lowerInput} dishes...`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 475 |
addMessage('bot', botResponse);
|
| 476 |
fetchMenuItems(lowerInput);
|
| 477 |
} else {
|
| 478 |
+
botResponse = `Looking for "${userInput}"...`;
|
| 479 |
addMessage('bot', botResponse);
|
| 480 |
fetchMenuItems(null, userInput);
|
| 481 |
}
|
|
|
|
| 488 |
const existingBox = document.querySelector('.selection-box');
|
| 489 |
if (existingBox) existingBox.remove();
|
| 490 |
|
| 491 |
+
const existingCustomBox = document.querySelector('.custom-box');
|
| 492 |
+
if (existingCustomBox) existingCustomBox.remove();
|
| 493 |
+
|
| 494 |
+
const existingSubmitBox = document.querySelector('.submit-box');
|
| 495 |
+
if (existingSubmitBox) existingSubmitBox.remove();
|
| 496 |
+
|
| 497 |
+
// First Selection Box (Name Input)
|
| 498 |
+
if (selectionBoxVisible) {
|
| 499 |
+
const selectionBox = document.createElement('div');
|
| 500 |
+
selectionBox.className = 'selection-box';
|
| 501 |
+
|
| 502 |
+
const vegButton = document.createElement('button');
|
| 503 |
+
vegButton.textContent = 'Veg';
|
| 504 |
+
vegButton.className = 'option-button green';
|
| 505 |
+
vegButton.onclick = () => {
|
| 506 |
+
addMessage('user', 'Vegetarian');
|
| 507 |
+
conversation.push({ role: 'user', message: 'Vegetarian' });
|
| 508 |
+
handleResponse('vegetarian');
|
| 509 |
+
};
|
| 510 |
+
selectionBox.appendChild(vegButton);
|
| 511 |
+
|
| 512 |
+
const nonVegButton = document.createElement('button');
|
| 513 |
+
nonVegButton.textContent = 'Non-Veg';
|
| 514 |
+
nonVegButton.className = 'option-button red';
|
| 515 |
+
nonVegButton.onclick = () => {
|
| 516 |
+
addMessage('user', 'Non-Vegetarian');
|
| 517 |
+
conversation.push({ role: 'user', message: 'Non-Vegetarian' });
|
| 518 |
+
handleResponse('non-vegetarian');
|
| 519 |
+
};
|
| 520 |
+
selectionBox.appendChild(nonVegButton);
|
| 521 |
+
|
| 522 |
+
const nameInput = document.createElement('input');
|
| 523 |
+
nameInput.type = 'text';
|
| 524 |
+
nameInput.placeholder = 'Enter dish name...';
|
| 525 |
+
nameInput.className = 'manual-input';
|
| 526 |
+
nameInput.addEventListener('keypress', (e) => {
|
| 527 |
+
if (e.key === 'Enter' && nameInput.value.trim()) {
|
| 528 |
+
const itemName = nameInput.value.trim();
|
| 529 |
+
addMessage('user', itemName);
|
| 530 |
+
conversation.push({ role: 'user', message: itemName });
|
| 531 |
+
handleResponse(itemName);
|
| 532 |
+
nameInput.value = '';
|
| 533 |
+
}
|
| 534 |
+
});
|
| 535 |
+
selectionBox.appendChild(nameInput);
|
| 536 |
|
| 537 |
+
chatMessages.appendChild(selectionBox);
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
// Second Custom Box (Menu Items and Custom Requests)
|
| 541 |
if (selectedItems.length > 0) {
|
| 542 |
+
const customBox = document.createElement('div');
|
| 543 |
+
customBox.className = 'selection-box custom-box';
|
| 544 |
+
|
| 545 |
const label = document.createElement('span');
|
| 546 |
+
label.textContent = 'Selected Items:';
|
| 547 |
+
customBox.appendChild(label);
|
| 548 |
|
| 549 |
selectedItems.forEach((item, index) => {
|
| 550 |
const itemContainer = document.createElement('div');
|
|
|
|
| 566 |
itemSpan.textContent = `${itemName} (Qty: ${item.quantity || 1})`;
|
| 567 |
contentDiv.appendChild(itemSpan);
|
| 568 |
|
| 569 |
+
const customInput = document.createElement('input');
|
| 570 |
+
customInput.type = 'text';
|
| 571 |
+
customInput.placeholder = 'Add ingredient...';
|
| 572 |
+
customInput.className = 'custom-input';
|
| 573 |
+
customInput.addEventListener('keypress', (e) => {
|
| 574 |
+
if (e.key === 'Enter' && customInput.value.trim()) {
|
| 575 |
+
const ingredientName = customInput.value.trim();
|
| 576 |
fetchSectorItemDetails(ingredientName, index);
|
| 577 |
+
customInput.value = '';
|
| 578 |
}
|
| 579 |
});
|
| 580 |
+
contentDiv.appendChild(customInput);
|
| 581 |
|
| 582 |
itemContainer.appendChild(contentDiv);
|
| 583 |
|
|
|
|
| 591 |
};
|
| 592 |
itemContainer.appendChild(removeButton);
|
| 593 |
|
| 594 |
+
customBox.appendChild(itemContainer);
|
| 595 |
+
|
| 596 |
+
// Display original item if customized
|
| 597 |
+
if (item.additionalIngredients && item.additionalIngredients.length > 0) {
|
| 598 |
+
const originalContainer = document.createElement('div');
|
| 599 |
+
originalContainer.className = 'selected-item';
|
| 600 |
+
|
| 601 |
+
const originalImg = document.createElement('img');
|
| 602 |
+
originalImg.src = item.image_url || 'https://via.placeholder.com/30';
|
| 603 |
+
originalImg.alt = item.name;
|
| 604 |
+
originalImg.className = 'selected-item-image';
|
| 605 |
+
originalContainer.appendChild(originalImg);
|
| 606 |
+
|
| 607 |
+
const originalContentDiv = document.createElement('div');
|
| 608 |
+
originalContentDiv.className = 'selected-item-content';
|
| 609 |
+
|
| 610 |
+
const originalSpan = document.createElement('span');
|
| 611 |
+
originalSpan.textContent = `${item.name} (Qty: ${item.quantity || 1})`;
|
| 612 |
+
originalContentDiv.appendChild(originalSpan);
|
| 613 |
+
|
| 614 |
+
originalContainer.appendChild(originalContentDiv);
|
| 615 |
+
|
| 616 |
+
const originalRemoveButton = document.createElement('button');
|
| 617 |
+
originalRemoveButton.textContent = 'X';
|
| 618 |
+
originalRemoveButton.className = 'remove-button';
|
| 619 |
+
originalRemoveButton.onclick = () => {
|
| 620 |
+
selectedItems.splice(index, 1);
|
| 621 |
+
addMessage('bot', `Removed "${item.name}".`);
|
| 622 |
+
updateSelectionBox();
|
| 623 |
+
};
|
| 624 |
+
originalContainer.appendChild(originalRemoveButton);
|
| 625 |
+
|
| 626 |
+
customBox.appendChild(originalContainer);
|
| 627 |
+
}
|
| 628 |
});
|
| 629 |
|
| 630 |
+
chatMessages.appendChild(customBox);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 631 |
|
| 632 |
+
// Sector_Detail__c Buttons
|
| 633 |
+
const sectorButtons = document.createElement('div');
|
| 634 |
+
sectorButtons.className = 'sector-buttons';
|
| 635 |
+
|
| 636 |
+
const vegItemsButton = document.createElement('button');
|
| 637 |
+
vegItemsButton.textContent = 'Veg Items';
|
| 638 |
+
vegItemsButton.className = 'option-button green';
|
| 639 |
+
vegItemsButton.onclick = () => fetchSectorItems('vegetarian');
|
| 640 |
+
sectorButtons.appendChild(vegItemsButton);
|
| 641 |
+
|
| 642 |
+
const nonVegItemsButton = document.createElement('button');
|
| 643 |
+
nonVegItemsButton.textContent = 'Non-Veg Items';
|
| 644 |
+
nonVegItemsButton.className = 'option-button red';
|
| 645 |
+
nonVegItemsButton.onclick = () => fetchSectorItems('non-vegetarian');
|
| 646 |
+
sectorButtons.appendChild(nonVegItemsButton);
|
| 647 |
+
|
| 648 |
+
chatMessages.appendChild(sectorButtons);
|
| 649 |
+
|
| 650 |
+
// Third Submit Box
|
| 651 |
+
const submitBox = document.createElement('div');
|
| 652 |
+
submitBox.className = 'selection-box submit-box';
|
| 653 |
+
|
| 654 |
+
const submitLabel = document.createElement('span');
|
| 655 |
+
submitLabel.textContent = 'Submit Order:';
|
| 656 |
+
submitBox.appendChild(submitLabel);
|
| 657 |
|
| 658 |
const quantityInput = document.createElement('input');
|
| 659 |
quantityInput.type = 'number';
|
|
|
|
| 661 |
quantityInput.value = '1';
|
| 662 |
quantityInput.placeholder = 'Qty';
|
| 663 |
quantityInput.className = 'quantity-input';
|
| 664 |
+
submitBox.appendChild(quantityInput);
|
| 665 |
|
| 666 |
const orderNameInput = document.createElement('input');
|
| 667 |
orderNameInput.type = 'text';
|
| 668 |
orderNameInput.placeholder = 'Order Name';
|
| 669 |
orderNameInput.className = 'order-name-input';
|
| 670 |
+
submitBox.appendChild(orderNameInput);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 671 |
|
| 672 |
+
const submitButton = document.createElement('button');
|
| 673 |
+
submitButton.textContent = 'Submit';
|
| 674 |
+
submitButton.className = 'submit-button';
|
| 675 |
+
submitButton.onclick = () => promptAndSubmit(quantityInput.value, orderNameInput.value);
|
| 676 |
+
submitBox.appendChild(submitButton);
|
| 677 |
|
| 678 |
+
chatMessages.appendChild(submitBox);
|
| 679 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 680 |
|
|
|
|
| 681 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 682 |
+
console.log('Updated selection boxes:', selectedItems.map(item => ({ name: item.name, additionalIngredients: item.additionalIngredients })));
|
| 683 |
}
|
| 684 |
|
| 685 |
function fetchMenuItems(dietaryPreference = '', searchTerm = '') {
|
| 686 |
const payload = {};
|
| 687 |
if (dietaryPreference) payload.dietary_preference = dietaryPreference;
|
| 688 |
if (searchTerm) payload.search_term = searchTerm;
|
| 689 |
+
fetch('/get_menu_items', {
|
| 690 |
method: 'POST',
|
| 691 |
headers: { 'Content-Type': 'application/json' },
|
| 692 |
body: JSON.stringify(payload)
|
|
|
|
| 709 |
});
|
| 710 |
}
|
| 711 |
|
| 712 |
+
function fetchSectorItems(dietaryPreference) {
|
| 713 |
+
fetch('/get_menu_items', {
|
| 714 |
method: 'POST',
|
| 715 |
headers: { 'Content-Type': 'application/json' },
|
| 716 |
+
body: JSON.stringify({ dietary_preference })
|
| 717 |
})
|
| 718 |
.then(response => response.json())
|
| 719 |
.then(data => {
|
| 720 |
if (data.error) {
|
| 721 |
addMessage('bot', `Error: ${data.error}. Try again!`);
|
|
|
|
|
|
|
|
|
|
| 722 |
} else {
|
| 723 |
+
const sectorItems = data.menu_items.filter(item => item.source === 'Sector_Detail__c');
|
| 724 |
+
if (sectorItems.length > 0) {
|
| 725 |
+
addMessage('bot', `--- Found ${sectorItems.length} ${dietaryPreference} items from Sector_Detail__c ---`);
|
| 726 |
+
displayItemsList(sectorItems);
|
| 727 |
+
} else {
|
| 728 |
+
addMessage('bot', `No ${dietaryPreference} items found in Sector_Detail__c.`);
|
| 729 |
+
}
|
| 730 |
}
|
|
|
|
| 731 |
})
|
| 732 |
.catch(error => {
|
| 733 |
addMessage('bot', `Connection issue: ${error.message}. Retrying...`);
|
| 734 |
+
setTimeout(() => fetchSectorItems(dietaryPreference), 2000);
|
| 735 |
});
|
| 736 |
}
|
| 737 |
|
|
|
|
| 748 |
} else {
|
| 749 |
const details = data.item_details;
|
| 750 |
if (itemIndex !== null) {
|
| 751 |
+
// Adding as an additional ingredient
|
| 752 |
if (!selectedItems[itemIndex].additionalIngredients) {
|
| 753 |
selectedItems[itemIndex].additionalIngredients = [];
|
| 754 |
}
|
|
|
|
| 760 |
addMessage('bot', `"${details.name}" already added to "${selectedItems[itemIndex].name}"!`);
|
| 761 |
}
|
| 762 |
} else {
|
| 763 |
+
// Adding as a new item
|
| 764 |
if (selectedItems.some(item => item.name === details.name && !item.additionalIngredients)) {
|
| 765 |
addMessage('bot', `"${details.name}" already selected!`);
|
| 766 |
} else {
|
|
|
|
| 808 |
|
| 809 |
const fields = [
|
| 810 |
{ label: 'Price', value: item.price ? `$${item.price.toFixed(2)}` : 'N/A' },
|
| 811 |
+
{ label: 'Veg/Non-Veg', value: item.veg_nonveg || item.category },
|
| 812 |
+
{ label: 'Description', value: item.description },
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 813 |
];
|
| 814 |
fields.forEach(field => {
|
| 815 |
if (field.value) {
|
|
|
|
| 832 |
const selectedItem = {
|
| 833 |
name: item.name,
|
| 834 |
image_url: item.image_url || '',
|
| 835 |
+
category: item.category || item.veg_nonveg || 'Not specified',
|
| 836 |
description: item.description || 'No description available',
|
| 837 |
source: item.source,
|
| 838 |
quantity: 1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 839 |
additionalIngredients: []
|
| 840 |
};
|
| 841 |
if (selectedItems.some(existing => existing.name === selectedItem.name && !existing.additionalIngredients)) {
|
|
|
|
| 856 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 857 |
}
|
| 858 |
|
| 859 |
+
function promptAndSubmit(quantity, orderName) {
|
| 860 |
+
if (confirm(`Submit ${selectedItems.length} items (Qty: ${quantity}) as "${orderName || 'Order'}"?`)) {
|
| 861 |
+
submitToSalesforce(orderName, quantity);
|
| 862 |
+
} else {
|
| 863 |
+
addMessage('bot', 'Cancelled. Add more items?');
|
| 864 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 865 |
}
|
| 866 |
|
| 867 |
+
function submitToSalesforce(customOrderName, quantity) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 868 |
if (selectedItems.length === 0) {
|
| 869 |
addMessage('bot', 'No items selected! Add some dishes! 😊');
|
| 870 |
return;
|
| 871 |
}
|
| 872 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 873 |
const itemsToSubmit = selectedItems.map(item => ({
|
| 874 |
name: item.additionalIngredients && item.additionalIngredients.length > 0
|
| 875 |
? `${item.name} with ${item.additionalIngredients.join(', ')}`
|
|
|
|
| 877 |
category: item.category || 'Not specified',
|
| 878 |
description: item.description || 'No description available',
|
| 879 |
image_url: item.image_url || '',
|
| 880 |
+
quantity: parseInt(quantity) || 1,
|
| 881 |
additionalIngredients: item.additionalIngredients || []
|
| 882 |
}));
|
| 883 |
|
|
|
|
| 892 |
addMessage('bot', `Submission failed: ${data.error}. Try again?`);
|
| 893 |
} else {
|
| 894 |
addMessage('bot', `Submitted ${data.ingredient_name}! What's next?`);
|
|
|
|
| 895 |
selectedItems = [];
|
| 896 |
updateSelectionBox();
|
|
|
|
| 897 |
}
|
| 898 |
})
|
| 899 |
.catch(error => {
|
|
|
|
| 906 |
if (e.key === 'Enter') sendMessage();
|
| 907 |
});
|
| 908 |
|
| 909 |
+
// Initial display of Veg/Non-Veg buttons
|
| 910 |
+
updateSelectionBox();
|
| 911 |
console.log('Chef Bot script loaded!');
|
| 912 |
</script>
|
| 913 |
</body>
|