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. ExampleMinimize
It minimizes the Chat Widget. ExampleHide
It hides the Chat Widget on the site. You will need to use either ‘maximize’, or ‘minimize’ API calls to show it afterwards. ExampleDestroy
It destroys the Chat Widget. It won’t be available for further actions until the window is refreshed. ExampleHide greeting
It hides the currently displayed greeting. In order to hide particular greeting you can listen tonew_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. ExampleEcommerce
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. Examplestore_order_was_created
Use on your order confirmation page after a purchase is completed.
Example
store_product_added_to_cart
Use when a customer adds an item to the cart.
Example
store_product_removed_from_cart
Use when a customer removes an item from the cart.
Example
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. ExampleGet customer data
It returns a filtered list of customer data. ExampleGet chat data
It returns chat data which contains current chat and thread ids. ExampleSetters
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. ExampleSet customer name
It sets the customer’s name. ExampleSet customer email
It sets the customer’s email address. ExampleCallbacks
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
- On availability changed
- On visibility changed
- On customer status changed
- On new event
- On form submitted
- On rating submitted
- On greeting displayed
- On greeting hidden
- On rich message button clicked
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. PayloadOn availability changed
Availability has changed for the current group. PayloadOn 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. PayloadOn 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
On new event
It is called for both incoming and outgoing events. Payload- General
- Greeting
On form submitted
It is called after a form has been submitted in the chat. PayloadOn rating submitted
It is called after the customer has rated the chat, or cancelled the previous rating. PayloadOn greeting displayed
It is called after the greeting has been displayed to the customer. PayloadOn greeting hidden
It is called after the greeting has been cancelled by the customer orhide_greeting method.
Payload