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

# Events

> Run your code when something happens in the chat

Listen with `DeskHoot.on()`. It returns a function that stops listening.

```js theme={null}
const stop = DeskHoot.on("unread", ({ count }) => {
  document.title = count ? `(${count}) New message` : "Acme";
});

stop(); // stop listening
```

## Listening

**event** `string` *required*

The event to listen for. Any other name is ignored.

**handler** `function` *required*

Called with the event's details each time it happens.

`DeskHoot.off(event, handler)` removes a handler you added with the same function.

## Events

The chat loads the first time it opens, or straight away for a visitor who has chatted before. To get events earlier, call `DeskHoot.ready()`.

**ready** `\{\}`

The chat has loaded and is ready for your calls.

**open** `\{\}`

The chat opened, from the chat button or from `DeskHoot.open()`.

**close** `\{\}`

The chat closed.

**unread** `\{ count: number \}`

The number of unread messages changed.

**details**

**count** `number`

Messages the customer has not read yet.

**identityChanged** `\{ identified: boolean \}`

A customer was signed in or out.

**details**

**identified** `boolean`

`true` when a [verified customer](https://docs.deskhoot.com/sdk/identify.md) is signed in, `false` for a guest.

**identityRequired** `\{\}`

The chat can take a signed customer now, for example after the customer continued in a separate chat window. If your page has one, call `DeskHoot.setUser()`.

**identity-error** `\{ code: string \}`

A signed customer was refused.

**details**

**code** `string`

Why, as one of the [Verify users errors](https://docs.deskhoot.com/sdk/identify.md#errors).

**error** `\{ code: string \}`

Something went wrong in the chat.

**details**

**code** `string`

What went wrong. `widget_unavailable` means the chat could not load, for example because this website is not in **Allow your websites** or the connection timed out after 20 seconds.

## Related

> [card] [Open and close](https://docs.deskhoot.com/sdk/control.md)
>
> Control the chat from your own code.

> [card] [Verify users](https://docs.deskhoot.com/sdk/identify.md)
>
> Show signed-in customers to your team.

> [card] [Light or dark](https://docs.deskhoot.com/sdk/theme.md)
>
> Match your website's theme.

> [card] [Methods](https://docs.deskhoot.com/sdk/methods.md)
>
> What `DeskHoot` can do.


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