(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(); // Force social icons after the thank-you line, even if no links/marker are present if ( isMedantaClient && /Thank you for taking this assessment\.?/i.test(botAnswer) ) { renderSocialShareOptions(botBubble); } // Reset inactivity timer after bot reply as well startOrResetInactivityTimer(); // Render choice buttons for Medanta based on the latest bot message, directly under it renderOptionButtonsFrom(botAnswer, botBubble); // Medanta: after assessment result, show only the first FAQ question button if ( isMedantaClient && !medantaFaqShown && /Prostate\s+Cancer\s+Risk\s+Level:/i.test(botAnswer) ) { medantaFaqShown = true; medantaQuestionStep = 0; // Track assessment completion const riskLevelMatch = botAnswer.match( /Prostate\s+Cancer\s+Risk\s+Level:\s*(LOW|HIGH)/i ); logMedantaAnalyticsEvent("assessment_completed", { risk_level: riskLevelMatch ? riskLevelMatch[1].toUpperCase() : null, }); // Render a single button to start FAQs renderFaqFirstButton(botBubble); } // Track assessment start (when Q1 is shown) if ( isMedantaClient && /How old are you/i.test(botAnswer) && /\(a\)|\(b\)|\(c\)|\(d\)|\(e\)/i.test(botAnswer) ) { logMedantaAnalyticsEvent("assessment_started"); medantaQuestionStep = 1; } } // 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(); }); if (!isMedantaClient) { 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(); }); }); } // Enforce buttons-only UI for Medanta: hide text input bar and mic/send if (isMedantaClient && textInputBar) { textInputBar.style.setProperty("display", "none", "important"); } } 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); })();