Skip to main content

What It Is

CometChatMessageTemplate is a model class, not a rendered component. Each instance maps a message type + category pair to a set of view functions that control how that message renders inside CometChatMessageList. Pass an array of templates to the templates prop on CometChatMessageList.

Template Structure

A message bubble is composed of these view slots, each overridable per template:
ViewDefault renderingSignature
headerViewSender name(message: CometChat.BaseMessage, alignment: MessageBubbleAlignment, textFormatters?: CometChatTextFormatter[]) => JSX.Element | null
contentViewText / image / video / audio / file bubble(message: CometChat.BaseMessage, alignment: MessageBubbleAlignment, textFormatters?: CometChatTextFormatter[]) => JSX.Element | null
footerViewReactions(message: CometChat.BaseMessage, alignment: MessageBubbleAlignment) => JSX.Element | null
bottomViewLink previews, “load more”(message: CometChat.BaseMessage, alignment: MessageBubbleAlignment) => JSX.Element | null
statusInfoViewReceipt + timestamp(message: CometChat.BaseMessage, alignment: MessageBubbleAlignment, hideReceipts?: boolean, messageSentAtDateTimeFormat?: CalendarObject, showError?: boolean) => JSX.Element | null
replyViewReply preview(message: CometChat.BaseMessage, alignment?: MessageBubbleAlignment, onReplyViewClicked?: (msg: CometChat.BaseMessage) => void, textFormatters?: CometChatTextFormatter[]) => JSX.Element | null
bubbleViewEntire bubble (overrides all above)(message: CometChat.BaseMessage, alignment: MessageBubbleAlignment) => JSX.Element | null
optionsLong-press action sheet(loggedInUser: CometChat.User, message: CometChat.BaseMessage, group?: CometChat.Group) => CometChatMessageOption[]

Fetching Existing Templates

Retrieve the built-in templates and modify specific ones:

Common Patterns

Custom header with status badge

Custom content view for a custom message type

Custom bottom view with warning

Replace entire bubble

Custom action sheet options

New template for a custom message type


Styling

CometChatMessageTemplate renders inside .cometchat-message-bubble. Style individual bubble sections using CSS:

Properties

bubbleView

KeyValue
Type((message: CometChat.BaseMessage, alignment: MessageBubbleAlignment) => Element | JSX.Element | null) | null
Defaultnull
Replaces the entire message bubble. When set, headerView, contentView, footerView, bottomView, statusInfoView, and replyView are ignored for that template.

bottomView

KeyValue
Type((message: CometChat.BaseMessage, alignment: MessageBubbleAlignment) => Element | JSX.Element | null) | null
Defaultnull
Custom bottom section below the content area. Default renders link previews or “load more” for long messages.

category

KeyValue
Typestring
Default""
Maps the template to a CometChat message category (e.g., CometChatUIKitConstants.MessageCategory.message, CometChatUIKitConstants.MessageCategory.custom).

contentView

KeyValue
Type((message: CometChat.BaseMessage, alignment: MessageBubbleAlignment, textFormatters?: CometChatTextFormatter[]) => Element | JSX.Element | null) | null
Defaultnull
Custom content area. Default renders text, image, video, audio, or file bubble based on message type.

footerView

KeyValue
Type((message: CometChat.BaseMessage, alignment: MessageBubbleAlignment) => Element | JSX.Element | null) | null
Defaultnull
Custom footer below the content area. Default renders reactions.

headerView

KeyValue
Type((message: CometChat.BaseMessage, alignment: MessageBubbleAlignment) => Element | JSX.Element | null) | null
Defaultnull
Custom header above the content area. Default renders sender name.

options

KeyValue
Type(loggedInUser: CometChat.User, message: CometChat.BaseMessage, group?: CometChat.Group) => CometChatMessageOption[]
DefaultSDK default options
Returns the list of action sheet items for long-press on a message bubble.

replyView

KeyValue
Type((message: CometChat.BaseMessage, alignment?: MessageBubbleAlignment, onReplyViewClicked?: (msg: CometChat.BaseMessage) => void, textFormatters?: CometChatTextFormatter[]) => Element | JSX.Element | null) | null
Defaultnull
Custom reply preview above the content area.

statusInfoView

KeyValue
Type((message: CometChat.BaseMessage, alignment: MessageBubbleAlignment, hideReceipts?: boolean, messageSentAtDateTimeFormat?: CalendarObject, showError?: boolean) => Element | JSX.Element | null) | null
Defaultnull
Custom status info area. Default renders receipt icon and timestamp.

type

KeyValue
Typestring
Default— (required)
Maps the template to a CometChat message type (e.g., CometChatUIKitConstants.MessageTypes.text, CometChatUIKitConstants.MessageTypes.image).