Chatbot
Advanced
Using onReady and onError events

Chatbot - Using the onReady and onError event callbacks

How it works

When the DOM element is registered on the page, the Chatbot will make an initial request to the Aidbase API to fetch the configuration for the Chatbot.

When the configuration is fetched and validated, the Chatbot will be ready to use.
The onReady() callback will be called immediately after the Chatbot is ready.

If the Chatbot encounters an error during the process described above, the onError() callback will be called.

HTML
<ab-chat
  id='my-chatbot'
  chatbotID='YOUR-CHATBOT-ID'
  // ...additional attributes
></ab-chat>
ℹ️

If you don't manually add the <ab-chat> element, it will be added automatically.
It will have an id "ab-chat" which you can use to query the DOM node:
<ab-chat id="ab-chat"></ab-chat>

Example

JavaScript
// Get the DOM node of the Chatbot
const chatbot = document.getElementById('my-chatbot');
 
// Set the onReady callback
chatbot.onReady = () => {
  console.log('Chatbot is ready!');
};
 
// Set the onError callback
chatbot.onError = (error) => {
  console.error('Something went wrong: ' + error);
};