Skip to main content

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 the LiveChatWidget 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
The LiveChatWidget object comes with four functions:
  • on registers a callback function for a specific event
  • once similar to on but after single event trigger the callback is removed
  • off removes a callback registered by on
  • call allows you to invoke methods and setters
  • get makes it possible to fetch data
The usage of these functions is based on passing the correct arguments in the following pattern:
For example, if you would like to set your customer’s name to 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.
From now on the snippet code will be executed but the chat widget and its resources will not be loaded. It means that although you will have access to 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.