Documentation Index Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
AI Integration Quick Reference
Field Value Packages com.cometchat:chatuikit-kotlin · com.cometchat:chatuikit-jetpackKey class ShortCutFormatter (extends CometChatTextFormatter)Required setup CometChatUIKit.init() then CometChatUIKit.login("UID")Track character ! — triggers shortcut expansion in the message composerExtension message-shortcuts CometChat extension must be enabledSample app GitHub Related Mentions Formatter | All Guides
ShortCutFormatter extends CometChatTextFormatter to expand shortcodes (like !hi) into full text via the Message Shortcuts extension. When a user types a shortcut trigger in the composer, a suggestion appears with the expansion — selecting it inserts the text.
Steps
Extend CometChatTextFormatter with '!' as the tracking character:
class ShortCutFormatter : CometChatTextFormatter ( '!' ) {
private val messageShortcuts: HashMap < String , String > = HashMap ()
private val shortcuts: MutableList < SuggestionItem > = ArrayList ()
init {
prepareShortCuts ()
}
}
2. Fetch shortcuts from the extension
private fun prepareShortCuts () {
CometChat. callExtension (
"message-shortcuts" , "GET" , "/v1/fetch" , null ,
object : CometChat . CallbackListener < JSONObject >() {
override fun onSuccess (responseObject: JSONObject ) {
try {
val shortcutObject = responseObject
. getJSONObject ( "data" ). getJSONObject ( "shortcuts" )
val keysItr = shortcutObject. keys ()
while (keysItr. hasNext ()) {
val key = keysItr. next ()
messageShortcuts[key] = shortcutObject. getString (key)
}
} catch (e: JSONException ) { e. printStackTrace () }
}
override fun onError (e: CometChatException ) {}
})
}
3. Override the search method
Match user input against stored shortcuts and update the suggestion list:
override fun search (context: Context , queryString: String ?) {
val query = trackingCharacter. toString () + queryString
shortcuts. clear ()
if (messageShortcuts. containsKey (query)) {
val suggestionItem = SuggestionItem (
"" , " $query => ${ messageShortcuts[query] } " ,
null , null , messageShortcuts[query], null , null
)
suggestionItem.isHideLeadingIcon = true
shortcuts. add (suggestionItem)
}
setSuggestionItemList (shortcuts)
}
override fun onScrollToBottom () {
// No pagination needed for shortcuts
}
5. Integrate with MessageComposer
Kotlin (XML Views)
Jetpack Compose
Add the XML element to your layout: < com.cometchat.uikit.kotlin.presentation.messagecomposer.ui.CometChatMessageComposer
android:id = "@+id/composer"
android:layout_width = "match_parent"
android:layout_height = "match_parent" />
Then add the formatter to the composer: import com.cometchat.uikit.core.CometChatUIKit
val cometChatMessageComposer: CometChatMessageComposer = findViewById (R.id.composer)
val cometChatTextFormatters = CometChatUIKit. getDataSource (). getTextFormatters ( this , cometChatMessageComposer.additionParameter)
cometChatTextFormatters. add ( ShortCutFormatter ())
cometChatMessageComposer. setTextFormatters (cometChatTextFormatters)
import com.cometchat.uikit.core.CometChatUIKit
// In your composable or ViewModel setup
val textFormatters = CometChatUIKit. getDataSource (). getTextFormatters (context, additionParameter)
textFormatters. add ( ShortCutFormatter ())
CometChatMessageComposer (
user = user,
textFormatters = textFormatters
)
Typing ! followed by a valid shortcut key (e.g., !hi) displays a suggestion with the expanded text. Selecting it inserts the expansion into the composer.
Next Steps
Message Composer Configure the composer where ShortCutFormatter is integrated
Mentions Formatter Format @mentions with styled tokens and click handling
All Guides Browse all feature and formatter guides
Sample App Full working sample application on GitHub