# Methods

## 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.

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

*see more init options in the* [*attributes*](https://developers.chathive.app/sdk/attributes#widget-init-attributes) *section.*

### Chathive.widget.embed

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

<pre class="language-typescript"><code class="lang-typescript">Chathive.widget.embed({
    apiKey: "YOUR_API_KEY",
<strong>    selector: "YOUR_HTML_TAG",
</strong>    // Optional attributes
    language: "en",
    hide: false,
}) 
</code></pre>

*see more init options in the* [*attributes*](https://developers.chathive.app/sdk/attributes#widget-embed-attributes) *section.*

### Chathive.widget.isWidgetLoaded

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

```typescript
Chathive.widget.isWidgetLoaded();
```

### Chathive.widget.open

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

```typescript
Chathive.widget.open();
```

&#x20;If you want to keep the widget hidden, set show attribute to false.&#x20;

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

### Chathive.widget.close

This will close the widget and keep the trigger visible.

```typescript
Chathive.widget.close();
```

If you also want to hide the widget set hide attribute to true.&#x20;

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

### Chathive.widget.hide

Hide the widget from your website

```typescript
Chathive.widget.hide();
```

### Chathive.widget.isHidden

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

```typescript
Chathive.widget.isHidden();
```

### Chathive.widget.show

Show the widget on your website

```typescript
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.

```typescript
Chathive.widget.destroy();
```

## Messages

### Chathive.widget.sendMessage

Send a message as the website visitor.

```typescript
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

```typescript
Chathive.widget.getCurrentLanguage();
```

### Chathive.widget.setLanguage

Set or change the language of the widget. We support all [ISO 639-1 language codes](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).

```typescript
Chathive.widget.setLanguage("nl");
```

## Text <a href="#text" id="text"></a>

Most static text that you see in the form can be customised

#### getText <a href="#gettext" id="gettext"></a>

Get the text configuration that has been set

```
Chathive.widget.getText();
```

#### setText <a href="#settext" id="settext"></a>

Set or change the text of your interface. *More info about* [*text configuration*](https://developers.chathive.app/sdk/ai-form/configuration#text-customization)

```
Chathive.widget.setText(TextObject);
```

## Settings

### isFileUploadAllowed

Check if file upload has been allowed

```javascript
Chathive.widget.getIsFileUploadAllowed()
```

### setIsFileUploadAllowed

Change if customers are allowed to upload files into the conversation. Will only work if file upload has been enabled in the project.

```javascript
Chathive.widget.setIsFileUploadAllowed(allowed: boolean);
```

## Timezone

Customize the timezone for your conversation. By default, the project's timezone will be used.

### getTimezone

Returns the current timezone

```typescript
Chathive.widget.getTimezone();
```

### setTimezone

Set or update timezone for the current form interface.

```typescript
Chathive.widget.setTimezone("Europe/Brussel");
```

## Notifications

### Chathive.widget.disableNotifications

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

```typescript
Chathive.widget.disableNotifications();
```

### Chathive.widget.enableNotifications

Allow notifications to be shown when widget is closed.

```typescript
Chathive.widget.enableNotifications();
```

## Context

### Chathive.widget.getContext

Get the current context of the conversation

```typescript
Chathive.widget.getContext();
```

### Chathive.widget.setContextField

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

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

## Customer data

### Chathive.widget.getCustomerData

Get the data from the current customer

```typescript
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

```typescript
Chathive.widget.updateCustomerData(CustomerData| undefined);
```

*More info about* [*customerData*](https://developers.chathive.app/attributes#customer-data)
