> For the complete documentation index, see [llms.txt](https://developers.chathive.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.chathive.app/sdk/chatbot/events.md).

# Events

You can listen for emitted events by subscribing to them using the on method with your custom callback. For example, your function can be executed every time the widget is opend

## Chathive.widget.on

Subscribes to emitted events, which are described below.\
This function returns a subscription id that can be used to unsubscribe.

```typescript
Chathive.widget.on(eventName, () => void);
```

## Chathive.widget.off

Unsubscribes from emitted events, which are described below.

```typescript
Chathive.widget.off(subscriptionId);
```

## Events list

<table><thead><tr><th width="232">Event name</th><th>Description</th></tr></thead><tbody><tr><td>widget.init</td><td>Widget has been initialised and is ready to be used</td></tr><tr><td>widget.opened</td><td>Widget is opened</td></tr><tr><td>widget.closed</td><td>Widget is closed</td></tr><tr><td>message.inbound</td><td>New message is received.<br><em>Messages are send partially and need to be reconstructed</em></td></tr><tr><td>message.outbound</td><td>Message is send by the user</td></tr><tr><td>tool.called</td><td>Event is emitted when ever a tool is called or ended</td></tr><tr><td>tool.custom.event</td><td>Event is emitted when ever your custom event emitter tool is called</td></tr><tr><td>typing.started</td><td>Is typing is triggered by the agent</td></tr><tr><td>typing.stopped</td><td>Is typing stopped</td></tr></tbody></table>
