useWebchat
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
import { useWebchat } from '@botpress/webchat'
function App() {
const { client, clientState, on, user, conversationId, newConversation, messages, isFetchingMessages, isTyping } =
useWebchat({
clientId: '$CLIENT_ID$', // Insert your Client ID here
})
}
Parameters
clientId string
required
Returned Values
client WebchatClient
clientState 'connecting' | 'connected' | 'error' | 'disconnected'
on (event: string, callback: Function) => void
user User
conversationId string
newConversation () => void
messages BlockMessage[]
isFetchingMessages boolean
isTyping boolean