# Javascript API: Methods

Tiledesk provides a Tiledesk JavaScript object that responds to a few methods. These allow you to update widget without a page refresh and interact with the messenger window.

## Open the widget

This will open the widget:

```javascript
window.Tiledesk('open');
```

## Minimize the widget

This will minimize the widget:

```javascript
window.Tiledesk('close');
```

## Hide the widget

This will hide the widget:

```javascript
window.Tiledesk('hide');
```

## Show the widget

This will show the widget:

```javascript
window.Tiledesk('show');
```

## Dispose the widget

This will clear the widget html elements from the DOM:

```javascript
window.Tiledesk('dispose');
```

## Reinitialize the widget

If your app is characterized by very few page refreshes (ie., content is swapped out on the client side but no page refresh happens, Angular, React, jQuery, etc..) and lots of asynchronous JS, you'll need to update Tiledesk when your user's data changes. A reInit call simulates a page refresh, causing Tiledesk to reload the widget and all the configurations.

```javascript
window.Tiledesk('reInit');
```

## Restart the widget

This method allow you to restart widget with the same user's data without make a new authentication. This also mantein all the configurations.

```javascript
window.Tiledesk('restart');
```

## Signin with anonymously

This method make a signin anonymously

```javascript
window.Tiledesk('signInAnonymous');
```

## Signin with JWT Custom Token

This method make a signin using a JWT Custom Token as described [here](https://developer.tiledesk.com/widget/auth).

```javascript
window.Tiledesk('signInWithCustomToken', customJwt);
```

## Make a logout

This will logout the widget:

```javascript
window.Tiledesk('logout');
```

## Show callout

This will show the widget callout if it is not open:

```javascript
window.Tiledesk('showCallout');
```

## Show or hide the PreChatForm

This parameter configures the PreChatForm visibility:

```javascript
window.Tiledesk('setPreChatForm', true|false);
```

## Set custom PreChatForm Json

This method allow you to customize preChatFormJson property, and change preChatForm structure if preChatForm is still active (ensure preChatForm value is set to true, otherwize use window\.Tiledesk('setPreChatForm', true) method before call setPreChatFormJson ). This method accept an Array (see [docs](https://developer.tiledesk.com/widget/advanced/prechat-form-json) for more detail about customize it):

```javascript
window.Tiledesk('setPreChatFormJson', customFormArray);
```

## Get custom PreChatForm Json

This method allow you to get current preChatForm Json array used in the preChatForm component when is active (check preChatForm value is set to true):

```javascript
window.Tiledesk('setPreChatFormJson', customFormArray);
```

## Set new value to Widget parameter

You can change a value to the Tiledesk Widget parameter. Pass an object in the form of key/value, where key represent che name of the property you want to modify, and value is the new value you want to set:

```javascript
window.Tiledesk('setParameter', {key: string, value: string});
```

## Set new value to Widget attribute parameter

You can change a value to the Tiledesk Widget attribute parameter. Pass an object in the form of key/value, where key represent che name of the property you want to modify, and value is the new value you want to set:

```javascript
window.Tiledesk('setAttributeParameter', {key: string, value: string});
```

## Start a new conversation

You can programatically start a new conversation:

```javascript
window.Tiledesk('startConversation');
```

## Open a conversation from a specif ID

You can programatically open an already existing conversation by id in the form of *'support-group-'+\<project\_id>+'-'+uuid*

```javascript
window.Tiledesk('openConversationById', conversation_id);
```

## Clear site data

You can programatically clear saved session data :

```javascript
window.Tiledesk('clearStorage');
```
