K
KOS COMPANY
Ciao, vuoi informazioni sul nostro servizio?
Oppure hai intenzione di sviluppare un prodotto?
`; messagesContainer.appendChild(holder); messagesContainer.scrollTop = messagesContainer.scrollHeight; } function hideTyping() { const el = document.getElementById("typingIndicator"); if (el) el.remove(); } /* ===== Invio messaggio ===== */ function sendMessage() { const userText = input.value.trim(); if (!userText) return; // assicura un id chat (solo backend) ensureChatId(); // Messaggio utente appendMessage(userText, "user"); input.value = ""; // animazione in attesa showTyping(); // indice messaggio const msgIndex = bumpMessageIndex(); fetch(webhookUrl, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ question: userText, chat_id: CHAT_ID, message_index: msgIndex, started_at: CHAT_STARTED_AT }) }) .then(r => r.json()) .then(data => { hideTyping(); const payload = Array.isArray(data) ? (data[0] || {}) : (data || {}); const reply = payload.reply || {}; // 2.1: summary const summaryRaw = reply.summary || ""; const summaryPlain = summaryRaw ? stripHtml(summaryRaw) : splitSummary(reply.text || "").summary; // 2.2: details let detailsRaw = reply.details || payload.data || ""; if (!detailsRaw) { const rest = splitSummary(reply.text || "").rest; detailsRaw = rest; } const isRichList = / { hideTyping(); appendBotReply("⚠️ Errore di connessione.", ""); }); } // Enter = invio input.addEventListener("keypress", function (e) { if (e.key === "Enter") sendMessage(); });