Skip to main content
The useWebchat hook provides access to the Webchat client and its state. It allows you to:
  • Interact with your bot
  • Listen to real-time events
  • Manage conversation lifecycle, user info, and messages
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.

Usage

App.tsx

Parameters

string
Your Botpress project Client ID. Required to initialize the client and establish communication with the server.

Returned Values

WebchatClient
The underlying client instance. Can be used to manually send events, fetch data, or interact with the server.
'connecting' | 'connected' | 'error' | 'disconnected'
Represents the current connection state of the client.
(event: string, callback: Function) => void
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:
User
The current user’s profile object:
string
The active conversation’s unique identifier.
() => void
A function to start a new conversation. Resets the current chat session.
BlockMessage[]
An array of messages for the active conversation. Includes user and bot messages.
boolean
Indicates whether messages are currently being fetched from the server.
boolean
Reflects whether the bot is currently “typing,” as indicated by typing events from the server.
Last modified on June 15, 2026