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.

testChannel.Join();
if(!chat.TryGetChannel("general", out var generalChannel)
|| !chat.TryGetChannel("genius-support", out var geniusSupportChannel))
{
return;
}
testChannel.SendText("I'm mentioning #general and #genius-support", new SendTextParams()
{
ReferencedChannels = new Dictionary<int, Channel>() {
{ 0, generalChannel },
{ 1, geniusSupportChannel }
}
});

Get channel suggestions

GetChannelSuggestions() returns all channels referenced in the sent 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

This method takes the following signature:

chat.GetChannelSuggestions(
string text,
int limit = 10
)

Input

ParameterTypeRequiredDefaultDescription
textstringYesn/aAt least a 3-letter string typed in after # with the channel name you want to reference.
limitintYes10Maximum number of returned channel names that match the typed 3-letter suggestion. The default value is set to 10, and the maximum is 100.

Output

TypeDescription
List<Channel>Returned array of Channel objects.

Basic usage

Return five channels that have names starting with Sup.

// try to get the "support" channel
if (chat.TryGetChannel("support", out Channel channel))
{
Console.WriteLine($"Found channel with name {channel.Name}");

// get channel suggestions from the chat object with names starting with "Sup" and limit to 5 results
var channelSuggestions = chat.GetChannelSuggestions("Sup", limit: 5);

// print out the suggested channel names
Console.WriteLine("Channel suggestions:");
foreach (Channel suggestedChannel in channelSuggestions)
{
Console.WriteLine(suggestedChannel.Name);
}
}
show all 19 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

Properties

PropertyTypeDescription
ReferencedChannelsList<Channel>List of all channels referenced in a message.

Basic usage

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

// reference the "support" channel
if (chat.TryGetChannel("support", out var channel))
{
Console.WriteLine($"Found channel with name {channel.Name}");

// get the message with the specified timetoken
if (channel.TryGetMessage("16200000000000000", out var message))
{
Console.WriteLine($"Message: {message.MessageText}");

// check if the message contains any channel references
if (message.ReferencedChannels != null && message.ReferencedChannels.Count > 0)
{
Console.WriteLine("The message contains channel references.");
foreach (var referencedChannel in message.ReferencedChannels)
show all 33 lines
Last updated on