> 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/zh/cha-jian-yu-ji-cheng/web-plugins/convai-web-sdk/react/useconvaiclient-hook.md).

# useConvaiClient Hook

## 配置

```tsx
interface ConvaiConfig {
  apiKey: string;                    // 必需：您的 API 密钥
  characterId: string;                // 必需：角色 ID
  endUserId?: string;                 // 可选：用于记忆和分析
  url?: string;                       // 可选：自定义 API 端点
  enableVideo?: boolean;              // 启用视频/屏幕共享（默认：false）
  startWithVideoOn?: boolean;         // 启动时开启摄像头（默认：false）
  startWithAudioOn?: boolean;         // 启动时开启麦克风（默认：false）
  ttsEnabled?: boolean;               // 启用 TTS（默认：true）
  enableLipsync?: boolean;            // 启用 blendshape（默认：false）
  blendshapeConfig?: {
    format?: 'arkit' | 'mha';         // 形变格式（默认：'mha'）
  };
  actionConfig?: {                    // 可选：角色动作
    actions: string[];
    characters: Array<{ name: string; bio: string }>;
    objects: Array<{ name: string; description: string }>;
    currentAttentionObject?: string;
  };
}

```

### 返回值

```tsx
const convaiClient = useConvaiClient(config);
```

### State

```tsx
convaiClient.state              // 连接 + 活动状态
convaiClient.connectionType     // 'audio' | 'video' | null
convaiClient.isBotReady         // 机器人已准备好接收消息
convaiClient.chatMessages       // 所有对话消息
convaiClient.userTranscription  // 实时语音转文本
```

### 连接方法

```tsx
convaiClient.connect(config?)   
convaiClient.disconnect()
convaiClient.reconnect()
convaiClient.resetSession()
```

### 消息发送

```tsx
convaiClient.sendUserTextMessage(text)
convaiClient.sendTriggerMessage(triggerName, message?)
convaiClient.updateTemplateKeys({ key: 'value' })
convaiClient.updateDynamicInfo({ text: 'context' })
```

### 控制

```tsx
convaiClient.audioControls
convaiClient.videoControls
convaiClient.screenShareControls
convaiClient.toggleTts(enabled)
```

### 示例：手动连接

```tsx
function App() {
  const convaiClient = useConvaiClient(); // 无初始配置

  const connect = () => convaiClient.connect({
    apiKey: '你的-api-key',
    characterId: 'your-character-id'
  });

  return <button onClick={connect}>连接</button>;
}
```


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/web-plugins/convai-web-sdk/react/useconvaiclient-hook.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
