Skip to main content
You can listen to Webchat events within your website’s source code. This is useful if you want to:
  • Make your website more responsive to Webchat
  • Adjust UI elements depending on Webchat’s status
  • Handle Webchat errors on your website

With embedded Webchat

If you added Webchat to your website using the embed code, you can use the window.botpress.on method to listen to events. Just copy and paste any code snippet below into your source code. Then, you can add whatever code you want—it’ll execute whenever the event fires.
You will need:
  • A website with an embedded bot
  • Familiarity with JavaScript

Webchat is initialized

This event fires when Webchat has finished loading and is ready to be opened:
index.js
This occurs when window.botpress.init (the function in the second inject script) finishes its execution.

Webchat is ready

This event fires after Webchat has been opened for the first time and is ready to receive messages:
index.js

Webchat opens

This event fires when the Webchat window is opened:
index.js

Webchat closes

This event fires when the Webchat window is closed:
index.js

New conversation starts

This event fires when a new conversation starts in Webchat:
index.js

Message is sent

This event fires when either the user or the bot sends a message:
index.js

Error occurs

This event fires when the bot raises an error:
index.js

Custom event

This event fires when the bot triggers a custom event:
index.js

With the Webchat React library

You will need:
If you’re using the Webchat React library, you can use the useWebchat hook’s returned on value to listen to events. Just add the following code at the top level of your Webchat implementation:
useWebchat
Then, paste any of the code snippets below to listen to events. You can add whatever code you want—it’ll execute whenever the event fires.
The useWebchat hook is incompatible with the batteries-included <Webchat> component—using them together will cause issues and unexpected behaviour.If you need to use the hook, make sure you’re manually building Webchat.

New conversation starts

This event fires when a new conversation starts in Webchat:

Message is sent

This event fires when either the user or the bot sends a message:

Error occurs

This event fires when the bot raises an error:

Webchat visibility changes

This event fires when you change Webchat’s visibility using a Webchat Card:

Configuration changes

This event fires when you change Webchat’s configuration using the Configure Webchat Card:

Custom event

This event fires when the bot triggers a custom event:

Bot is typing

This event fires when the bot starts/stops typing:
Last modified on January 27, 2026