useWebchatClient
The useWebchatClient
hook provides access to the Botpress Webchat integration instance and related state. It allows you to:
- Interact with the bot
- Listen to real-time events
- Manage conversation lifecycle, user info, and messages
useWebchatClient
is the primary entry point for integrating the Webchat experience into custom UIs or applications.
Usage
Parameters
Your Botpress project Client ID. Required to initialize the client and establish communication with the backend.
Returned Values
The underlying client instance. Can be used to manually send events, fetch data, or interact with the backend.
Represents the current connection state of the client.
Allows you to listen to client events such as incoming messages, typing indicators, or custom events. Here are the native Webchat events that you can listen to:
Events | Description |
---|---|
conversation | Triggered when a new conversation is started. |
message | Triggered when a new message is received. |
messageSent | Triggered when a message is sent. |
error | Triggered when an error occurs. |
webchatVisibility | Triggered when the webchat visibility changes. (‘show’ or ‘hide’ or ‘toggle’) |
webchatConfig | Triggered when the webchat configuration changes. |
customEvent | Triggered when a custom event is received. |
isTyping | Triggered when the bot is typing. |
The current user’s profile object:
The active conversation’s unique identifier.
A function to start a new conversation. Resets the current chat session.
An array of messages for the active conversation. Includes user and bot messages.
Indicates whether messages are currently being fetched from the backend.
Reflects whether the bot is currently “typing,” as indicated by typing events from the backend.
Was this page helpful?