Overview
MessageTemplate provides you with the capability to define and customize both the structure and the behavior of the Message Bubble. It acts as a schema or design blueprint for the creation of a variety of Message Bubble components, allowing you to manage the appearance and interactions of Message Bubble within your application effectively and consistently.Structure

- Leading view: This is where the sender’s avatar is displayed. It’s typically on the left of the Message Bubble for messages from others and on the right for messages from the current user.
- Header view: This displays the sender’s name and is especially useful in group chats where multiple users are sending messages.
- Reply view: This view can be used to extend the Message Bubble with additional elements. It’s typically placed above the Content view.
- Content view: This is the core of the Message Bubble where the message content (text, images, videos, etc.) is displayed.
- Bottom view: This view can be used to extend the Message Bubble with additional elements, such as link previews or a ‘load more’ button for long messages. It’s typically placed beneath the Content view.
- Thread view: This is where the thread reply icon and reply counts are displayed. It’s located below the footer view.
- Footer view: This is where the reactions are displayed. It’s located at the bottom of the Message Bubble.
- Status Info view: This is where the timestamp of the message and its delivery or read status are displayed. It’s located inside the Message Bubble just below the content view.
Properties
MessageTemplate provides you with methods that allow you to alter various properties of the Message Bubble. These properties include aspects such as thetype
and category
of a message, the appearance and behavior of the header, content, and footer sections of the message bubble,
-
type
Using
type
you can set the type of CometChatMessage, This will map your MessageTemplate to the corresponding CometChatMessage. You can set the MessageTemplates Type using the following code snippet. -
category
Using
category
you can set the category of a MessageTemplate. This will create a MessageTemplate with the specified category and link it with a CometChatMessage of the same category. Please refer to our guide on Message Categories for a deeper understanding of message categories. -
headerView
The
headerView
method allows you to assign a custom header view to the Message Bubble. By default, it is configured to display the sender’s name. -
contentView
The
contentView
method allows you to assign a custom content view to the Message Bubble. By default, it displays the Text Bubble, Image Bubble, File Bubble, Audio Bubble, or Video Bubble depending on the message type. -
footerView
The
footerView
method allows you to assign a custom Footer view to the Message Bubble. By default it shows thr reactions for the message bubble. -
bottomView
The
bottomView
method allows you to assign a custom Bottom view to the Message Bubble. By defuault is has buttons such as link previews or a ‘load more’ button for long messages. -
bubbleView
The
bubbleView
method allows you to assign a custom Bubble view to the Message Bubble. By default, headerView, contentView, statusInfoView and footerView together form a message bubble. -
statusInfoView
The
statusInfoView
method allows you to assign a custom status info view to the Message Bubble. By default, it displays the receipt and timestamp. -
options
The
options
lets you set the list of actions that a user can perform on a message. This includes actions like reacting to, editing, or deleting a message.
Customization
Let’s dive into how you can use the properties of MessageTemplate to customize an existing template or add a new one to the MessageList component. The first step is to fetch the list of existing templates when you want to modify or add to them. This can be done using the getAllMessageTemplates() method from the DataSource of the CometChatUIKit class.Existing Templates
You will need to first get the MessageTemplate object for the type of message you want to customize. You will be customizing the text message bubble here. The code snippet to get the Text MessageTemplate is as follows.templates
prop of CometChatMessageList
component.
HeaderView
TheheaderView
method of MessageTemplate allows you to add custom views to the header of your message bubbles. In the example below, we will add a custom header view of every text message in the MessageList.

Contentview
Thecontentview
method of MessageTemplate allows you to add a custom view to the content of your message bubbles. In the example below, we will add a custom layout to the content view of every text message in the MessageList.

BottomView
ThebottomView
method of MessageTemplate allows you to add a custom button view to your message bubbles. In the example below, we will add a custom bottom view to every text message in the MessageList.

FooterView
ThefooterView
method of MessageTemplate allows you to add a footer view to your message bubbles. In the example below, we will add a custom footer view to every text message in the MessageList.

BubbleView
ThebubbleView
method of MessageTemplate allows you to add a bubble view to your message bubbles. In the example below, we will add a custom bubble view to the text message in the MessageList.

StatusInfoView
ThestatusInfoView
method of MessageTemplate allows you to add a status info view to your message bubbles. In the example below, we will add a custom status info view to every text message in the MessageList.

Options
Theoptions
method in the MessageTemplate allows you to customize the options that appear in the action sheet when a message is long-pressed. By default, CometChat UI Kit provides a set of options like “Thread Reply”, “Copy” ,“Edit”, and “Delete”.
However, if you wish to override or modify these options, you can use the options
method and pass a list of CometChatActionsIcon
. This list of options will replace the default set.

New Templates
You can create an entirely new template for custom messages is one of the powerful features of CometChat’s MessageTemplate.