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 Package Custom class extending com.cometchat.chatuikit.shared.formatters.CometChatTextFormatter Key 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 ShortCutFormatterKotlin : CometChatTextFormatter ( '!' ) {
private val messageShortcuts: HashMap < String , String > = HashMap ()
private val shortcuts: MutableList < SuggestionItem > = ArrayList ()
init {
prepareShortCuts ()
}
}
public class ShortCutFormatter extends CometChatTextFormatter {
private HashMap < String , String > messageShortcuts ;
private List < SuggestionItem > shortcuts ;
public ShortCutFormatter () {
super ( '!' );
messageShortcuts = new HashMap <>();
shortcuts = new ArrayList <>();
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 ) {}
})
}
private void prepareShortCuts () {
CometChat . callExtension ( "message-shortcuts" , "GET" , "/v1/fetch" , null ,
new CometChat . CallbackListener < JSONObject >() {
@ Override
public void onSuccess ( JSONObject responseObject ) {
try {
JSONObject shortcutObject = responseObject
. getJSONObject ( "data" ). getJSONObject ( "shortcuts" );
Iterator < String > keysItr = shortcutObject . keys ();
while ( keysItr . hasNext ()) {
String key = keysItr . next ();
messageShortcuts . put (key, shortcutObject . getString (key));
}
} catch ( JSONException e ) { e . printStackTrace (); }
}
@ Override
public void onError ( CometChatException e ) {}
});
}
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
public void search (@ NonNull Context context, String queryString) {
String query = getTrackingCharacter () + queryString;
shortcuts . clear ();
if ( messageShortcuts . containsKey (query)) {
SuggestionItem suggestionItem = new SuggestionItem (
"" , query + " => " + messageShortcuts . get (query),
null , null , messageShortcuts . get (query), null , null );
suggestionItem . setHideLeadingIcon ( true );
shortcuts . add (suggestionItem);
}
setSuggestionItemList (shortcuts);
}
override fun onScrollToBottom () {
// No pagination needed for shortcuts
}
@ Override
public void onScrollToBottom () {
// No pagination needed for shortcuts
}
5. Integrate with MessageComposer
Add the XML element to your layout:
< com.cometchat.chatuikit.messagecomposer.CometChatMessageComposer
android:id = "@+id/composer"
android:layout_width = "match_parent"
android:layout_height = "match_parent" />
Then add the formatter to the composer:
val cometChatMessageComposer: CometChatMessageComposer = findViewById (R.id.composer)
val cometChatTextFormatters = CometChatUIKit. getDataSource (). getTextFormatters ( this , cometChatMessageComposer.additionParameter)
cometChatTextFormatters. add ( ShortCutFormatterKotlin ())
cometChatMessageComposer. setTextFormatters (cometChatTextFormatters)
CometChatMessageComposer cometChatMessageComposer = findViewById ( R . id . composer );
List < CometChatTextFormatter > cometChatTextFormatters = CometChatUIKit . getDataSource (). getTextFormatters ( this , cometChatMessageComposer . getAdditionParameter ());
cometChatTextFormatters . add ( new ShortCutFormatter ());
cometChatMessageComposer . setTextFormatters (cometChatTextFormatters);
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