StreamAI / scripts /chat.js
privateuserh's picture
Update scripts/chat.js
703af34 verified
raw
history blame
1.43 kB
// scripts/chat.js
const getElement = (id) => document.getElementById(id);
async function sendMessage() {
const userInput = getElement('user-input');
const chatMessages = getElement('chat-messages');
if (userInput.value.trim() === '') return;
// ... (keep the complete sendMessage logic from the previous response here)
// ... (This includes adding user message, creating AI bubble, and the fetch call)
}
function quickPrompt(prompt) {
getElement('user-input').value = prompt;
sendMessage();
}
function updateRecommendationsFromAI(aiResponse) {
// This is a placeholder. You can enhance this logic.
let filter = 'all';
if (aiResponse.includes('comedy')) filter = 'comedy';
else if (aiResponse.includes('thriller')) filter = 'thriller';
else if (aiResponse.includes('romance')) filter = 'romance';
// In a truly modular system, this would emit an event that ui.js listens for.
// For simplicity, we'll call a function defined in the global scope (see app.js).
window.loadRecommendations(filter);
}
export function initChat() {
getElement('send-btn').addEventListener('click', sendMessage);
getElement('user-input').addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
sendMessage();
}
});
// Make quickPrompt globally accessible for the inline HTML onclick attributes
window.quickPrompt = quickPrompt;
}