Methods

The Chathive JavaScript SDK provides an JavaScript object with a few methods. These allow you to interact with the widget and customize it's behaviour

Widget

Chathive.widget.init

The primairy use-case of the SDK is to show the Chathive widget on your website. This can be done by calling the init method. By default we will immediately show the widget trigger on your website if you don't want this you can provide the hide attribute to hide the widget by default.

Chathive.widget.init({
    apiKey: "YOUR_API_KEY",
    // Optional attributes
    language: "en",
    hide: false,
    config: { notificationsEnabled: true }
}) 

see more init options in the attributes section.

Chathive.widget.embed

Instead of showing a widget on your screen, this method will embed your widget into your app.

Chathive.widget.embed({
    apiKey: "YOUR_API_KEY",
    selector: "YOUR_HTML_TAG",
    // Optional attributes
    language: "en",
    hide: false,
    config: { notificationsEnabled: true }
}) 

see more init options in the attributes section.

Chathive.widget.isWidgetLoaded

Check if the widget has been initialised and is ready to be used. This will return a boolean

Chathive.widget.isWidgetLoaded();

Chathive.widget.open

This will open the widget, if the widget was hidden it will be shown.

Chathive.widget.open();

If you want to keep the widget hidden, set show attribute to false.

Chathive.widget.open({ show: false });

Chathive.widget.close

This will close the widget and keep the trigger visible.

Chathive.widget.close();

If you also want to hide the widget set hide attribute to true.

Chathive.widget.open({ hide: true });

Chathive.widget.hide

Hide the widget from your website

Chathive.widget.hide();

Chathive.widget.isHidden

Check if the widget is hidden. This will return a boolean

Chathive.widget.isHidden();

Chathive.widget.show

Show the widget on your website

Chathive.widget.show();

Chathive.widget.destroy

Remove the widget from your website. f you want to re-enable the widget you need to recall the init method.

Chathive.widget.destroy();

Messages

Chathive.widget.sendMessage

Send a message as the website visitor.

Chathive.widget.sendMessage("YOUR MESSAGE");

Language

Chathive.widget.getCurrentLanguage

Get the current language that is used in the widget. By default we will use the language that is marked as default in your dashboard

Chathive.widget.getCurrentLanguage();

Chathive.widget.setLanguage

Set or change the language of the widget. We support all ISO 639-1 language codes.

Chathive.widget.setLanguage("nl");

Notifications

Chathive.widget.disableNotifications

Don't get notifications when the widget is closed. Is usefull on mobile devices

Chathive.widget.disableNotifications();

Chathive.widget.enableNotifications

Allow notifications to be shown when widget is closed.

Chathive.widget.enableNotifications();

Context

Chathive.widget.getContext

Get the current context of the conversation

Chathive.widget.getContext();

Chathive.widget.setContextFields

Context is currently a experimental feature and is only used by the agent for a select group of beta user.

Set or update a new key in the conversation context. If you set a value to undefined this key will be removed from the context

Chathive.widget.setContextFields({
    key: string;
    value: Boolean | number | string | undefined,
});

Customer data

Chathive.widget.getCustomerData

Get the data from the current customer

Chathive.widget.getCustomerData();

Chathive.widget.updateCustomerData

Set or update the customer data for the current session. This will help you to identify the customer behind a conversation

Chathive.widget.updateCustomerData(CustomerData| undefined);

More info about customerData

Last updated