Mention in Messages
The mention feature in chat can be used to call attention to specific members. By @mentioning their names, this will promptly notify them so you can get a faster response to your message.
You can mention members or a channel in text messages. Just specify the display name to mention. Up to 30 channel members can be mentioned per message.
You can fetch mention configurations and provide information about unread text messages with mention.
Mention is supported in these channel types:
Community
Live
Mention is not supported in the Conversation channel type.
AmityMessage
contains new properties related to mention feature:
mentionedUsers
- an array ofAmityUser
objects. It provides information of mentioned users in the current text message.metadata
- a dictionary which can contain any information about the current message. Our default structure to represent mentions is inside the metadata property. Customers can use any structure to represent mentions.AmityMessageMentionMetadata
is a helper class which can transform metadata into mentions and vice versa. This class uses our custom structure of representing mentions in text messages.mentionees
- an array ofAmityMentionees
objects.AmityMentionees
model represents the following information about mentions in the message:type: AmityMessageMentionType. The type of the current mention. This can either be
user
orchannel
.users: Nullable array of AmityUser. The users list who are mentioned in the current message. If
AmityMessageMentionType
ischannel
, this array will be empty.
The mentionees
array can contain a maximum of two objects because mention type can be only eitherchannel
or user
. Each object in the array represents information about a specific type of mention.
How mention works
You can define your own structure to represent mentions. To do this, you can use the metadata
property of AmityMessage
and store mentions in the metadata property. To represent mentions with our own structure, you need to use the AmityMessageMentionMetadata
helper class and AmityMention
class.
AmityMessageMentionMetadata
has two class member functions:
Member function | Description |
| Takes metadata dictionary as an argument and if it’s possible, then it gets mentions from metadata and returns an array of |
| Takes an array of |
How to use AmityMention
To represent mention with our structure, you must use the AmityMention
model array provided by AmityMessageMentionMetadata
’s mentionsFromMetadata
method.
AmityMention
model contains four properties:
type
:AmityMessageMentionType
- type of the mentionindex
:Integer
- start index of current mentionuserId
:String
- userId of the user being mentioned. If the type of the mention is channel, thenuserId
is undefined.length
:Integer
- length of the mention
The length property doesn’t include the “@“ mention sign. For example, “@all” mention’s length is 3.
How to create a mention with our structure
We create mentions in metadata to be able to represent mentions on different platforms(iOS, Android, and Web). Back-end won’t validate metadata property for message, but we need to provide amentionees
object to Back-end to be able to handle notifications.
AmityMentioneesBuilder
class helps build mentionees
object. It has two methods:
mentionChannel()
- builds mention with channelmentionUsers(userIds: [String])
- takes an array of userIds and builds mentions with type user and userIds
To create a text message with mentions, there is a new method in AmityMessageRepository
:
To update a text message and provide mention information, there is a new method in AmityMessageEditor
:
Create metadata and mentionees
objects. Send a text message with mentions.
How to update mentions for a text message
Mention Configurations
Mention channel can be turned off. It means that you cannot mention that specific channel. To get configurations for mention channel, you must use AmityClient
’s mentionConfigurations
property which is the AmityMentionConfigurations
object.
AmityMentionConfigurations
has the isMentionAllEnabled
property which is an indicator whether you can mention the channel or not.
Search members
To search members when mentioning, you must use AmityChannelParticipation
’s searchMembers
function:
The above function takes the following parameters to make a search:
searchMembers - display name or user ID of the member being searched
filterBuilder - to help build a filter for filtering search results
roles
It will return AmityCollection
of AmityChannelMember
.
You can filter search results with more than one option. For example, filter by muted and banned users. AmityChannelMembershipFilterBuilder
has this method:
This function takes the AmityChannelMembershipSearchFilter
type as an argument. Search results are ordered by last created.
AmityChannelMembershipSearchFilter
is an enum which has three cases:
member
- Standard membermute
- Muted memberban
- Banned member
Usage:
This code will return AmityCollection
of AmityChannelMember
which contains only banned and muted users.
Unread mention count
When a member is mentioned(mention type could be channel as well) in a text message and the message is not read, then hasMention
property is "true" in AmityChannel
class. Everytime the hasMention
property is true, this means that the member has an unread message with mention(message could be created or updated as well).
Mentioning banned users
Banned users cannot be mentioned. However, admins can still find the banned users' names in the suggestion list during search when composing the message. But once the message is sent, the banned users’ information will not be included in the message payload anymore.
Banned users will not be notified nor receive any push notification.
Users who are not admins will not be able to search for the banned users' names as the latter will not appear in the suggestion list.
Mention notifications
When users are being mentioned, they will receive push notifications. You can customize the push notification content such as the title and the body using the notification setting API.
Provide the notification title and body in the titleTemplate
and bodyTemplate
parameters respectively. Here is a sample model:
Name | Data Type | Description |
---|---|---|
|
| Event name |
|
| If set to |
|
| Notification title |
|
| Notification body |
Last updated