Add a chat widget to a character
Add the Convai chat widget to a Convai Embody character so users can type and talk to it over the connection the character already holds.
Add the Convai Web SDK chat widget beside a Convai Embody character so users can type and speak to it. Use this page after the character renders in your React app. At the end, a message sent from the widget gets a spoken reply that the character lip-syncs.
Prerequisites
A character rendered with
ConvaiCharacterorCharacterModel. See Add a 3D character to a React app.
Lift the client out of the character
The character holds the connection. onReady hands you the character once its body is loaded and its connection is live, and character.client is that connection's ConvaiClient. Store it in state outside the canvas, because the widget is DOM and cannot render inside the 3D scene.
Render the widget
Pass the character's own client to ConvaiWidget. The widget subscribes to it, so the chat and the character share one connection. ConvaiClient comes from @convai/embody/react; ConvaiWidget is the chat UI package's, so install it (0.3.0 or later) next to Convai Embody:
npm install @convai/web-widgetimport { useState } from 'react'
import { ConvaiCharacter, type ConvaiClient } from '@convai/embody/react'
import { ConvaiWidget } from '@convai/web-widget/react'
export default function App({ token }: { token: string }) {
const [client, setClient] = useState<ConvaiClient | null>(null)
return (
<>
<ConvaiCharacter
token={token}
characterId="YOUR_CHARACTER_ID"
onReady={(character) => setClient(character.client)}
/>
{client && <ConvaiWidget convaiClient={client} />}
</>
)
}Verify the widget
Type a message in the widget and send it.
Next steps
React API referenceConvaiWidget component referenceLast updated
Was this helpful?