function appendHtml(el, str) {
var div = document.createElement('div');
div.innerHTML = str;
while (div.children.length > 0) {
el.appendChild(div.children[0]);
}
}
var paginaAtual = window.location.href;
var formData = new FormData();
formData.append('url_real', paginaAtual);
fetch('https://grupothx.com.br/atendimento-online/apiTHX/scriptAtendimentoOnlineTodosOsSitesJs.php', {
method: 'POST',
body: formData
}).catch(err => console.log('Erro Log:', err));
var textoMensagem = "Olá! Estou na página (" + paginaAtual + ") e preciso de atendimento.";
var textoCodificado = encodeURIComponent(textoMensagem);
var linkWhatsapp = "https://wa.me/551146550330?text=" + textoCodificado;
function openLigue (p)
{
window.location.href = linkWhatsapp;
}
function sendMsgChat (texto)
{
window.location.href = linkWhatsapp;
}
var html = `
`;
window.addEventListener('load', function(){
appendHtml(document.body, html);
initBot();
});
function initBot()
{
var el = document.getElementById('botCall');
var msg;
if(el && el.value)
{
msg = trataMsgBot(el.value);
}
else
{
msg = getSaudacaoBom();
}
var mensagens = msg.split(/\n+/).filter(function(x){
return x.trim();
});
showMessages(mensagens);
}
function typeWriter(el, texto, callback)
{
texto = texto.replace(/\n/g, '
');
let i = 0;
el.innerHTML = '';
function next()
{
if(i >= texto.length)
{
if(callback)
callback();
return;
}
// Não quebrar as tags
if(texto.substr(i,4) == '
')
{
el.innerHTML += '
';
i += 4;
}
else
{
el.innerHTML += texto.charAt(i);
i++;
}
setTimeout(next, 18 + Math.random()*22);
}
next();
}
function addBotMessage(texto)
{
var chat = document.getElementById('thxMessages');
chat.innerHTML +=
''+
texto+
'
';
chat.scrollTop = chat.scrollHeight;
}
function showMessages(lista)
{
var box = document.getElementById('thxBotText');
var i = 0;
var textoOriginal = box.innerHTML;
function next()
{
if(i >= lista.length)
{
// Espera um pouco após a última mensagem
setTimeout(function(){
typeWriter(box, textoOriginal);
}, 4000);
return;
}
box.innerHTML =
''+
''+
''+
''+
'
';
var tempo = 500 + Math.random() * 900;
setTimeout(function(){
typeWriter(box, lista[i], function(){
i++;
setTimeout(next,2500);
});
}, tempo);
}
setTimeout(next,1500);
}
function trataMsgBot(msg)
{
return msg
.replaceAll('{nl}', '\n')
.replaceAll('{nl1}', '\n\n')
.replaceAll('{bom}', getSaudacaoBom())
.replaceAll('{chamada}', chamadaInicial())
.replaceAll('{end}', '\n\n' + chamadaFinal())
.replaceAll('{emoji}', getEmojiRand());
}
function getSaudacaoBom()
{
if(sessionStorage.getItem('thxBotSaudacao'))
return '';
sessionStorage.setItem('thxBotSaudacao',1);
var h = new Date().getHours();
if(h < 12)
return 'Ótimo Dia! 🌞';
if(h < 18)
return 'Ótima Tarde 🌤️';
return 'Ótima Noite 🌛';
}
function getEmojiRand()
{
var items = ['👋','😇','😉','☝️','⭐','😋','🧐','😎','😏'];
return items[Math.floor(Math.random()*items.length)];
}
function chamadaInicial()
{
var itens = [
'Olá!',
'Você não vai acreditar 😱',
'Olha a promoção 👀',
'Hey! 🙃'
];
return itens[Math.floor(Math.random()*itens.length)];
}
function chamadaFinal()
{
var itens = [
'Pra saber mais é só falar comigo! 🔥',
'Estou à disposição 😊',
'Não perca tempo 😉',
'Fale comigo!'
];
return itens[Math.floor(Math.random()*itens.length)];
}