AI Integration Quick Reference
AI Integration Quick Reference
Overview
CometChatCompactMessageComposer is a Component that provides a compact, single-line message input with optional rich text formatting capabilities. It supports bold, italic, underline, strikethrough, code, links, lists, and blockquotes.
This is a compact variant of CometChatMessageComposer. It shares a similar props API but provides a streamlined, single-line interface with rich text formatting controls.
Wire it alongside CometChatMessageHeader and CometChatMessageList to build a standard chat view.
Features such as Rich Text Formatting, Attachments, Message Editing, Mentions, Link Previews, and Voice Recording are supported.

Before using this component: Ensure
CometChatUIKit.init(UIKitSettings) has completed and the user is logged in via CometChatUIKit.login("UID"). See React.js Integration.Minimal Render
Usage
Integration
The following code snippet illustrates how you can directly incorporate the CompactMessageComposer component into your app.- TypeScript
- JavaScript
- The
CometChatCompactMessageComposercomponent renders a compact, single-line message input - The input supports typing, sending messages, attachments, emoji, stickers, and voice recording
- Clicking the send button dispatches the message to the specified
user
Actions and Events
Callback Props
Actions dictate how a component functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the component to fit your specific needs.onSendButtonClick
Fires when the send message button is clicked. Overrides the default send behavior.- TypeScript
- JavaScript
onError
Fires on internal errors (network failure, auth issue, SDK exception). This action doesn’t change the behavior of the component but rather listens for any errors that occur in the CompactMessageComposer component.- TypeScript
- JavaScript
onTextChange
Fires as the user types in the composer input.- TypeScript
- JavaScript
Custom Mentions Request Builders
You can customize how mentioned users and group members are fetched by providing custom request builders.- TypeScript
- JavaScript
Filters
CompactMessageComposer component does not have any available filters.Global UI Events
Events are emitted by aComponent. By using events you can extend existing functionality. Being global events, they can be applied in multiple locations and are capable of being added or removed.
CometChatMessageEvents emits events subscribable from anywhere in the application. Add listeners and remove them on cleanup.
| Event | Fires when | Payload |
|---|---|---|
| ccMessageSent | A message is sent | { message: CometChat.BaseMessage, status: string } |
| ccMessageEdited | A message is edited | { message: CometChat.BaseMessage, status: string } |
| ccReplyToMessage | A user replies to a message | { message: CometChat.BaseMessage, status: string } |
inProgress, success, and error.
When to use: sync external UI with message state changes. For example, update a notification badge when messages are sent, or trigger analytics when a message is edited.
- TypeScript
- JavaScript
In React 18 StrictMode,
useEffect runs twice on mount in development. The component handles listener cleanup internally, but any additional listeners added alongside the component need cleanup in the useEffect return function to avoid duplicate event handling.Customization
To fit your app’s design requirements, you can customize the appearance of the CompactMessageComposer component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.Functionality
These are a set of small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can change text, set custom icons, and toggle the visibility of UI elements.- TypeScript
| Property | Type | Default | Description | Code |
|---|---|---|---|---|
| user | CometChat.User | undefined | Specifies the recipient of the message (user object). | user={chatUser} |
| group | CometChat.Group | undefined | Specifies the group to send messages to. Used if the user prop is not provided. | group={chatGroup} |
| parentMessageId | number | undefined | Specifies the ID of the parent message for threading or replying to a specific message. | parentMessageId={12345} |
| initialComposerText | string | "" | The initial text pre-filled in the message input when the component mounts. | initialComposerText="Hello" |
| placeholderText | string | "Type a message..." | The placeholder text displayed in the message input when it is empty. | placeholderText="Type a message..." |
| disableTypingEvents | boolean | false | Disables the typing indicator for the current message composer. | disableTypingEvents={true} |
| disableMentions | boolean | false | Disables the mentions functionality in the message composer. | disableMentions={true} |
| disableMentionAll | boolean | false | Controls whether group mentions like @all appear in suggestions. | disableMentionAll={true} |
| mentionAllLabel | string | "all" | Allows setting a custom alias label for group mentions (@channel, @everyone, etc.). | mentionAllLabel="all" |
| mentionsUsersRequestBuilder | CometChat.UsersRequestBuilder | undefined | Provides a custom UsersRequestBuilder to control how the mentioned users list is fetched. | mentionsUsersRequestBuilder={usersRequestBuilder} |
| mentionsGroupMembersRequestBuilder | CometChat.GroupMembersRequestBuilder | undefined | Provides a custom GroupMembersRequestBuilder to customize how mentioned group members are retrieved. | mentionsGroupMembersRequestBuilder={groupMembersRequestBuilder} |
| enableRichTextEditor | boolean | false | Master switch to enable rich text formatting. When false, the composer works as plain text only. | enableRichTextEditor={true} |
| showToolbarOnSelection | boolean | false | Shows a floating toolbar when text is selected. Ignored on mobile devices. | showToolbarOnSelection={true} |
| hideRichTextFormattingOptions | boolean | false | Hides the rich text formatting toolbar. Keyboard shortcuts still work. | hideRichTextFormattingOptions={true} |
| hideImageAttachmentOption | boolean | false | Hides the image attachment option in the message composer. | hideImageAttachmentOption={true} |
| hideVideoAttachmentOption | boolean | false | Hides the video attachment option in the message composer. | hideVideoAttachmentOption={true} |
| hideAudioAttachmentOption | boolean | false | Hides the audio attachment option in the message composer. | hideAudioAttachmentOption={true} |
| hideFileAttachmentOption | boolean | false | Hides the file attachment option in the message composer. | hideFileAttachmentOption={true} |
| hidePollsOption | boolean | false | Hides the polls option in the message composer. | hidePollsOption={true} |
| hideCollaborativeDocumentOption | boolean | false | Hides the collaborative document option in the message composer. | hideCollaborativeDocumentOption={true} |
| hideCollaborativeWhiteboardOption | boolean | false | Hides the collaborative whiteboard option in the message composer. | hideCollaborativeWhiteboardOption={true} |
| hideAttachmentButton | boolean | false | Hides the attachment button in the message composer. | hideAttachmentButton={true} |
| hideVoiceRecordingButton | boolean | false | Hides the voice recording button in the message composer. | hideVoiceRecordingButton={true} |
| hideEmojiKeyboardButton | boolean | false | Hides the emoji keyboard button in the message composer. | hideEmojiKeyboardButton={true} |
| hideStickersButton | boolean | false | Hides the stickers button in the message composer. | hideStickersButton={true} |
| hideSendButton | boolean | false | Hides the send button in the message composer. | hideSendButton={true} |
| showScrollbar | boolean | false | Controls the visibility of the scrollbar in the composer. | showScrollbar={true} |
| enterKeyBehavior | EnterKeyBehavior | EnterKeyBehavior.SendMessage | Determines the behavior of the Enter key (e.g., send message or add a new line). | enterKeyBehavior={EnterKeyBehavior.SendMessage} |
| disableSoundForMessage | boolean | false | Disables sound for incoming messages. | disableSoundForMessage={true} |
| customSoundForMessage | string | undefined | Specifies a custom audio sound for incoming messages. | customSoundForMessage="sound.mp3" |
Rich Text Formatting
The CompactMessageComposer includes a built-in rich text editor. Rich text must be explicitly enabled viaenableRichTextEditor={true} (defaults to false).
Formatting Toolbar
The toolbar provides the following formatting tools in a fixed order:| Tool | Icon | Shortcut | Description |
|---|---|---|---|
| Bold | B | Cmd/Ctrl+B | Bold text |
| Italic | I | Cmd/Ctrl+I | Italic text |
| Underline | U | Cmd/Ctrl+U | Underline text |
| Strikethrough | S | Cmd/Ctrl+Shift+S | Strikethrough text |
| Inline Code | </> | Cmd/Ctrl+E | Inline code |
| Code Block | ``` | Cmd/Ctrl+Shift+C | Multi-line code block |
| Link | 🔗 | Cmd/Ctrl+K | Add/edit hyperlink |
| Bullet List | • | Cmd/Ctrl+Shift+8 | Unordered list |
| Ordered List | 1. | Cmd/Ctrl+Shift+7 | Numbered list |
| Blockquote | ❝ | Cmd/Ctrl+Shift+9 | Quote block |
Toolbar Visibility Modes
The toolbar supports multiple display modes controlled via props. When multiple props are set, they follow this priority order:enableRichTextEditor={false}— Highest priority, disables all rich text features (plain text only)hideRichTextFormattingOptions={true}— Toolbar visible by default above inputshowToolbarOnSelection={true}— Floating toolbar appears on text selection (desktop only)
Behavior Matrix
enableRichTextEditor | hideRichTextFormattingOptions | showToolbarOnSelection | Result |
|---|---|---|---|
false | - | - | Plain text, no formatting UI |
true | false | true | Floating toolbar appears on text selection (desktop) |
true | true | false | Toolbar visible by default above input |
true | false | false | No toolbar UI, only keyboard shortcuts work |
Mobile Behavior
On mobile devices, only the fixed toolbar is supported. The floating selection toolbar is disabled for better touch UX.| Props | Mobile Behavior |
|---|---|
showToolbarOnSelection={true} | Ignored on mobile — Falls back to fixed toolbar |
hideRichTextFormattingOptions={true} | Fixed toolbar visible by default above input |
Toolbar Configuration Examples
- Selection Toolbar
- Toolbar Always Visible
- Keyboard Shortcuts Only
- Combined Modes
Custom View Slots
Each slot replaces a section of the default UI. Slots that accept parameters receive the relevant data for customization.| Slot | Type | Replaces |
|---|---|---|
headerView | JSX.Element | Area above the composer input |
auxiliaryButtonView | JSX.Element | Sticker and AI button area |
sendButtonView | JSX.Element | Send button |
attachmentOptions | CometChatMessageComposerAction[] | Default attachment options list (replaces defaults) |
textFormatters | CometChatTextFormatter[] | Text formatting in composer |
Advanced
For advanced-level customization, you can set custom views to the component. This lets you tailor each aspect of the component to fit your exact needs and application aesthetics. You can create and define your views, layouts, and UI elements and then incorporate those into the component.AttachmentOptions
By usingattachmentOptions, you can set a list of custom MessageComposerActions for the CompactMessageComposer Component. This will override the existing list of MessageComposerActions.

- TypeScript
- css
AuxiliaryButtonView
You can insert a custom view into the CompactMessageComposer component to add additional functionality using the following method.The CompactMessageComposer Component utilizes the AuxiliaryButton to provide sticker and AI functionality. Overriding the AuxiliaryButton will subsequently replace the sticker functionality.
- TypeScript
SendButtonView
You can set a custom view in place of the already existing send button view.- TypeScript
- css
HeaderView
You can set custom headerView to the CompactMessageComposer component using the following method.- TypeScript
- css
TextFormatters
Assigns the list of text formatters. If the provided list is not null, it sets the list. Otherwise, it assigns the default text formatters retrieved from the data source. To configure the existing Mentions look and feel check out CometChatMentionsFormatter- ShortCutFormatter.ts
- TypeScript
Next Steps
Message Composer
Full-featured multi-line message composer component.
Message List
Display messages with real-time updates.
Mentions Formatter
Implement @mentions in your chat application.
Theme Customization
Customize colors, fonts, and styling.