- 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, 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
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:
- A working React app that implements Webchat
useWebchat
hook’s returned on
value to listen to events. Just add the following code at the top level of your Webchat implementation:
useWebchat
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.