(function () { const chatHtml = `
An error occured in serving your query. please try again
"; scrollToBottom(); return; } const reader = response.body.getReader(); const decoder = new TextDecoder("utf-8"); let botAnswer = ""; while (true) { const { done, value } = await reader.read(); if (done) break; botAnswer += decoder.decode(value, { stream: true }); typingBubble.innerHTML = marked.parse(botAnswer); scrollToBottom(); } typingBubble.remove(); const botBubble = createBubble(marked.parse(botAnswer), "bot"); chatMessagesListContainer.appendChild(botBubble); scrollToBottom(); // Reset inactivity timer after bot reply as well startOrResetInactivityTimer(); } // speech to text (voice input) let recognition; let isListening = false; if ("webkitSpeechRecognition" in window) { recognition = new webkitSpeechRecognition(); recognition.continuous = false; recognition.interimResults = false; recognition.lang = "en-US"; recognition.onstart = () => { isListening = true; microphoneButton.classList.add("listening"); }; recognition.onend = () => { isListening = false; microphoneButton.classList.remove("listening"); }; recognition.onresult = (e) => { const transcript = e.results[0][0].transcript; textInput.value = transcript; }; } else { microphoneButton.disabled = true; microphoneButton.title = "Speech recognition not supported in this browser"; } microphoneButton.addEventListener("click", (e) => { e.stopPropagation(); // Prevent container click event if (!recognition) return; if (!isListening) recognition.start(); else recognition.stop(); }); document.querySelectorAll(".suggestionsButton").forEach((suggestionBtn) => { suggestionBtn.addEventListener("click", (e) => { e.stopPropagation(); // Prevent container click event const question = suggestionBtn.innerHTML.trim(); textInput.value = question; sendMessage(question); startOrResetInactivityTimer(); }); }); } async function loadLibrary(src) { return new Promise((resolve, reject) => { const script = document.createElement("script"); script.src = src; script.onload = resolve; script.onerror = reject; document.head.appendChild(script); }); } loadLibrary("https://cdn.jsdelivr.net/npm/marked/marked.min.js"); // Remove Tailwind CDN - use our exact equivalent styles instead document.addEventListener("DOMContentLoaded", onDomContentLoaded); })();