CometChatAIAssistantChat is a composite component that assembles the message header, message list, and message composer to provide an AI agent chat experience. It supports streaming responses, quick starter suggestions, “New Chat” to reset context, and a chat history sidebar.
Report incorrect code
Copy
Ask AI
import React from "react";import { CometChat } from "@cometchat/chat-sdk-javascript";import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";export function AIAssistantChatDemo() { const [agent, setAgent] = React.useState<CometChat.User>(); React.useEffect(() => { // Replace with your assistant UID CometChat.getUser("assistant_uid").then((u) => setAgent(u)); }, []); if (!agent) return null; return( <> <CometChatAIAssistantChat user={agent} /> </> ); }
A CometChat.User (the AI agent) is required to start the assistant chat.
To fit your app’s design requirements, you can customize the appearance of the Assistant Chat component. We provide exposed properties that allow you to modify the experience and behavior according to your specific needs.
These props tailor the experience. Most message options (copy/edit/delete/react, receipts, date separators, etc.) are disabled by default for assistant chats.
Report incorrect code
Copy
Ask AI
import React from "react";import { CometChat } from "@cometchat/chat-sdk-javascript";import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";export function AIAssistantChatDemo = () => { const [agent, setAgent] = React.useState<CometChat.User>(); React.useEffect(() => { CometChat.getUser("assistant_uid").then((u) => setAgent(u)); }, []); if (!agent) return null; // Example: Set streaming speed to 30 characters per second // and show close button // You can also customize suggestions, empty state, etc. return ( <CometChatAIAssistantChat user={agent} showCloseButton={true} setStreamingSpeed={30} /> )}
Property
Description
Example
user
Required CometChat.User representing the AI agent.
user={agent}
streamingSpeed
Characters-per-second speed for streaming replies. Default 30.
streamingSpeed={50}
suggestedMessages
Array of quick prompts for the empty state.
suggestedMessages=["Help", "Summarize"]
hideSuggestedMessages
Hide the suggestions section.
hideSuggestedMessages={true}
hideNewChat
Hide the New Chat button in header.
hideNewChat={true}
hideChatHistory
Hide the History button/sidebar.
hideChatHistory={true}
showBackButton
Show back button in header.
showBackButton
showCloseButton
Show close button in header.
showCloseButton
onBackButtonClicked
Back button handler.
onBackButtonClicked={() => {}}
onCloseButtonClicked
Close button handler.
onCloseButtonClicked={() => {}}
onSendButtonClick
Send button handler.
onSendButtonClick={() => {}}
onError
Error handler.
onError={handleError}
emptyView
Custom empty state for the list.
emptyView={<Empty/>}
loadingView
Custom loading view.
loadingView={<Loading/>}
errorView
Custom error view.
errorView={<Error/>}
emptyChatGreetingView
Custom empty title (default uses metadata.greetingMessage or user name).
Customize header sections using the following props: headerItemView, headerTitleView, headerSubtitleView, headerLeadingView, headerTrailingView, and headerAuxiliaryButtonView. These customizations are done in the similar way as the Message Header component.
The header’s “New Chat” and “History” buttons are built-in. You can override them by providing a custom headerAuxiliaryButtonView.