Web Chat API
Overview
The Quidget Web Chat provides a simple JavaScript API that allows you to control the chat widget programmatically from your website.
Prerequisites
Before using the API, ensure that the Quidget Web Chat is fully installed and initialized on your page. The chat widget must be properly loaded and ready to function.
Available Methods
Method | Description |
---|---|
showChat() | Opens the chat widget, making it visible to users |
hideChat() | Closes the chat widget, hiding it from users |
startChat() | Opens the chat and skips the home screen if it exists |
window.quidget.api.showChat()
Description: Opens the chat widget, making it visible to users. This method is equivalent to clicking the chat button.
Usage: Call this method when you want to display the chat interface to your users.
window.quidget.api.hideChat()
Description: Closes the chat widget, hiding it from users. This method is equivalent to clicking the close button on the chat interface.
Usage: Call this method when you want to hide the chat interface from your users.
window.quidget.api.startChat()
Description: A comprehensive method that not only opens the chat but also skips the home screen if it exists. This is the most common method for initiating a chat conversation.
Usage: Use this method when you want to directly start a chat conversation, bypassing any welcome or home screen content.
Implementation Examples
Add a button to your page that opens the chat when clicked:
<button onclick="window.quidget.api.startChat()">OPEN CHAT</button>
Custom Event Integration
Trigger the chat based on user interactions:
// Open chat when user scrolls page
window.addEventListener('scroll', function() {
if (your_condition) {
window.quidget.api.startChat();
}
});
Error Handling
If the chat widget is not properly initialized, API calls may not work as expected. Always ensure the chat is fully loaded before attempting to use these methods.
// Check if chat is available before using
if (window?.quidget?.api) {
window.quidget.api.startChat();
} else {
console.warn('Quidget Chat is not yet loaded');
}