AI Integration Quick Reference
AI Integration Quick Reference
| Field | Value |
|---|---|
| Package | @cometchat/chat-uikit-react-native |
| Key class | CometChatTextFormatter (abstract base class for custom formatters) |
| Required setup | CometChatUIKit.init(UIKitSettings) then CometChatUIKit.login("UID") |
| Purpose | Extend to create custom inline text patterns with regex, styling, and callbacks |
| Features | Text formatting, customizable styles, dynamic text replacement, suggestion list integration |
| Sample app | GitHub |
| Related | ShortCut Formatter · Mentions Formatter · All Guides |
CometChatTextFormatter is an abstract class for formatting text in the message composer and message bubbles. Extend it to build custom formatters — hashtags, keywords, or any regex-based pattern.
| Capability | Description |
|---|---|
| Text formatting | Auto-format text based on regex patterns and styles |
| Custom styles | Set colors, fonts, and backgrounds for matched text |
| Suggestion list | Display suggestions when tracking character is typed |
| Message handling | Process messages before sending with handlePreMessageSend |
Base Class Overview
TheCometChatTextFormatter class provides the foundation for all text formatters in React Native:
Steps
1. Import the base class
2. Extend it
3. Implement formatting methods
OverridegetFormattedText to apply custom styling to matched patterns:
Example
A hashtag formatter used with CometChatMessageList and CometChatMessageComposer.- HashTagTextFormatter.tsx
- ChatScreen.tsx
Methods Reference
| Method | Description |
|---|---|
setTrackingCharacter(char) | Character that starts tracking (e.g. # for hashtags) |
setRegexPatterns(pattern) | Regex pattern to match text for formatting |
getFormattedText(inputText) | Returns formatted JSX from input text |
handlePreMessageSend(message) | Process message before sending |
search(searchKey) | Search function called when tracking character is typed |
fetchNext() | Fetch next page of suggestions |
setSearchData(data) | Set suggestion list data |
setSuggestionItems(items) | Set the suggestion items array |
getSuggestionItems() | Get current suggestion items |
setMessage(message) | Set the message object in context |
getMessage() | Get the current message object |
setUser(user) | Set the user in context |
setGroup(group) | Set the group in context |
setLoggedInUser(user) | Set the logged-in user |
setComposerId(id) | Set the composer ID for event handling |
setId(id) | Set unique identifier for the formatter |
Advanced: Suggestion List Integration
For formatters that need to show suggestions (like mentions), implement thesearch method: