TAU Widget
JavaScript API
Control the TAU Widget programmatically via window.myChatbot.
JavaScript API
After the widget loads, all methods are available on window.myChatbot.
Basic control
openChat()
Opens the chat window.
window.myChatbot.openChat();closeChat()
Closes the chat window.
window.myChatbot.closeChat();toggleChatHome()
Toggles between open and closed.
window.myChatbot.toggleChatHome();isChatOpen — property
Indicates whether the chat is open.
if (window.myChatbot.isChatOpen) {
console.log('Chat is open');
}openChatWithMessage(message)
Opens the chat with a pre-filled message.
window.myChatbot.openChatWithMessage('I need help with my order');Real-time configuration
updateConfig(newConfig)
Updates the widget configuration without reloading.
window.myChatbot.updateConfig({
chatbotButtonBackground: '#FF5722',
defaultMessage: 'New default message',
enableWhatsApp: true
});config — property
Reads the current configuration.
console.log(window.myChatbot.config);
// Check a specific parameter
if (window.myChatbot.config.enableWhatsApp) {
console.log('WhatsApp mode active');
}Lifecycle
reloadWidget()
Fully reloads the widget with the current configuration. Useful after major changes.
window.myChatbot.updateConfig({ mode: 'cool' });
window.myChatbot.reloadWidget();destroy()
Completely removes the widget and cleans up resources.
window.myChatbot.destroy();updateChatbotButtonVisibility()
Updates button visibility after changing showChatbotButton.
window.myChatbot.config.showChatbotButton = false;
window.myChatbot.updateChatbotButtonVisibility();dismissChatbotTextCallout()
Removes the text bubble near the button.
window.myChatbot.dismissChatbotTextCallout();Practical examples
Contextual chat by page
function setupContextualChat() {
const path = window.location.pathname;
if (path.includes('/products/')) {
window.myChatbot.updateConfig({
defaultMessage: 'I have questions about this product'
});
} else if (path.includes('/checkout/')) {
window.myChatbot.updateConfig({
defaultMessage: 'I am having trouble at checkout',
enableWhatsApp: true
});
}
}
// Run when the widget is ready
window.addEventListener('message', function(event) {
if (event.origin !== 'https://app.taubot.ai') return;
if (event.data.type === 'Loaded app') {
setupContextualChat();
}
});Event-based control
window.addEventListener('message', function(event) {
if (event.origin !== 'https://app.taubot.ai') return;
switch (event.data.type) {
case 'Opened chat window':
// Chat opened — update analytics
gtag('event', 'chat_opened');
break;
case 'conversion':
// Conversion — change button to green
window.myChatbot.updateConfig({
chatbotButtonBackground: '#00C853'
});
break;
case 'Sent message':
// Message sent — notify team
notifySupport();
break;
}
});Custom CTA button
document.querySelector('#btn-talk-to-support')
.addEventListener('click', function() {
window.myChatbot.openChatWithMessage('I need to speak with an agent');
});