Webchat
Installation
npm install @botpress/webchat
yarn add @botpress/webchat
pnpm add @botpress/webchat
Usage
import { useEffect, useState } from 'react'
import { getClient, Webchat, WebchatProvider, WebchatClient, Configuration } from '@botpress/webchat'
const clientId = '$CLIENT_ID'
const userData = { foo: 'bar' }
const configuration: Configuration = {
botAvatar: 'https://upload.wikimedia.org/wikipedia/commons/9/91/T-bone-raw-MCB.jpg',
botDescription: 'Hello, world!',
botName: 'Hello Bot',
}
function App() {
const [client, setClient] = useState<WebchatClient | null>(null)
useEffect(() => {
const client = getClient({ clientId })
setClient(client)
client.on('*', (ev) => {
console.log('Event:', ev)
client.getUser().then((user) => {
console.log('User:', user)
})
})
}, [])
if (!client) {
return <div>Loading...</div>
}
return (
<WebchatProvider theme={{}} client={client} configuration={configuration} userData={userData}>
<Webchat />
</WebchatProvider>
)
}
export default App