TAU Widget

API JavaScript

Controle o TAU Widget programaticamente via window.myChatbot.

API JavaScript

Após o carregamento do widget, todos os métodos ficam disponíveis em window.myChatbot.


Controle básico

openChat()

Abre a janela do chat.

window.myChatbot.openChat();

closeChat()

Fecha a janela do chat.

window.myChatbot.closeChat();

toggleChatHome()

Alterna entre aberto e fechado.

window.myChatbot.toggleChatHome();

isChatOpen — propriedade

Indica se o chat está aberto.

if (window.myChatbot.isChatOpen) {
  console.log('Chat está aberto');
}

openChatWithMessage(message)

Abre o chat com uma mensagem pré-preenchida.

window.myChatbot.openChatWithMessage('Preciso de ajuda com meu pedido');

Configuração em tempo real

updateConfig(newConfig)

Atualiza a configuração do widget sem recarregar.

window.myChatbot.updateConfig({
  chatbotButtonBackground: '#FF5722',
  defaultMessage: 'Nova mensagem padrão',
  enableWhatsApp: true
});

config — propriedade

Lê a configuração atual.

console.log(window.myChatbot.config);

// Verificar parâmetro específico
if (window.myChatbot.config.enableWhatsApp) {
  console.log('Modo WhatsApp ativo');
}

Ciclo de vida

reloadWidget()

Recarrega completamente o widget com a configuração atual. Útil após grandes mudanças.

window.myChatbot.updateConfig({ mode: 'cool' });
window.myChatbot.reloadWidget();

destroy()

Remove completamente o widget e limpa recursos.

window.myChatbot.destroy();

updateChatbotButtonVisibility()

Atualiza a visibilidade do botão após alterar showChatbotButton.

window.myChatbot.config.showChatbotButton = false;
window.myChatbot.updateChatbotButtonVisibility();

dismissChatbotTextCallout()

Remove o balão de texto próximo ao botão.

window.myChatbot.dismissChatbotTextCallout();

Exemplos práticos

Chat contextual por página

function setupContextualChat() {
  const path = window.location.pathname;

  if (path.includes('/produtos/')) {
    window.myChatbot.updateConfig({
      defaultMessage: 'Tenho dúvidas sobre este produto'
    });
  } else if (path.includes('/checkout/')) {
    window.myChatbot.updateConfig({
      defaultMessage: 'Estou com problemas no checkout',
      enableWhatsApp: true
    });
  }
}

// Executar quando o widget estiver pronto
window.addEventListener('message', function(event) {
  if (event.origin !== 'https://app.taubot.ai') return;
  if (event.data.type === 'Loaded app') {
    setupContextualChat();
  }
});

Controle baseado em eventos

window.addEventListener('message', function(event) {
  if (event.origin !== 'https://app.taubot.ai') return;

  switch (event.data.type) {
    case 'Opened chat window':
      // Chat foi aberto — atualizar analytics
      gtag('event', 'chat_opened');
      break;

    case 'conversion':
      // Conversão — mudar botão para verde
      window.myChatbot.updateConfig({
        chatbotButtonBackground: '#00C853'
      });
      break;

    case 'Sent message':
      // Mensagem enviada — notificar equipe
      notifySupport();
      break;
  }
});

Botão CTA personalizado

document.querySelector('#btn-falar-com-suporte')
  .addEventListener('click', function() {
    window.myChatbot.openChatWithMessage('Preciso falar com um atendente');
  });

On this page