> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-embody/add-a-chat-widget-to-a-character.md).

# 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 `ConvaiCharacter` or `CharacterModel`. See [Add a 3D character to a React app](/api-docs/plugins-and-integrations/web-plugins/convai-embody/add-a-3d-character-to-a-react-app.md).

### 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

`useWidgetClient` adapts the character's client to the props `ConvaiWidget` expects and returns `null` until a client exists. `ConvaiWidget`, `ConvaiClient`, and `useWidgetClient` are all exported from `@convai/embody/react`, so the app needs no direct import from `@convai/web-sdk`.

{% code title="src/App.tsx" %}

```tsx
import { useState } from 'react'
import {
  ConvaiCharacter,
  ConvaiWidget,
  useWidgetClient,
  type ConvaiClient,
} from '@convai/embody/react'

export default function App({ token }: { token: string }) {
  const [client, setClient] = useState<ConvaiClient | null>(null)
  const widgetClient = useWidgetClient(client)

  return (
    <>
      <ConvaiCharacter
        token={token}
        characterId="YOUR_CHARACTER_ID"
        onReady={(character) => setClient(character.client)}
      />
      {widgetClient && <ConvaiWidget convaiClient={widgetClient} />}
    </>
  )
}
```

{% endcode %}

{% hint style="warning" %}
Do not create the widget's client with `useConvaiClient`. That hook constructs a second `ConvaiClient`, which opens a second connection: the widget would talk to one session while the character lip-syncs to another, so the character stays silent.
{% endhint %}

### Verify the widget

Type a message in the widget and send it.

{% hint style="success" %}
The reply appears in the widget, the character speaks it, and the character's mouth moves in time with the audio.
{% endhint %}

### Next steps

{% content-ref url="/pages/CNRIrVYbzZ53QpYCXQCV" %}
[React API reference](/api-docs/plugins-and-integrations/web-plugins/convai-embody/react-api-reference.md)
{% endcontent-ref %}

{% content-ref url="/pages/VVA0bI3FaMJjHAXp7Ce4" %}
[ConvaiWidget component reference](/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/react/convaiwidget.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-embody/add-a-chat-widget-to-a-character.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
