Skip to main content
Version: 6.19.0

Methods and properties of API

General info

Use the global object ThreadsWidget to access methods and properties of API.

Visibility settings

The methods below are designed to manage chat visibility. For example, use them if you deploy custom methods to show/hide the chat instead of using the standard start button. To switch the chat to the mode without the standard start button, set the isContainerHidden parameter in the chat configuration to true:

"isContainerHidden": true

You can find a complete example of creating a custom button to control the visibility of the chat in the examples/Custom button folder.

Methods

SDK API ThreadsWidget.showChat()

Use this method to show the chat container.

Example
<button onclick="ThreadsWidget.showChat()">Show</button>

SDK API ThreadsWidget.hideChat()

Use this method to hide the chat container.

Example
<button onclick="ThreadsWidget.hideChat()">Hide</button>

SDK API ThreadsWidget.version()

Use this method to return the chat version.

Example
ThreadsWidget.version();

SDK API ThreadsWidget.commitHash()

Use this method to return the hash of the commit on which the chat is built.

Example
ThreadsWidget.commitHash();

SDK API ThreadsWidget.onLoad(callback)

Use this method to specify a callback function that is executed when the chat is finished loading.

Parameters

callback - function executed when the chat is finished loading

Example
ThreadsWidget.onLoad(function () {
// remove preloaders etc.
});

SDK API ThreadsWidget.on(event, callback)

Use this method to set an event handler. It is necessary to set event handlers after initializing a web chat using the ThreadsWidget.onLoad(callback) method.

Parameters
  • callback - The function that will be executed when the even occurs

  • event - The event name

    As the event name, you can set the following:

    • hideChat - This event occurs when the chat container is hidden.

    • showChat - This event occurs when the chat container is showing.

    • closeChat - This event occurs when closing the chat (from the full chat window to a chat button).

    • openChat - This event occurs when opening the chat (from the chat button into a full chat window).

    • showInviteMessage - This event occurs when a welcome message is shown.

    • hideInviteMessage - This event occurs when the welcome message is hidden.

    • changeOperationMode - This event occurs when operation mode is changed. After the event occurs, the handler will be called to which the following data will be passed:

      {
      isNowInactive: Boolean // Gets the true/false value if the event occurred when the chat became inactive/active, according to the chat mode settings.
      }
    • changeUnreadCounter - This event occurs when unread messages appear in the chat. The number of unread messages will be passed to the handler.

    • messageSent - This event occurs when the client has sent a message. The message object will be passed to the handler.

SDK API ThreadsWidget.setLocale(locale)

Use this method to change the chat locale language on the fly.

Example
ThreadsWidget.setLocale('ru');

SDK API ThreadsWidget.reInit([Object])

Use this method to reinitialize the chat. For SPA websites, the method allows you to switch the chat from the authorized mode to the unauthorized mode and vice versa without reloading the page. Object - An object where the key is the value of the webchat/clientId parameter of the settings.json configuration file, and its value is the ID of the authorized client. If you pass an empty string as a value, the chat will switch to the unauthorized mode.

Examples
  • Switching to the unauthorized mode

    ThreadsWidget.reInit({
    clientId: '',
    });
  • Switching to the authorized mode

    ThreadsWidget.reInit({
    clientId: 'h5lkdj3dxdkjdn123oxsdmvkaffqef',
    });

SDK API ThreadsWidget.clientLogout()

Log out as an authorized user. Required to stop sending push notifications to the device.

SDK API ThreadsWidget.getUnreadCounter()

Use this method to return the number of unread messages in the widget.

Example
ThreadsWidget.getUnreadCounter();

SDK API ThreadsWidget.setUnavailable([Boolean])

Use this method to manage the widget availability on the fly. edna provides processing of the business scenario when the appropriate conditions occur:

  • After getting the setUnavailable call, the widget remains visible if the client has an active thread.
  • After getting the setUnavailable call, if the client does not have an active thread, but the widget is opened, the chat remains visible, but the input field is not available.
  • All other calls hide the widget.
Example
ThreadsWidget.setUnavailable(true);