About the API
The Chat Widget JavaScript API lets you interact with the chat widget embedded on your site. It might come in handy whenever you want to gather some additional data using Text, show or hide your chat widget on certain occasions, or amend its behavior in a way that is not provided by the standard settings. This document focuses on Developers and requires a basic knowledge of JavaScript. However, if you would have any questions, don’t hesitate to start a chat with our Support Team or add a new topic on our Discord for Developers.Getting started
The API is accessed through theLiveChatWidget object. It’s being initialized within the widget code, which is used to install our chat widget on your site.
If you haven’t installed the code yet, you can either find it directly in the app or copy it from below. Remember to replace <ORGANIZATION_ID> with your organization ID.
Text widget code
LiveChatWidget object comes with four functions:
onregisters a callback function for a specific eventoncesimilar toonbut after single event trigger the callback is removedoffremoves a callback registered byoncallallows you to invoke methods and settersgetmakes it possible to fetch data
John Doe, this is how it would look like:
Asynchronous Initialization
Asynchronous initialization is an optional feature available for chat widget via JavaScript API. It allows for far more control over the moment when the chat widget should be loaded. It can be especially useful if you would like to make widget initialization happen as a consequence of some user interaction, or your own application business logic event. This feature is disabled by default, so the chat widget loads automatically just after the snippet code is executed. In order to enable it, you need to explicitly set__lc.asyncInit property to true.
LiveChatWidget object, the widget itself will not be present on your website and the ready callback will not be triggered.
Later in your code you can initialize chat widget manually when needed.
To do that simply call init function from LiveChatWidget object.