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

- Leading widget: This is where the sender’s avatar is displayed. It’s typically on the left of the MessageBubble for messages from others and on the right for messages from the current user.
- Header widget: This displays the sender’s name and is especially useful in group chats where multiple users are sending messages.
- Content widget: This is the core of the MessageBubble where the message content (text, images, videos, etc.) is displayed.
- Bottom widget: This widget can be used to extend the MessageBubble with additional elements, such as link previews or a ‘load more’ button for long messages. It’s typically placed beneath the Content widget.
- Footer widget: This is where the timestamp of the message and its delivery or read status are displayed. It’s located at the bottom of the MessageBubble.
Properties
MessageTemplate provides you with methods that allow you to alter various properties of the MessageBubble. 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 MessageTemplate 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. -
Header Widget
The.
headerView
property allows you to assign a custom header widget to the MessageBubble. By default, it is configured to display the sender’s name. -
Content Widget
The
contentView
method allows you to assign a custom content widget to the MessageBubble. By default, it displays the Text Bubble, Image Bubble, File Bubble, Audio Bubble, or Video Bubble, depending on the message type. -
Footer Widget
The
footerView
property allows you to assign a custom Footer widget to the MessageBubble. By default, it displays the receipt and timestamp. -
Bottom Widget
The
bottomView
property allows you to assign a custom Bottom widget to the MessageBubble.By defuault is has buttons such as link previews or a ‘load more’ button for long messages. -
Bubble Widget
The
bubbleView
property allows you to assign a custom Bubble widget to the MessageBubble. By default, headerView, contentView, and footerView together form a message bubble. -
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 Widget.Header widget
TheheaderView
method of MessageTemplate allows you to add custom widgets to the header of your message bubbles.
Here is the complete example for reference:

Content widget
ThecontentView
method of MessageTemplate allows you to add a custom widget to the content of your message bubbles.
Here is the complete example for reference:

Bottom Widget
ThebottomView
property of MessageTemplate allows you to add a custom button widget to your message bubbles.
Here is the complete example for reference:

Footer Widget
ThefooterView
property of MessageTemplate allows you to add a footer widget to your message bubbles.
Here is the complete example for reference:

Bubble Widget
ThebubbleView
property of MessageTemplate allows you to add a bubble widget to your message bubbles.
Here is the complete example for reference:

Options List
Theoptions
property 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 “Reply”, “Edit”, and “Delete”.
However, if you wish to override or modify these options, you can use the options
method and pass a list of CometChatMessageOption
. This list of options will replace the default set.
Here is the complete example for reference:

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