try { var options = { chatPanel: { header: { filters: { filterValues: ["Spain","Web"] } }, settings: { conversationId: sessionStorage.getItem("myConversationId"), startLanguage: "es-ES", enableProactivityForSmallDevices: true, requestFeedback: false } }, }; var boost = window.boostInit("sectoralarm", options); var chatPanel = boost.chatPanel; var hasSentMessage = false; let btn = document.createElement("button"); btn.id = "boostai"; btn.type = "button"; btn.className = "button button__small boost_button"; var el = ' '; btn.innerHTML = "Chatea con nosotros" + el; btn.onclick = function () { openChat(); }; document.body.appendChild(btn); let div = document.createElement("div"); div.id = "csatmodal"; div.className = "csatmodal"; div.innerHTML = "
" + "
" + "" + "Chatea con Sector Alarm
" + "
"; div.style.display = "none"; document.body.appendChild(div); const closeModalsBtn = document.querySelectorAll(".modal-box__exit-button"); closeModalsBtn.forEach(closeBtn => { closeBtn.addEventListener('click', (e) => { e.currentTarget.parentElement.parentElement.parentElement.style.display = 'none' }); }); var modalbody = document.getElementById("modalbody"); var html = '
' + '
' + '
' + '
' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + 'Si hay algo que quieras compartir con nosotros, puedes dejarnos un comentario.' + '' + '' + '' + '
' + '
'; modalbody.innerHTML = "

¡Valora tu experiencia en el chat!

" + html; form = document.getElementById('csat-form'); form.onsubmit = function (e) { var country = "ES"; e.preventDefault(); if (form.rating.value !== "" || form.message.value !== "") { sendfeedback(reference, conversationId, form.rating.value, form.message.value, country); var modal = document.getElementById("csatmodal"); modal.style.display = "none"; } }; } catch (ex){ } function openChat() { boost.chatPanel.addEventListener("conversationIdChanged", function (event) { if (typeof event.detail.conversationId === 'string' && event.detail.conversationId !== "") { //only change if it has a value sessionStorage.setItem("myConversationId", event.detail.conversationId); conversationId = event.detail.conversationId; } }); boost.chatPanel.addEventListener('conversationReferenceChanged', function (ev) { reference = ev.detail.conversationReference; }); boost.chatPanel.addEventListener("chatPanelClosed", function (event) { sessionStorage.removeItem("myConversationId"); if (hasSentMessage) { opencsatmodal(); } }); boost.chatPanel.addEventListener("messageSent", function () { hasSentMessage = true; }); boost.chatPanel.show(); } function opencsatmodal() { const modal = document.getElementById("csatmodal"); modal.style.display = "block"; } function closecsatmodal() { const modal = document.getElementById("csatmodal"); modal.style.display = "none"; } function sendfeedback(reference, conversationId, csat, comments, country) { console.log("Feedback - " + reference + " " + conversationId + " " + csat + " " + comments + " " + country); var rating = 1; var csatscore = parseInt(csat); if (csatscore < 4) { rating = 0; } var data = { command: "FEEDBACK", conversation_id: conversationId, value: { rating: rating, text: "CSAT Score : " + csat + " - " + comments } }; $.ajax({ type: 'POST', xhrFields: { withCredentials: true }, url: "https://sectoralarm.boost.ai/api/chat/v2", headers: { "Content-Type": "application/json" }, data: JSON.stringify(data), success: function (data, textStatus, xhr) { console.log("Success - " + xhr.status); }, error: function (xhr, ajaxOptions, throwError) { //Error block console.log("Fail - " + xhr.status); } }); }