Skip to main content
This guide walks you through building a custom CometChatTextFormatter that detects #hashtags in messages, highlights them, and shows a suggestion dropdown in the composer.

Prerequisites

Step 1: Create the Formatter Class

Extend CometChatTextFormatter and set the tracking character to #:
The search method is called whenever the user types after the tracking character. Filter your data and set the suggestion list:

Step 3: Handle Suggestion Selection

When the user taps a suggestion, insert the hashtag into the composer:

Step 4: Style Hashtags in Message Bubbles

Override buildMessageBubbleSpan to apply styling to hashtags when they appear in sent/received messages:

Step 5: Pre-Send Hook (Optional)

Modify the message before it’s sent — for example, attach hashtag metadata:

Step 6: Register the Formatter

Pass your formatter to the components that should use it:

Complete Example