Mention Support: User mentions are supported in posts, comments, and messages. Channel mentions are available in messages only.
Key Features
User Mentions
Tag specific users with @username notation for direct engagement
Channel Mentions
Mention entire channels to notify all members (messages only)
Smart Notifications
Automatic push notifications alert mentioned users instantly
Flexible Structure
Customizable mention data structure for advanced use cases
Where Mentions Work
Posts
Mention users in community posts to boost engagement and start conversations
Comments
Tag users in comment threads for focused discussions
Messages
Direct mentions in chat messages, including channel-wide mentions
-
mentionUsers(userIds)
- In order to mention users and notify specific users. This function supports all mentionable models. -
mentionChannel(channelId)
- In order to mention and notify the whole channel. This function supports only a message model. -
metadata
- a free-form JSON object that can accommodate any information regarding the mentioned users. Our default structure for representing mentions is also in the metadata property.
Default Mention Data Structure
To represent mentions using our structure, you will need to utilize the AmityMention object. This object can be created during mentionable model creation, as well as during rendering.Tag specific users in posts and comments with @username notation.
Mention Properties
Mention Properties
Property | Type | Description |
---|---|---|
type | enum | Always "user" for user mentions |
index | number | Start index of the mention in text |
userId | string | ID of the mentioned user |
length | number | Length of the mention text (excluding ”@” symbol) |
Index Calculation: The
length
property doesn’t include the ”@” symbol. For “@alice”, the length is 5, not 6.Creating Mention Metadata
Below is an example to create a comment with mentions by using our default mention metadata structure:Parsing and Displaying Mentions
As we mentioned we provided the flexibility for you to define your own mention object data structure to represent mentions. You can use the default data structure provided by the SDK to render mentions in your application, which can be accessed through the helper class. This allows you to easily retrieve mentions and render them. The mentionable model contains properties related to the mentioned feature:-
mentionUsers
- The AmityUser object array contains details about users mentioned in the current content. -
metadata
- a free-form JSON object that can accommodate any information regarding the mentioned users. Our predefined structure for representing mentions is also in the metadata property.
Best Practices
Do's
Validation & Data Integrity
Validation & Data Integrity
- Validate mention data before submitting content
- Verify user IDs exist before creating mentions
- Check text positions match mention metadata
- Sanitize user input to prevent mention abuse
User Experience
User Experience
- Provide visual feedback for mentions in UI
- Make mentions clickable for better navigation
- Show autocomplete suggestions during typing
- Handle mention notifications appropriately
Performance
Performance
- Cache user data for mention suggestions
- Debounce search queries for better performance
- Limit suggestion results to reasonable numbers
- Index mention text for fast searching
Don'ts
Spam Prevention
Spam Prevention
- Don’t mention users excessively - respect user attention
- Don’t allow mention spam - implement rate limiting
- Don’t mention in irrelevant contexts - keep mentions contextual
- Don’t ignore user preferences - respect notification settings
Security & Privacy
Security & Privacy
- Don’t expose private information in mention metadata
- Don’t allow mentions of blocked users - check relationships
- Don’t mention without permission in private channels
- Don’t store sensitive data in mention metadata
Technical Issues
Technical Issues
- Don’t forget mention click handlers in your UI
- Don’t ignore mention parsing errors - handle gracefully
- Don’t hard-code mention styling - make it customizable
- Don’t skip mention validation - always verify data
Troubleshooting
Mentions not triggering notifications
Mentions not triggering notifications
Common causes:
- Missing
mentionUsers
array in the parameter - Invalid user IDs in the mention list
- User has disabled mention notifications
- Network connectivity issues
Mention highlighting not working
Mention highlighting not working
Common causes:
- Incorrect mention positions in metadata
- Missing mention parsing in UI components
- CSS styling issues
- Metadata not matching actual text
Performance issues with mention input
Performance issues with mention input
Common causes:
- No debouncing on search queries
- Loading too many user suggestions
- Inefficient mention parsing
- Memory leaks in component state
Mention data inconsistency
Mention data inconsistency
Common causes:
- Text modifications after mention creation
- Incorrect index calculations
- Unicode character handling issues
- Concurrent text editing