JavaScript: open the chatbot from your own buttons and scripts
On this page
To keep your pages fast, WPBot first shows only the chat icon. The chatbot's scripts and styles load when the visitor first touches the icon (or earlier, depending on your settings). Your own code should therefore open the chat through one of the ways below, which work before and after the chat has loaded.
Open the chat from any element (no code)
Give any link, button or image the class wpbot-click-chat:
<a href="#chat" class="wpbot-click-chat">Questions? Chat with us</a>
<button type="button" class="wpbot-click-chat">Start a chat</button>
A click loads the chat if needed and opens it. It never closes an open chat, and it works even when the floating icon is hidden with Enable floating icon off. In a menu built with Appearance → Menus or the Site Editor, add wpbot-click-chat as the item's CSS class.
To open the chat at a specific intent or form, use the shortcode [wpbot-click-chat intent="…"] instead (Chatbot shortcodes).
Open the chat from JavaScript
window.qcldWpbotChatLoad( callback ) loads the chat if it is not loaded yet and calls your function once it is ready. Then click the chat button:
function openWpbotChat() {
if ( typeof window.qcldWpbotChatLoad !== 'function' ) {
return; // The chatbot is not on this page.
}
window.qcldWpbotChatLoad( function () {
if ( ! document.querySelector( '.active-chat-board' ) ) {
var ball = document.querySelector( '.wp-chatbot-ball' );
if ( ball ) {
ball.click();
}
}
} );
}
window.qcldWpbotChatLoad exists only while the chat loads on demand. If you turned on-demand loading off, the chat is already loaded and you can click .wp-chatbot-ball directly.
Run code when the chat has loaded
The launcher fires a qcld_wpbot_chat_loaded event on document once the chat's scripts have run:
document.addEventListener( 'qcld_wpbot_chat_loaded', function () {
// The chat window and its scripts are ready.
} );
When the chat loads
| Situation | When the full chat loads |
|---|---|
| Normal pages | On the first interaction with the chat icon (pointing at it, touching it, focusing it or clicking it) |
| A setting needs the chat early (for example auto-open or proactive greetings) | When the browser is idle |
| Pages with a chat shortcode in their content | With the page |
| WPBot Pro's Load chat engine set to When idle or On first interaction | As chosen in ChatBot → Performance |
To load the full chat with every page instead, turn on-demand loading off with one of:
define( 'WPBOT_LAZY_WIDGET_DISABLE', true );inwp-config.phpadd_filter( 'qcld_wpbot_chat/lazy_widget', '__return_false' );
Do this only if a script of yours needs the chat's own scripts on every page: it makes pages heavier.
Keyboard
On the front end, Ctrl + B opens and closes the chat window and Esc closes it. Enter or Space on the chat icon opens the chat and moves the keyboard focus into it.
Site Insight events
If Site Insight records the page, you can add your own events and tags to the visit with qcInsights.event( name, data ) and qcInsights.tag( key, value ). See AI Marketing, Site Insight and asset cache hooks.
Availability
The wpbot-click-chat class, qcldWpbotChatLoad() and the loaded event work in every edition, including WPBot Free. The Ctrl + B shortcut and the Load chat engine setting come with every WPBot Pro edition.
Was this article helpful?
Sorry about that. Get help another way:

