Reference channels
Channel referencing lets users mention channels in messages by typing # followed by at least three letters. Matching channel names appear as suggestions.
Generic referencing
Channel references, user mentions, and links are MessageElement instances with different MentionTarget types.
Suggestions include all channels in the app keyset (up to 100), regardless of user membership. Configure up to 100 channel references per message (default: 10) and display them as links.
Implementation is similar to user mentions and links.
Requires App Context
Enable App Context for your keyset in the Admin Portal.
Add channel references
Add channel references with # followed by at least three letters of the channel name (e.g., #Sup).
Method signature
You can add a channel reference by calling the AddMention() method with the target of MentionTarget.Channel.
Refer to the addMention() method for details.
Sample code
Create the Hello Alex! I have sent you this link on the #offtopic channel. message where #offtopic is a channel reference.
1
Remove channel references
RemoveMention() lets you remove a previously added channel reference from a draft message.
Method signature
You can remove channel references from a draft message by calling the RemoveMention() method at the exact offset where the channel reference 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
Remove the channel reference from the Hello Alex! I have sent you this link on the #offtopic channel. message where #offtopic is a channel reference.
1
Get channel suggestions
The event handler you attached to the OnDraftUpdated event returns all channels referenced in the draft message that match the provided 3-letter string from your app's keyset.
For example, if you type #Sup, you will get the list of channels starting with Sup like Support or Support-Agents. The default number of returned suggested channel names is 10, configurable to a maximum value of 100.
Method signature
You must handle the event to update to the contents of a message draft, as well as retrieve the current message elements suggestions for user mentions, channel reference, and links. For example, when the message draft contains ... @name ... or ... #chann ....
Enable receiving suggested mentions
You must enable receiving suggested mentions by setting messageDraft.ShouldSearchForSuggestions = true; before introducing your event handler.
Refer to the Add a message draft listener section for details.
Sample code
Insert the first suggested mention whenever the draft is updated and mentions are detected.
1
Get referenced channels
You can access the ReferencedChannels property of the Message object to return all channel names referenced in a message.
Method signature
This is how you can access the property:
1message.ReferencedChannels
Properties
| Property | Description |
|---|---|
ReferencedChannelsType: List<ReferencedChannel> | List of all channels referenced in a message. |
Sample code
Check if the message with the 16200000000000000 timetoken contains any channel references.
1