> ## Documentation Index
> Fetch the complete documentation index at: https://botpress-pb-update-api.mintlify.site/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](/webchat/get-started/quick-start).

***

## `open`

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

```js theme={null}
window.botpress.open();
```

It becomes available after [Webchat has been initialized](/webchat/interact/listen-to-events#webchat-is-initialized).

### Parameters

The `open` method takes no parameters.

### Returns

<ResponseField name="" type="void" />

***

## `close`

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

```js theme={null}
window.botpress.close();
```

It becomes available after [Webchat has been initialized](/webchat/interact/listen-to-events#webchat-is-initialized).

### Parameters

The `close` method takes no parameters.

### Returns

<ResponseField name="" type="void" />

***

## `toggle`

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

```js theme={null}
window.botpress.toggle();
```

It becomes available after [Webchat has been initialized](/webchat/interact/listen-to-events#webchat-is-initialized).

### Parameters

The `toggle` method takes no parameters.

### Returns

<ResponseField name="" type="void" />

***

## `updateUser`

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

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

It becomes available after [Webchat has been initialized](/webchat/interact/listen-to-events#webchat-is-initialized).

### Parameters

<ResponseField name="user" type="User">
  The user attributes to update.

  <Expandable>
    <ResponseField name="name" type="string">
      A name for the user.
    </ResponseField>

    <ResponseField name="pictureUrl" type="string">
      URL pointing to a picture for the user.
    </ResponseField>

    <ResponseField name="data" type="object">
      An object containing any additional data as key-value pairs. The values can be of any type.
    </ResponseField>

    <ResponseField name="userKey" type="string">
      A custom key to associate with the user.
    </ResponseField>
  </Expandable>
</ResponseField>

<Note>
  By default, the `user` object contains the following properties:

  <ResponseField name="user" type="User">
    <Expandable>
      <ResponseField name="id" type="string" required>
        Unique identifier for the user.
      </ResponseField>

      <ResponseField name="createdAt" type="string" required>
        User creation timestamp in ISO 8601 format.
      </ResponseField>

      <ResponseField name="updatedAt" type="string" required>
        Last user update timestamp in ISO 8601 format.
      </ResponseField>
    </Expandable>
  </ResponseField>

  These are generated by the server and can't be updated or deleted.
</Note>

### Returns

<ResponseField name="" type="Promise<void>">
  A Promise that resolves `void` when the user data has been successfully updated.
</ResponseField>

***

## `getUser`

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

```js theme={null}
await window.botpress.getUser();
```

It becomes available after [Webchat has been initialized](/webchat/interact/listen-to-events#webchat-is-initialized).

### Parameters

The `getUser` method takes no parameters.

### Returns

<ResponseField name="" type="Promise<User>">
  A Promise that resolves when the user information has been retrieved.

  <Expandable>
    <ResponseField name="id" type="string" required>
      Unique identifier for the user.
    </ResponseField>

    <ResponseField name="createdAt" type="string" required>
      User creation timestamp in ISO 8601 format.
    </ResponseField>

    <ResponseField name="updatedAt" type="string" required>
      Last user update timestamp in ISO 8601 format.
    </ResponseField>

    <ResponseField name="name" type="string">
      A name for the user.
    </ResponseField>

    <ResponseField name="pictureUrl" type="string">
      URL pointing to a picture for the user.
    </ResponseField>

    <ResponseField name="data" type="object">
      An object containing any additional data as key-value pairs. The values can be of any type.
    </ResponseField>

    <ResponseField name="userKey" type="string">
      A custom key to associate with the user.
    </ResponseField>
  </Expandable>
</ResponseField>

***

## `config`

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

```js theme={null}
window.botpress.config({
  configuration: {},
  user: {}
});
```

It becomes available after [Webchat has been initialized](/webchat/interact/listen-to-events#webchat-is-initialized).

### Parameters

<ResponseField name="" type="object" required>
  An object containing the Webchat configuration and user data to update.

  <Expandable>
    <ResponseField name="configuration" type="object">
      Webchat configuration settings to update.

      <Expandable>
        <ResponseField name="botName" type="string">
          Name of the bot displayed in the Webchat header.
        </ResponseField>

        <ResponseField name="botAvatar" type="string">
          URL to the bot's avatar image.
        </ResponseField>

        <ResponseField name="botDescription" type="string">
          Description of the bot.
        </ResponseField>

        <ResponseField name="composerPlaceholder" type="string">
          Placeholder text for the message input field.
        </ResponseField>

        <ResponseField name="color" type="string">
          Primary color theme for the Webchat interface as a HEX code.
        </ResponseField>

        <ResponseField name="themeMode" type="string">
          Theme mode. Can be `light` or `dark`.
        </ResponseField>

        <ResponseField name="variant" type="string">
          Visual variant. Can be `solid` or `soft`.
        </ResponseField>

        <ResponseField name="allowFileUpload" type="boolean">
          Whether to enable file upload functionality.
        </ResponseField>

        <ResponseField name="showPoweredBy" type="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.
          </Warning>
        </ResponseField>

        <ResponseField name="feedbackEnabled" type="boolean">
          Whether to enable message feedback functionality.
        </ResponseField>

        <ResponseField name="fabImage" type="string">
          URL to the Floating Action Button (FAB) image.
        </ResponseField>

        <ResponseField name="radius" type="number">
          Border radius for the Webchat interface. Must be between 0.5 and 4.
        </ResponseField>

        <ResponseField name="fontFamily" type="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.
          </Warning>
        </ResponseField>

        <ResponseField name="additionalStylesheet" type="string">
          Custom CSS styles to apply to the Webchat interface.
        </ResponseField>

        <ResponseField name="additionalStylesheetUrl" type="string">
          URL to an external stylesheet to load for the Webchat interface.
        </ResponseField>

        <ResponseField name="storageLocation" type="string">
          Storage location for webchat data. Can be `localStorage` or `sessionStorage`.
        </ResponseField>

        <ResponseField name="footer" type="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.
          </Tip>
        </ResponseField>

        <ResponseField name="headerVariant" type="string">
          Header visual variant. Can be `solid` or `glass`.
        </ResponseField>

        <ResponseField name="adminKey" type="string">
          Admin key for enhanced permissions and functionality.
        </ResponseField>

        <ResponseField name="phone" type="object">
          Phone contact information object.

          <Expandable>
            <ResponseField name="title" type="string">
              Display title for the phone contact.
            </ResponseField>

            <ResponseField name="link" type="string">
              Phone number or link for the contact.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="email" type="object">
          Email contact information object.

          <Expandable>
            <ResponseField name="title" type="string">
              Display title for the email contact.
            </ResponseField>

            <ResponseField name="link" type="string">
              Email address or mailto link for the contact.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="website" type="object">
          Website contact information object.

          <Expandable>
            <ResponseField name="title" type="string">
              Display title for the website contact.
            </ResponseField>

            <ResponseField name="link" type="string">
              Website URL for the contact.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="termsOfService" type="object">
          Terms of service link object.

          <Expandable>
            <ResponseField name="title" type="string">
              Display title for the terms of service link.
            </ResponseField>

            <ResponseField name="link" type="string">
              URL to the terms of service page.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="privacyPolicy" type="object">
          Privacy policy link object.

          <Expandable>
            <ResponseField name="title" type="string">
              Display title for the privacy policy link.
            </ResponseField>

            <ResponseField name="link" type="string">
              URL to the privacy policy page.
            </ResponseField>
          </Expandable>
        </ResponseField>
      </Expandable>
    </ResponseField>

    <Note>
      If you omit the configuration object or leave any fields blank, they will default to the Webchat configuration set in your Dashboard.
    </Note>

    <ResponseField name="user" type="User">
      User data to update.

      <Expandable>
        <ResponseField name="name" type="string">
          A name for the user.
        </ResponseField>

        <ResponseField name="pictureUrl" type="string">
          URL pointing to a picture for the user.
        </ResponseField>

        <ResponseField name="data" type="object">
          An object containing any additional data as key-value pairs. The values can be of any type.
        </ResponseField>

        <ResponseField name="userKey" type="string">
          A custom key to associate with the user.
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

### Returns

<ResponseField name="" type="void" />

***

## `restartConversation`

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

```js theme={null}
await window.botpress.restartConversation();
```

It becomes available after [Webchat is ready to receive messages](/webchat/interact/listen-to-events#webchat-is-ready).

### Parameters

The `restartConversation` method takes no parameters.

### Returns

<ResponseField name="" type="Promise<void>">
  A Promise that resolves to `void` when a new conversation has been successfully created.
</ResponseField>

***

## `sendMessage`

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

```js theme={null}
await window.botpress.sendMessage("<string>");
```

It becomes available after [Webchat is ready to receive messages](/webchat/interact/listen-to-events#webchat-is-ready).

### Parameters

<ResponseField name="message" type="string" required>
  The message to send to the bot.
</ResponseField>

### Returns

<ResponseField name="" type="Promise<void>">
  A Promise that resolves to `void` when the message has successfully been sent.
</ResponseField>

***

## `sendEvent`

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

```js theme={null}
await window.botpress.sendEvent({});
```

It becomes available after [Webchat is ready to receive messages](/webchat/interact/listen-to-events#webchat-is-ready).

### Parameters

<ResponseField name="event" type="object" required>
  An object containing custom data to send to the bot. Can contain any key-value pairs.
</ResponseField>

### Returns

<ResponseField name="" type="Promise<void>">
  A Promise that resolves to `void` when the event has successfully been sent.
</ResponseField>

***

## `setUnreadMessageCount`

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

```js theme={null}
window.botpress.setUnreadMessageCount(123);
```

It becomes available after [Webchat has been initialized](/webchat/interact/listen-to-events#webchat-is-initialized).

### Parameters

<ResponseField name="count" type="number" required>
  The number of unread messages to display on the FAB.
</ResponseField>

### Returns

<ResponseField name="" type="void" />

***

## `on`

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

```js theme={null}
window.botpress.on('<string>', (event) => {});
```

### Parameters

<ResponseField name="type" 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)                                              |
</ResponseField>

<ResponseField name="handler" type="function" required>
  Callback function that gets called when the event occurs. The function receives event data specific to each event type as its parameter.
</ResponseField>

### Returns

<ResponseField name="" type="function">
  An unsubscribe function that can be called to remove the event listener.
</ResponseField>
