Skip to main content

Methods

JS API 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. Here’s the list of available methods:

Maximize

It maximizes the Chat Widget. Example
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.

Minimize

It minimizes the Chat Widget. Example

Hide

It hides the Chat Widget on the site. You will need to use either ‘maximize’, or ‘minimize’ API calls to show it afterwards. Example

Destroy

It destroys the Chat Widget. It won’t be available for further actions until the window is refreshed. Example

Hide greeting

It 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. Example

Trigger sales tracker

It 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. Example
Payload

Ecommerce

Available ecommerce methods:

Track sales event

Sends an ecommerce event. Cart and order events appear in the agent’s Inbox in real time. Order events also feed the All Sales and AI Agent Sales reports. Data syncs once a day, so orders appear in the reports the following day. Example
Payload

store_order_was_created

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

store_product_added_to_cart

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

store_product_removed_from_cart

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

Getters

You can use getters to fetch the data from the Chat Widget. Available getters:

Get state

It returns the Chat Widget state. This includes Widget visibility and license availability. Example
Response

Get customer data

It returns a filtered list of customer data. Example
Response

Get chat data

It returns chat data which contains current chat and thread ids. Example
Response

Setters

Various data can be sent over to the Text integration so that your agents can use it. For more information, you can read these articles in our Help Center: https://www.text.com/help/custom-variables-configuration/. Available setters:

Set session variables

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

Update session variables

It 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. Example

Set customer name

It sets the customer’s name. Example

Set customer email

It sets the customer’s email address. Example

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. Available callbacks:

On ready

The Chat Widget has finished loading. If the Chat Widget is already loaded the provided handler function will be called immediately. With this callback, you will receive the Chat Widget state and customer data as if requested by their getters. Payload

On availability changed

Availability has changed for the current group. Payload

On visibility changed

It is called once the visibility of the Chat Widget has changed. 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

It is called once the status of your customer has changed. 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 new event

It is called for both incoming and outgoing events. Payload

On form submitted

It is called after a form has been submitted in the chat. Payload

On rating submitted

It is called after the customer has rated the chat, or cancelled the previous rating. Payload

On greeting displayed

It is called after the greeting has been displayed to the customer. Payload

On greeting hidden

It is called after the greeting has been cancelled by the customer or hide_greeting method. Payload

On rich message button clicked

It is called after the rich message button has been clicked by the customer. Payload