AI Integration Quick Reference
AI Integration Quick Reference
#word patterns and renders them as highlighted, styled tokens. The formatter works across all text surfaces: the message composer (live as you type), message bubbles, conversation subtitle (last message preview), and the message edit view.
How It Works
- User types
#angularin the composer. - On space or enter, the formatter wraps the hashtag in a styled
<span>. - When the message is sent, the raw text (
#angular) is stored in the message body. - When the message is rendered in the message list, conversation list, or edit view, the formatter re-applies the highlight.
textFormatters input on cometchat-message-list, cometchat-message-composer, and cometchat-conversations.
Prerequisites
- Angular UIKit installed and initialized (Integration Guide)
- A logged-in CometChat user
- Basic understanding of the Custom Text Formatter pattern
Step 1: Create the Formatter Class
Create a filehashtag-formatter.ts in your project:
priority = 15places it after the URL formatter (10) but before mentions (20), so URLs inside hashtags aren’t broken.- The regex
\B#(\w{1,50})\bmatches#preceded by a non-word boundary, followed by 1–50 word characters. This avoids matching#in URLs or hex colors. - The
<span>usesvar(--cometchat-primary-color)so it respects the active theme.
Step 2: Use in Message List and Composer
Pass the formatter to both the message list (for rendering) and the composer (for live preview and edit view):textFormatters input accepts an array. The UIKit merges your custom formatters with the built-in ones (URL, mentions, emoji, markdown) and applies them in priority order.
Step 3: Use in Conversations (Last Message Preview)
To highlight hashtags in the conversation list’s last message subtitle, pass the same formatter tocometchat-conversations:
#angular in the last message preview renders with the same highlight styling.
Step 4: Style the Hashtag
The inlinestyle attribute handles the base color, but you can add a global CSS rule for more control:
styles.css or styles.scss.
Step 5: Handle Hashtag Clicks (Optional)
To make hashtags interactive (e.g., filter messages by tag), extend the formatter to emit click events:.cometchat-hashtag elements:
Complete Example
A full two-panel layout with hashtag formatting across all surfaces:Where Hashtags Appear
The raw message text stored on the server is always plain text (e.g.,
Check out #angular). Formatting is applied at render time by the formatter pipeline. This means hashtag highlighting works retroactively on older messages too.Next Steps
Custom Text Formatter
Learn the full formatter API and lifecycle.
Mentions Formatter
Add @mentions with suggestion lists.
Message Composer
Customize the message input component.
All Guides
Browse all feature and formatter guides.