var __isChatVisible = false; var settingsChat = {}; var defaultSettings = { headerBackgroundColor: '#fcbe06', headerTextColor: '#000000', iconBackgroundColor: '#fcbe06', iconTextColor: '#000000', borderColor: '#fcbe06', firstRequestMessage: '' }; var mystyle = {}; var minimizar = true; var HttpClient = function () { this.get = function (aUrl, aCallback) { var anHttpRequest = new XMLHttpRequest(); anHttpRequest.onreadystatechange = function () { if (anHttpRequest.readyState == 4 && anHttpRequest.status == 200) aCallback(anHttpRequest.responseText); } anHttpRequest.open("GET", aUrl, true); anHttpRequest.send(null); } } function __init_chat_guru() { ___init_chat(true); } function ___init_chat(initchat) { if (initchat === true) { console.log("Checking script and parameter..."); var script = null; if (document.currentScript) { script = document.currentScript } else { // IE 11 support. var scripts = document.getElementsByTagName('script'); for (const s of scripts) { if (s.src && s.src.indexOf("chat.js") !== -1) { script = s; } } } if (script && script.src) { var url = new URL(script.src); const id = url.searchParams.get("id"); if (id) { console.log("ID read from scpt: " + id); const paramSettings = { minimized: true, nc: true, assistantName: 'null', buttonTextColor: 'null', buttonBackgroundColor: 'null', headerBackgroundColor: 'null', headerTextColor: 'null', chatHeight: '500px', chatWidth: '300px', zindex: 1300, pbottomdesktop: '80px', prightdesktop: '20px', pleftdesktop: 'inherit', pbottommobile: '20px', prightmobile: '20px', pleftmobile: 'revert', mode: 'default', urlVerSitio: '', }; __populateParamSettings(url, paramSettings); var client = new HttpClient(); var basePath = url.protocol + '//' + url.hostname + (url.port ? ':' + url.port : ''); client.get(basePath + '/api/Website/mapid/' + id, function(response) { const chaturl = basePath + '/widget/chat/' + response + '/' + window.location.hostname + '/' + id + '/' + encodeURIComponent(paramSettings.assistantName) + '/' + encodeURIComponent(paramSettings.buttonBackgroundColor) + '/' + encodeURIComponent(paramSettings.buttonTextColor) + '/' + encodeURIComponent(paramSettings.headerBackgroundColor) + '/' + encodeURIComponent(paramSettings.headerTextColor) + '/' + encodeURIComponent(window.location) + '/' + encodeURIComponent(paramSettings.urlVerSitio); const chatClientSettings = basePath + '/website/chat/settings/' + response; __loadChat(chaturl, chatClientSettings, paramSettings); //const pixelurl = 'https://traficogarantizado.com/pixel/pixel.png?tag=apertura_chat&id=' + encodeURIComponent(id) + '&site=' + encodeURIComponent(window.location); //client.get(pixelurl, function(r) { }); }); } else { console.log("cannot obtain id from chat"); } } } } window.addEventListener('load', function() { var script = null; if (document.currentScript) { script = document.currentScript } else { // IE 11 support. var scripts = document.getElementsByTagName('script'); for (const s of scripts) { if (s.src && s.src.indexOf("chat.js") !== -1) { script = s; } } } if (script && script.src) { var url = new URL(script.src); const id = url.searchParams.get("id"); if (id) { const paramSettings = { initChatAutomatically: true, }; __populateParamSettings(url, paramSettings); ___init_chat(paramSettings.initChatAutomatically); } } }) function __populateParamSettings(url, paramSettings){ const minimized = url.searchParams.get("minimized"); const headerBackgroundColor = url.searchParams.get("headerBackgroundColor"); const headerTextColor = url.searchParams.get("headerTextColor"); const iconBackgroundColor = url.searchParams.get("iconBackgroundColor"); const iconTextColor = url.searchParams.get("iconTextColor"); const borderColor = url.searchParams.get("borderColor"); const initChatAutomatically = url.searchParams.get("initChatAutomatically"); const assistantName = url.searchParams.get("assistantName"); const buttonTextColor = url.searchParams.get("buttonTextColor"); const buttonBackgroundColor = url.searchParams.get("buttonBackgroundColor"); const chatHeight = url.searchParams.get("chatHeight"); const chatWidth = url.searchParams.get("chatWidth"); const nc = url.searchParams.get("nc"); const urlVerSitio = url.searchParams.get("u"); const zindex = url.searchParams.get("zindex"); const prightmobile = url.searchParams.get("prightmobile"); const pleftmobile = url.searchParams.get("pleftmobile"); const pbottommobile = url.searchParams.get("pbottommobile"); const pbottomdesktop = url.searchParams.get("pbottomdesktop"); const prightdesktop = url.searchParams.get("prightdesktop"); const pleftdesktop= url.searchParams.get("pleftdesktop"); const mode= url.searchParams.get("mode"); if (minimized){ paramSettings.minimized = minimized === 'true'; } if (nc){ paramSettings.nc = nc === 'true'; } if (initChatAutomatically){ paramSettings.initChatAutomatically = initChatAutomatically === 'true'; } if (headerBackgroundColor){ paramSettings.headerBackgroundColor = headerBackgroundColor; } if (headerTextColor){ paramSettings.headerTextColor = headerTextColor; } if (iconBackgroundColor){ paramSettings.iconBackgroundColor = iconBackgroundColor; } if (iconTextColor){ paramSettings.iconTextColor = iconTextColor; } if (borderColor){ paramSettings.borderColor = borderColor; } if (assistantName){ paramSettings.assistantName = assistantName; } if (buttonTextColor){ paramSettings.buttonTextColor = buttonTextColor; } if (buttonBackgroundColor){ paramSettings.buttonBackgroundColor = buttonBackgroundColor; } if (chatHeight){ paramSettings.chatHeight = chatHeight; } if (chatWidth){ paramSettings.chatWidth = chatWidth; } if (urlVerSitio && urlVerSitio !== ""){ paramSettings.urlVerSitio = urlVerSitio; } if (zindex){ paramSettings.zindex = zindex; } if (pbottommobile){ paramSettings.pbottommobile = pbottommobile; } if (prightmobile){ paramSettings.prightmobile = prightmobile; } if (pleftmobile){ paramSettings.pleftmobile = pleftmobile; } if (pbottomdesktop){ paramSettings.pbottomdesktop = pbottomdesktop; } if (prightdesktop){ paramSettings.prightdesktop = prightdesktop; } if (pleftdesktop){ paramSettings.pleftdesktop = pleftdesktop; } if (mode){ paramSettings.mode = mode; } } window.addEventListener('resize', function () { //__onresize(); }) function __clean() { if (document.getElementById("pguruchatid")) { document.getElementById("pguruchatid").remove(); } } function __loadSetting(chatClientSettingsUrl) { return fetch(chatClientSettingsUrl).then(function(response) { return response.json(); }); } function __adjustSettings(settings, paramSettings) { if (paramSettings.headerBackgroundColor){ settings.headerBackgroundColor = paramSettings.headerBackgroundColor; } if (paramSettings.headerTextColor){ settings.headerTextColor = paramSettings.headerTextColor; } if (paramSettings.iconBackgroundColor){ settings.iconBackgroundColor = paramSettings.iconBackgroundColor; } if (paramSettings.iconTextColor){ settings.iconTextColor = paramSettings.iconTextColor; } if (paramSettings.borderColor){ settings.borderColor = paramSettings.borderColor; } if (paramSettings.minimized === true || paramSettings.minimized === false){ settings.minimized = paramSettings.minimized; } if (paramSettings.assistantName){ settings.assistantName = paramSettings.assistantName; } if (paramSettings.buttonTextColor){ settings.buttonTextColor = paramSettings.buttonTextColor; } if (paramSettings.buttonBackgroundColor){ settings.buttonBackgroundColor = paramSettings.buttonBackgroundColor; } if (paramSettings.chatHeight){ settings.chatHeight = paramSettings.chatHeight; } if (paramSettings.chatWidth){ settings.chatWidth = paramSettings.chatWidth; } if (paramSettings.nc){ settings.nc = paramSettings.nc; } if (paramSettings.urlVerSitio){ settings.urlVerSitio = paramSettings.urlVerSitio; } if (paramSettings.zindex){ settings.zindex = paramSettings.zindex; } if (paramSettings.pbottomdesktop){ settings.pbottomdesktop = paramSettings.pbottomdesktop; } if (paramSettings.prightdesktop){ settings.prightdesktop = paramSettings.prightdesktop; } if (paramSettings.pleftdesktop){ settings.pleftdesktop = paramSettings.pleftdesktop; } if (paramSettings.pbottommobile){ settings.pbottommobile = paramSettings.pbottommobile; } if (paramSettings.prightmobile){ settings.prightmobile = paramSettings.prightmobile; } if (paramSettings.pleftmobile){ settings.pleftmobile = paramSettings.pleftmobile; } if (paramSettings.mode){ settings.mode = paramSettings.mode; } } function __loadChat(urlChat, chatClientSettingsUrl, paramSettings) { __clean(); __loadSetting(chatClientSettingsUrl).then(function(response) { if (response?.data?.settingsInfo?.[0]?.settings) { settingsChat = response.data.settingsInfo[0].settings; } else { settingsChat = defaultSettings; } __adjustSettings(settingsChat, paramSettings) __loadHtml(urlChat, settingsChat); __onresize(); }).catch(function() { console.info("No se obtuvo la configuracion del chat"); __adjustSettings(defaultSettings, paramSettings) __loadHtml(urlChat, defaultSettings); __onresize(); }); } function __setStyles(style, mode){ const ncDisplay = settingsChat.nc ? 'flex' : 'none'; const positionFlotante = settingsChat.nc ? 'fixed' : 'static'; const borderRadius = settingsChat.nc ? '20px' : '0px'; const pbottom = window.innerWidth <= 768 ? settingsChat.pbottommobile :settingsChat.pbottomdesktop; const pright = window.innerWidth <= 768 ? settingsChat.prightmobile :settingsChat.prightdesktop; const pleft = window.innerWidth <= 768 ? settingsChat.pleftmobile :settingsChat.pleftdesktop; style.innerHTML = '' + '.flotante {' + ' font: 15px Verdana !important;' + ' position: ' + positionFlotante +';' + ' bottom: '+ pbottom + ';' + ' right: '+ pright + ';' + ' left: '+ pleft + ';' + ' border-radius: '+ borderRadius +';' + ' height: '+ settingsChat.chatHeight + ';' + ' width: '+ settingsChat.chatWidth + ';' + ' z-index: '+ settingsChat.zindex + ';' + ' background-color: #FFFFFF;' + ' border: 1px solid ' + settingsChat.borderColor + ';' + ' -webkit-box-shadow: 10px 10px 48px -13px rgba(0,0,0,0.75);' + ' -moz-box-shadow: 10px 10px 48px -13px rgba(0,0,0,0.75);' + ' box-shadow: 10px 10px 48px -13px rgba(0,0,0,0.75);' + '} ' + '.__chiquito { ' + ' height: 52px; ' + ' overflow-y: hidden; ' + '} '+ '.div-chico {' + ' height: 37px !important;' + '} ' + '.chat {' + ' overflow: hidden;' + '} ' + 'iframe { ' + ' background-color: transparent;' + ' border-radius: 0 0 20px 20px; ' + '} ' + '.__oculto { display: none; }' + '.__invisible { opacity: 0 !important; }' + '.necesitas-ayuda {' + ' padding: 13px 10px 10px 10px; ' + ' border-bottom: 1px solid #FFFFFF; ' + ' border-radius: 20px 20px 0 0; ' + ' background-color: ' + settingsChat.headerBackgroundColor + ';' + ' display: '+ ncDisplay+ '; ' + ' flex-direction: row; ' + ' justify-content: space-between; ' + '} ' + '.flotante-chico { ' + ' width: 50px; !importante' + '} ' + '.boton-minimizar {'+ ' height: 40px; '+ ' padding: 0 10px; ' + ' font-size: 2rem !important; '+ ' background-color: transparent; ' + ' color: ' + settingsChat.headerTextColor + ';' + ' border: 0; ' + ' transition: 0.5s; ' + ' border-radius: 10px; ' + ' cursor: pointer; ' + ' text-align: center; ' + '} '+ '.titulo { ' + ' width: 230px; ' + ' padding-top: 8px; ' + ' color: ' + settingsChat.headerTextColor + ';' + '} ' + '.botonera { ' + ' text-align: right; ' + ' width: 70px; ' + ' margin-top: -4px;' + '} ' + '__imagen-chat { ' + ' cursor: pointer; ' + '} ' + '.necesitas-ayuda.__necesitas-ayuda-chico { ' + ' background-color: ' + settingsChat.iconBackgroundColor + ';' + '} ' + '.svg-color-icon { ' + ' color: ' + settingsChat.iconTextColor + ';' + '} '; const mobilecss = '.flotante {' + ' position: ' + positionFlotante +';' + ' bottom: '+ pbottom + ';' + ' right: '+ pright + ';' + ' left: '+ pleft + ';' + ' width: inherit;' + ' height: 100%;' + ' max-height: 500px; ' + '} ' + '.__chiquito { ' + ' width: 50px; ' + ' left: '+ pleft + ';' + ' height: 52px; ' + ' z-index: '+ settingsChat.zindex + ';' + ' overflow-y: hidden; ' + '} '; if (mode && mode ==='mobile'){ style.innerHTML = style.innerHTML + mobilecss; } else { style.innerHTML = style.innerHTML + ' @media (max-width: 768px) {' + mobilecss + ' } '; } } function __loadHtml(url, settingsChat) { __isChatVisible = true; this.console.log("Generando iframe") var iframe = document.createElement('iframe'); iframe.src = url; iframe.id = '__chatguru'; iframe.classList = 'chat' iframe.style.display = 'block'; iframe.style.margin = '0 auto'; iframe.style.padding = '0'; iframe.style.border = '0 none'; iframe.style.height = '100%'; iframe.style.width = '100%'; iframe.frameBorder = "0"; iframe.scrolling = "no"; iframe.style.allowtransparency = "true"; var style = document.createElement('style'); style.type = 'text/css'; __setStyles(style, settingsChat.mode); document.getElementsByTagName('head')[0].appendChild(style); mystyle = style; var cabecera = document.createElement('div') cabecera.id = 'pguruchatid'; cabecera.classList = 'necesitas-ayuda'; cabecera.innerHTML = '