AI Integration Quick Reference
AI Integration Quick Reference
| Field | Value |
|---|---|
| Packages | com.cometchat:chatuikit-kotlin · com.cometchat:chatuikit-jetpack |
| Key class | CometChatMentionsFormatter (extends CometChatTextFormatter) |
| Required setup | CometChatUIKit.init() then CometChatUIKit.login("UID") |
| Purpose | Format @mentions with styled tokens, suggestion list, and click handling for users and group members |
| Sample app | GitHub |
| Related | ShortCut Formatter | All Guides |
CometChatMentionsFormatter extends CometChatTextFormatter to format @mentions in text messages. It styles mention tokens, generates suggestion lists as users type, and handles click events on rendered mentions across the message composer, message bubbles, and conversations list.
| Capability | Description |
|---|---|
| Mention formatting | Auto-formats mention placeholders into styled spans |
| Custom styles | Colors, fonts, and backgrounds per context (composer, bubbles, conversations) |
| User and group mentions | Works with both individual users and group members |
| Suggestion list | Generates mention candidates from user input |
| Click handling | Listener interface for tap on rendered mentions |
Usage
1. Create the formatter
- Kotlin (XML Views)
- Jetpack Compose
2. Add to a formatters list
3. Pass to a component
UsesetTextFormatters() on CometChatMessageComposer, CometChatMessageList, or CometChatConversations.
- Kotlin (XML Views)
- Jetpack Compose
Styling Mentions
Mention Click Handling
Set a click listener for mentions in message bubbles:
- Kotlin (XML Views)
- Jetpack Compose
Composer Mention Style
Customize how mentions appear in the message composer input field:
themes.xml
- Kotlin (XML Views)
- Jetpack Compose
Message Bubble Mention Style
Customize mentions in incoming and outgoing message bubbles:
themes.xml
- Kotlin (XML Views)
- Jetpack Compose
Conversations Mention Style
Customize mentions in the conversations list last-message preview:
themes.xml
- Kotlin (XML Views)
- Jetpack Compose
Customization Matrix
| What you want to change | Where | Property/API | Example |
|---|---|---|---|
| Maximum number of mentions allowed | CometChatMentionsFormatter | setMentionLimit(int limit) | mentionFormatter.setMentionLimit(5) |
| Group members fetched for mention suggestions | CometChatMentionsFormatter | .setGroupMembersRequestBuilder(...) | .setGroupMembersRequestBuilder(group -> GroupMembersRequest.GroupMembersRequestBuilder(group.guid)) |
| Users fetched for mention suggestions | CometChatMentionsFormatter | .setUsersRequestBuilder(...) | .setUsersRequestBuilder(UsersRequest.UsersRequestBuilder().friendsOnly(true)) |
| Who can be mentioned | CometChatMentionsFormatter | .setMentionsType(...) | .setMentionsType(UIKitConstants.MentionsType.USERS_AND_GROUP_MEMBERS) |
| Where mentions are visible | CometChatMentionsFormatter | .setMentionsVisibility(...) | .setMentionsVisibility(UIKitConstants.MentionsVisibility.BOTH) |
| Click action on a mention | CometChatMentionsFormatter | setOnMentionClick | mentionFormatter.setOnMentionClick { context, user -> } |
| Mention text style in composer | CometChatMentionsFormatter | setMessageComposerMentionTextStyle(context, styleRes) | mentionFormatter.setMessageComposerMentionTextStyle(context, R.style.CustomStyle) |
| Mention text style in outgoing bubbles | CometChatMentionsFormatter | setOutgoingBubbleMentionTextStyle(context, styleRes) | mentionFormatter.setOutgoingBubbleMentionTextStyle(context, R.style.CustomStyle) |
| Mention text style in incoming bubbles | CometChatMentionsFormatter | setIncomingBubbleMentionTextStyle(context, styleRes) | mentionFormatter.setIncomingBubbleMentionTextStyle(context, R.style.CustomStyle) |
| Mention text style in conversations list | CometChatMentionsFormatter | setConversationsMentionTextStyle(context, styleRes) | mentionFormatter.setConversationsMentionTextStyle(context, R.style.CustomStyle) |
Next Steps
Message Composer
Configure the composer where users type and send messages with mentions
Message List
Configure the message list where mention-styled bubbles are displayed
Conversations
Configure the conversations list where mention-styled previews appear
ShortCut Formatter
Add shortcut text expansion to the message composer