On this page

Mention users

Tag users in chat messages with @ mentions. Type @ followed by at least three letters to see username suggestions.

Generic referencing

Channel references, user mentions, and links are instances of MessageElement with different MentionTarget types.

Configuration options:

  • User source: channel members or all app users
  • Suggestions: up to 100 usernames (default: 10)
  • Username length: up to 200 characters
  • Mentions per message: up to 100 (default: 10)

Implementation follows similar patterns to channel referencing and links.

Requires App Context

To mention users from a keyset, you must enable App Context for your app's keyset in the Admin Portal.

Add user mentions

Add user mentions with @ followed by at least three letters (e.g., @Mar).

Mentioned users are stored in the MessageDraft object. When sent with send(), mention data is saved to message metadata.

Method signature

You can add a user reference by calling the addMention() method with the target of MentionTarget.user.

Refer to the addMention() method for details.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Create the Hello Alex! I have sent you this link on the #offtopic channel. message where Alex is a user mention.

1

Remove user mentions

removeMention() removes a user mention from a draft message.

Method signature

You can remove user mentions from a draft message by calling the removeMention() method at the exact offset where the user mention starts.

Refer to the removeMention() method for details.

Offset value

If you don't provide the position of the first character of the message element to remove, it isn't removed.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Remove the user mention from the Hello Alex! I have sent you this link on the #offtopic channel. message where Alex is a user mention.

1

Get user suggestions

The message elements listener returns users matching a 3-letter string from channel members or global users.

icon

Single listener


Example: typing Sam returns Samantha, Samir, etc. Default limit: 10 users (max: 100).

Method signature

You must add a message elements listener to receive user suggestions.

Refer to the addChangeListener() method for details.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Create a message draft and add a change listener to listen for user mentions.

1

Get mentioned users

getMessageElements() returns all users mentioned in a message.

Method signature

This method has the following signature:

1message.getMessageElements()

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Check if the message contains any mentions.

1

getCurrentUserMentions() retrieves all instances where the current user was mentioned in channels or threads. Use this to build a mentions feed.

Method signature

This method has the following signature:

1chat.getCurrentUserMentions(
2 startTimetoken: Timetoken? = nil,
3 endTimetoken: Timetoken? = nil,
4 count: Int = 100
5) async throws -> (mentions: [UserMentionDataWrapper<MessageImpl>], isMore: Bool)

Input

* required
ParameterDescription
startTimetoken
Type: Timetoken
Default:
n/a
Timetoken delimiting the start of a time slice (exclusive) to pull messages with mentions from. For details, refer to the Fetch History section.
endTimetoken
Type: Timetoken
Default:
n/a
Timetoken delimiting the end of a time slice (inclusive) to pull messages with mentions from. For details, refer to the Fetch History section.
count
Type: Int
Default:
100
Number of historical messages with mentions to return in a single call. Since each call returns all attached message actions by default, the maximum number of returned messages is 100. For more details, refer to the description of the includeMessageActions parameter in the Swift SDK docs.

Output

ParameterDescription
(mentions: [UserMentionDataWrapper<MessageImpl>], isMore: Bool)
Type: object
Returned object containing two fields: mentions and isMore.
 → enhancedMentionsData
Type: enhancedMentionsData (ChannelMentionData or ThreadMentionData)
Array listing the requested number of historical mention events with a set of information that differ slightly depending on whether you were mentioned in the main (parent) channel or in a thread.

For mentions in the parent channel, the returned ChannelMentionData includes these fields: event (of type Event<EventContent.Mention>), channelId where you were mentioned, message that included the mention, userId that mentioned you.

For mentions in threads, the returned ThreadMentionData includes similar fields, the only difference is that you'll get parentChannelId and threadChannelId fields instead of just channelId to clearly differentiate the thread that included the mention from the parent channel in which this thread was created.
 → isMore
Type: Bool
Info whether there are more historical events to pull.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

List the last ten mentions for the current chat user.

1

Show notifications for mentions

listenForEvents() monitors mention events in channels and threads you're a member of. Use this to trigger pop-up notifications.

Events documentation

To read more about the events of type Mention, refer to the Chat events documentation.

Method signature

This method has the following parameters:

1chat.listenForEvents<T: EventContent>(
2 type: T.Type,
3 channelId: String,
4 customMethod: EmitEventMethod = .publish,
5 ) -> AsyncStream<EventWrapper<T>>
Input
* required
ParameterDescription
type *
Type: T.Type
Default:
n/a
Type parameter allowing access to type information at runtime.
channelId *
Type: String
Default:
n/a
Channel to listen for new Mention events.
customMethod
Type: EmitEventMethod
Default:
n/a
An optional custom method for emitting events. If not provided, defaults to .publish. Available values: .publish and .signal.
Output
ParameterDescription
AsyncStream<EventWrapper<T>
An asynchronous stream that emits a value each time a new event of the specified type is detected.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Print a notification for a mention of the current chat user on the support channel.

1

Get mentioned users (deprecated)

mentionedUsers property returns all users mentioned in a message.

Method signature

This is how you can access the property:

1message.mentionedUsers
Last updated on