Skip to main content
The Chat Widget JavaScript API is grouped by how you interact with the widget. Interactions, ecommerce methods, and setters run through LiveChatWidget.call(). Getters read data with LiveChatWidget.get(), and callbacks subscribe to widget events with LiveChatWidget.on().

Available methods

Interactions

JavaScript API interaction methods allow you to create custom ways to interact with a widget. For example, you can hide your widget based on specific conditions or trigger a sales tracker defined earlier in Text. You can also run the maximize, minimize, and send_message actions with HTML attributes.

Maximize

Maximizes the chat widget.
To maximize the chat widget and pre-fill the chat input field with a predefined message, you can use the optional messageDraft param.
This method maximizes the chat widget and automatically inserts “I need help!” into the chat input field. If a pre-chat form is enabled, it instead creates a message draft that is sent when the form is submitted. The action will have no effect if the widget’s current state prevents message entry or if the user already has a message draft. To maximize the chat widget and start a new chat right away, use the optional startChat param.
The chat starts without any customer input. The param has no effect if a chat is already active or if a pre-chat form is enabled. You can combine it with messageDraft.
Payload

Send message

Sends a message on the customer’s behalf and maximizes the chat widget. Use it to turn an element on your page, such as a suggested question, into a message the customer sends with one click.
The call is ignored when text is empty, or when the group is offline and continuous chats are turned off. If a pre-chat form is enabled, the message becomes a draft and is sent once the form is submitted. Payload

Minimize

Minimizes the chat widget.

Hide

Hides the chat widget on the site. You will need to use either ‘maximize’, or ‘minimize’ API calls to show it afterwards.

Destroy

Destroys the chat widget. It won’t be available for further actions until the window is refreshed.

Hide greeting

Hides the currently displayed greeting. In order to hide particular greeting you can listen to new_event or greeting_hidden callbacks to know when greeting with specified id or uniqueId appears and disappears accordingly.

Trigger sales tracker

Triggers a sales tracker created in Text and passes over data about a sale. The data is then visible in Text’s Reports and Archives. For more information about how Sales Tracker works and how to set it up on your website, check out our official Help Center article: How Sales Tracker works in practice.
Payload

Ecommerce

Ecommerce methods send cart and order data from your store to Text.

Track sales event

Sends an ecommerce event. For active chats, cart and order events appear in the agent’s Inbox in real time. Order events also feed the All Sales, AI Agent Sales, and Sales conversion reports. In reports, data syncs once an hour.
Payload

store_order_was_created

Use on your order confirmation page after a purchase is completed.
Data

store_product_added_to_cart

Use when a customer adds an item to the cart.
Data

store_product_removed_from_cart

Use when a customer removes an item from the cart.
Data

Set customer cart

Sends the customer’s cart to the chat widget so agents can see it in the Inbox in real time. Call the method whenever the cart changes. There is no separate action to clear the cart. To clear it, call the method with an empty items array.
To clear the cart, call the method with an empty items array:
Send all amounts as integers in the cart currency’s minor unit. For example, send 14999 for USD 149.99. The currency value determines how the amounts are interpreted. Don’t send non-integer numbers or strings. Payload Items

Getters

You can use getters to fetch the data from the chat widget.

Get state

Returns the chat widget state. This includes Widget visibility and license availability.
Response

Get customer data

Returns a filtered list of customer data.
Response

Get chat data

Returns the chat data, which contains the current chat and thread IDs.
Response

Setters

Various data can be sent over to the Text integration so that your agents can use it.

Set session variables

Creates new session variables, or replaces the ones set previously.

Update session variables

Changes the values of your session variables. Note that existing variables won’t be replaced. The new session variables will be included together with the ones set previously.

Set customer name

Sets the customer’s name.

Set customer email

Sets the customer’s email address.

Set customer phone number

Sets the customer’s phone number.

Callbacks

Callbacks allow you to react to the events triggered by the chat widget. You can use them to add custom behaviors when certain events happen. This can be accomplished by subscribing a callback with the API.

On ready

Runs when the chat widget has finished loading. If the chat widget is already loaded, the provided handler function runs immediately. With this callback, you will receive the chat widget state and customer data as if requested by their getters. Payload

On availability changed

Runs when availability changes for the current group. Payload

On visibility changed

Runs when the chat widget visibility changes. This applies to both user actions like maximizing or minimizing the window as well as hiding or showing the chat widget through the use of this API. Payload

On customer status changed

Runs when the customer’s status changes. This can be used to track the following info:
  • If and when Customers are being invited to chat
  • If Customers are already chatting
  • If they are waiting for an agent to become available in the queue
Payload

On customer data changed

Runs every time the customer data changes. The payload matches the Get customer data response.

On new event

Runs for both incoming and outgoing events. Payload

On form submitted

Runs after the customer submits a form in the chat. Payload

On rating submitted

Runs after the customer rates the chat or cancels the previous rating. Payload

On greeting displayed

Runs after the chat widget displays the greeting to the customer. Payload

On greeting hidden

Runs after the customer or the hide_greeting method cancels the greeting. Payload

On rich message button clicked

Runs after the customer clicks the rich message button. Payload