# Chat window API

https://flowhelp.ai/docs/developers/api

Your page can control the chat window through `window.flowhelp`. You can call it before the widget loads: the calls are queued and run in order.

## Queue calls before the widget loads

Push each call as an array: the method name first, then its arguments. The widget runs them in order once it starts.

```js
window.flowhelp = window.flowhelp || [];
window.flowhelp.push(['open']);
window.flowhelp.push(['on', 'ready', () => console.log('widget ready')]);
```

After the `ready` event you can also call the methods directly, for example `window.flowhelp.open()` or `window.flowhelp.isOpen()`.

Through the `push` queue the methods return nothing, so `isOpen` makes sense only when called directly. An unknown method logs a console warning and does not throw.

## Methods

| Method                                    | Effect                                                                                                                                                |
| ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `open` / `close` / `toggle` / `isOpen`    | The chat window.                                                                                                                                      |
| `sendMessage(text)`                       | Sends a message as the user.                                                                                                                          |
| `setLocale('pl'\|'en'\|'de'\|'fr'\|'it')` | Window language (buttons and fixed messages). The assistant replies in the language the visitor writes in, whatever the window language.              |
| `setTheme('light'\|'dark'\|'auto')`       | Window theme on this page instead of the dashboard setting. `auto` follows the visitor's device.                                                      |
| `on(event, cb)` / `off(event, cb)`        | Events: `ready`, `open`, `close`, `message:sent`, `message:received`, `error`.                                                                        |
| `grantConsent()` / `revokeConsent()`      | Visitor consent. See [Visitor consent](https://flowhelp.ai/docs/developers/consent).                                                                  |
| `reset()`                                 | Clears the visitor identifier, the current conversation and the identity set by `identify`.                                                           |
| `identify({ userId, hash })`              | Identity of a signed-in user with an HMAC signature. `identify(null)` signs out. See [Logged-in users](https://flowhelp.ai/docs/developers/identify). |
| `init`                                    | No effect. The widget starts by itself.                                                                                                               |

## If your page has its own light/dark switch

The widget cannot see what the visitor chose in your switch, so your page has to pass the theme itself: on load and after every change.

```js
window.flowhelp = window.flowhelp || [];
window.flowhelp.push(['setTheme', 'dark']); // 'light', 'dark' or 'auto'
```

`light` and `dark` override the dashboard setting. `auto` hands the choice back to the visitor's device. The choice lasts until the page is reloaded, and the widget stores nothing about it in the browser.

With a custom background color, `setTheme` works the same way. The custom background replaces the theme of its own brightness, so a dark background replaces the dark theme, and the other theme stays standard. See [Chat window](https://flowhelp.ai/docs/appearance/window).

## Errors

The `error` event and an entry in the browser console with the error code report problems such as a used-up allowance. See [Limits and errors](https://flowhelp.ai/docs/developers/errors).

## See also

- [Logged-in users](https://flowhelp.ai/docs/developers/identify)
- [Visitor consent](https://flowhelp.ai/docs/developers/consent)
- [Limits and errors](https://flowhelp.ai/docs/developers/errors)

Last changed: November 24, 2026
