Reference channels

Channel referencing lets users mention specific channel names in a chat conversation. They can do it by adding # and typing at least three first letters of the channel name they want to reference. As a result, they get a list of suggested names when typing such a suggestion, like #Sup.

The list of returned channels contains all channels in an app (channel data taken from the Admin Portal keyset for the app), regardless of whether the users are members of these channels. The number of returned suggested channels for reference also depends on the app configuration and can show up to 100 suggestions. The names of the suggested channels can consist of multiple words.

You can configure your app to let users refer up to 100 channels in a single message (default value is 10) and show references as links.

You can implement channel referencing in your app similarly to user @mentions.

Requires App Context

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

Send message with channel references

You can let users reference channels in a message by adding # and typing at least three first letters of the channel name they want to reference, like #Sup.

Method signature

Head over to the SendText() method for details.

Basic usage

Reference the general and genius-support (#gen) channels in a message.

val channel = chat.getChannel("your-channel")

val generalChannel = chat.getChannel("general")
val geniusSupportChannel = chat.getChannel("genius-support")

val referencedChannels = mapOf(
0 to MessageReferencedChannel(id = generalChannel.id, name = generalChannel.name),
1 to MessageReferencedChannel(id = geniusSupportChannel.id, name = geniusSupportChannel.name)
)

channel.sendText(
text = "I'm mentioning #general and #genius-support",
referencedChannels = referencedChannels
).async { result ->
result.onSuccess {
show all 22 lines

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:

message.referencedChannels

Basic usage

Check if the message with the 16200000000000000 timetoken contains any channel references.

val channel = chat.getChannel("your-channel")

channel.getMessage(16200000000000000).async { result ->
result.onSuccess { message: Message? ->
if (message != null) {
// access the referencedChannels property
val referencedChannels = message.referencedChannels

if (referencedChannels != null && referencedChannels.isNotEmpty()) {
println("The message contains the following referenced channels:")
referencedChannels.forEach { (position, refChannel) ->
println("Position: $position, Channel: ${refChannel.name}, ID: ${refChannel.id}")
}
} else {
println("The message does not contain any channel references.")
show all 23 lines
Last updated on