> ## Documentation Index
> Fetch the complete documentation index at: https://botpress.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Webchat methods reference

This page contains a reference for all methods available when [injecting Webchat](https://botpress.com/docs/webchat/get-started/quick-start.md).

***

## `open`

The `window.botpress.open` method opens the Webchat window:

```js theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
window.botpress.open();
```

It becomes available after [Webchat has been initialized](https://botpress.com/docs/webchat/interact/listen-to-events.md#webchat-is-initialized).

### Parameters

The `open` method takes no parameters.

### Returns

***

## `close`

The `window.botpress.close` method closes the Webchat window:

```js theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
window.botpress.close();
```

It becomes available after [Webchat has been initialized](https://botpress.com/docs/webchat/interact/listen-to-events.md#webchat-is-initialized).

### Parameters

The `close` method takes no parameters.

### Returns

***

## `toggle`

The `window.botpress.toggle` method toggles the Webchat window open/closed depending on its current state:

```js theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
window.botpress.toggle();
```

It becomes available after [Webchat has been initialized](https://botpress.com/docs/webchat/interact/listen-to-events.md#webchat-is-initialized).

### Parameters

The `toggle` method takes no parameters.

### Returns

***

## `updateUser`

The asynchronous `window.botpress.updateUser` method updates the data associated with the current Webchat user:

```js theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
await window.botpress.updateUser({
  name: "<string>",
  pictureUrl: "<string>",
  data: {},
  userKey: "<string>"
});
```

It becomes available after [Webchat has been initialized](https://botpress.com/docs/webchat/interact/listen-to-events.md#webchat-is-initialized).

### Parameters

**user** `User`

The user attributes to update.

**name** `string`

A name for the user.

**pictureUrl** `string`

URL pointing to a picture for the user.

**data** `object`

An object containing any additional data as key-value pairs. The values can be of any type.

**userKey** `string`

A custom key to associate with the user.

> [!NOTE]
>
> By default, the `user` object contains the following properties:
>
> **user** `User`
>
> **id** `string` *required*
>
> Unique identifier for the user.
>
> **createdAt** `string` *required*
>
> User creation timestamp in ISO 8601 format.
>
> **updatedAt** `string` *required*
>
> Last user update timestamp in ISO 8601 format.
>
> These are generated by the server and can't be updated or deleted.

### Returns

A Promise that resolves `void` when the user data has been successfully updated.

***

## `getUser`

The asynchronous `window.botpress.getUser` method gets the data associated with the current Webchat user:

```js theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
await window.botpress.getUser();
```

It becomes available after [Webchat has been initialized](https://botpress.com/docs/webchat/interact/listen-to-events.md#webchat-is-initialized).

### Parameters

The `getUser` method takes no parameters.

### Returns

A Promise that resolves when the user information has been retrieved.

**id** `string` *required*

Unique identifier for the user.

**createdAt** `string` *required*

User creation timestamp in ISO 8601 format.

**updatedAt** `string` *required*

Last user update timestamp in ISO 8601 format.

**name** `string`

A name for the user.

**pictureUrl** `string`

URL pointing to a picture for the user.

**data** `object`

An object containing any additional data as key-value pairs. The values can be of any type.

**userKey** `string`

A custom key to associate with the user.

***

## `config`

The `window.botpress.config` method updates [Webchat's configuration](https://botpress.com/docs/webchat/get-started/configure-your-webchat.md) and the current user's data.

```js theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
window.botpress.config({
  configuration: {},
  user: {}
});
```

It becomes available after [Webchat has been initialized](https://botpress.com/docs/webchat/interact/listen-to-events.md#webchat-is-initialized).

### Parameters

An object containing the Webchat configuration and user data to update.

**configuration** `object`

Webchat configuration settings to update.

**botName** `string`

Name of the bot displayed in the Webchat header.

**botAvatar** `string`

URL to the bot's avatar image.

**botDescription** `string`

Description of the bot.

**composerPlaceholder** `string`

Placeholder text for the message input field.

**color** `string`

Primary color theme for the Webchat interface as a HEX code.

**themeMode** `string`

Theme mode. Can be `light` or `dark`.

**variant** `string`

Visual variant. Can be `solid` or `soft`.

**allowFileUpload** `boolean`

Whether to enable file upload functionality.

**showPoweredBy** `boolean` *deprecated*

Whether to show "Powered by Botpress" branding.

> [!WARNING]
>
> This setting is deprecated and no longer supported. Use the [`footer`](#param-footer) field instead.

**feedbackEnabled** `boolean`

Whether to enable message feedback functionality.

**fabImage** `string`

URL to the Floating Action Button (FAB) image.

**radius** `number`

Border radius for the Webchat interface. Must be between 0.5 and 4.

**fontFamily** `string`

Custom font family for the Webchat interface. Can be one of the default fonts:

`"inter" | "rubik" | "ibm plex sans" | "fira code"`

or any [Google Font](https://fonts.google.com/).

> [!WARNING]
>
> Google Font titles are case-sensitive.

**additionalStylesheet** `string`

Custom CSS styles to apply to the Webchat interface.

**additionalStylesheetUrl** `string`

URL to an external stylesheet to load for the Webchat interface.

**storageLocation** `string`

Storage location for webchat data. Can be `localStorage` or `sessionStorage`.

**footer** `string`

Custom footer content for the Webchat interface. Set to an empty string to remove the footer.

> [!TIP]
>
> You can use Markdown to create links and stylize the footer text.

**headerVariant** `string`

Header visual variant. Can be `solid` or `glass`.

**adminKey** `string`

Admin key for enhanced permissions and functionality.

**phone** `object`

Phone contact information object.

**title** `string`

Display title for the phone contact.

**link** `string`

Phone number or link for the contact.

**email** `object`

Email contact information object.

**title** `string`

Display title for the email contact.

**link** `string`

Email address or mailto link for the contact.

**website** `object`

Website contact information object.

**title** `string`

Display title for the website contact.

**link** `string`

Website URL for the contact.

**termsOfService** `object`

Terms of service link object.

**title** `string`

Display title for the terms of service link.

**link** `string`

URL to the terms of service page.

**privacyPolicy** `object`

Privacy policy link object.

**title** `string`

Display title for the privacy policy link.

**link** `string`

URL to the privacy policy page.

> [!NOTE]
>
> If you omit the configuration object or leave any fields blank, they will default to the Webchat configuration set in your Dashboard.

**user** `User`

User data to update.

**name** `string`

A name for the user.

**pictureUrl** `string`

URL pointing to a picture for the user.

**data** `object`

An object containing any additional data as key-value pairs. The values can be of any type.

**userKey** `string`

A custom key to associate with the user.

### Returns

***

## `restartConversation`

The asynchronous `window.botpress.restartConversation` method ends the current conversation and starts a new one:

```js theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
await window.botpress.restartConversation();
```

It becomes available after [Webchat is ready to receive messages](https://botpress.com/docs/webchat/interact/listen-to-events.md#webchat-is-ready).

### Parameters

The `restartConversation` method takes no parameters.

### Returns

A Promise that resolves to `void` when a new conversation has been successfully created.

***

## `sendMessage`

The asynchronous `window.botpress.sendMessage` method sends a new message to your bot on behalf of the current user:

```js theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
await window.botpress.sendMessage("<string>");
```

It becomes available after [Webchat is ready to receive messages](https://botpress.com/docs/webchat/interact/listen-to-events.md#webchat-is-ready).

### Parameters

**message** `string` *required*

The message to send to the bot.

### Returns

A Promise that resolves to `void` when the message has successfully been sent.

***

## `sendEvent`

The asynchronous `window.botpress.sendEvent` method sends a new event to your bot:

```js theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
await window.botpress.sendEvent({});
```

It becomes available after [Webchat is ready to receive messages](https://botpress.com/docs/webchat/interact/listen-to-events.md#webchat-is-ready).

### Parameters

**event** `object` *required*

An object containing custom data to send to the bot. Can contain any key-value pairs.

### Returns

A Promise that resolves to `void` when the event has successfully been sent.

***

## `setUnreadMessageCount`

The `window.botpress.setUnreadMessageCount` method sets the number of unread messages to display on the Floating Action Button (FAB):

```js theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
window.botpress.setUnreadMessageCount(123);
```

It becomes available after [Webchat has been initialized](https://botpress.com/docs/webchat/interact/listen-to-events.md#webchat-is-initialized).

### Parameters

**count** `number` *required*

The number of unread messages to display on the FAB.

### Returns

***

## `on`

The `window.botpress.on` method sets up an event listener for a given Webchat event:

```js theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
window.botpress.on('<string>', (event) => {});
```

### Parameters

**type** `string` *required*

The event type to listen for. Can be any of the following event types:

| Event | Description |
| - | - |
| `conversation` | Fires when a new conversation starts |
| `message` | Fires when a message is sent |
| `error` | Fires when an error occurs |
| `customEvent` | Fires for custom events |
| `webchat:initialized` | Fires when Webchat has finished loading and is ready to be opened |
| `webchat:ready` | Fires when Webchat has been opened for the first time and is ready to receive messages |
| `webchat:opened` | Fires when Webchat is opened |
| `webchat:closed` | Fires when Webchat is closed |
| `*` | Fires for any event (receives all events) |

**handler** `function` *required*

Callback function that gets called when the event occurs. The function receives event data specific to each event type as its parameter.

### Returns

An unsubscribe function that can be called to remove the event listener.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.