AI Agent Component Spec
AI Agent Component Spec
Overview
CometChatMentionsFormatter formats @mentions in text messages. It styles mention tokens, generates suggestion lists as users type, and handles click events on rendered mentions.
Time estimate: 10 minutesDifficulty: Intermediate
Prerequisites
- React.js integration completed
- Custom Formatters guide reviewed
Steps
Step 1: Import the formatter
Step 2: Initialize with users
Set up the formatter with a list of mentionable users:Step 3: Pass to components
Use thetextFormatters prop on message components:
Step 4: Format existing messages
Apply formatting to raw message text:Complete Example
Capabilities
| Feature | Description |
|---|---|
| Mention formatting | Auto-formats <@uid:...> placeholders into styled tokens |
| Custom styles | Colors, fonts, and backgrounds for mention text |
| User and group mentions | Works with both individual users and group members |
| Suggestion list | Generates mention candidates from user input |
| Click handling | Listener interface for tap/click on rendered mentions |
Common Issues
| Issue | Solution |
|---|---|
| No suggestions appearing | Verify users are set via setCometChatUserGroupMembers() |
| Mentions not styled | Check formatter is passed to textFormatters prop |
| Wrong users in suggestions | Update user list when group membership changes |