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.

func referenceChannelsExample(chat: ChatImpl) {  
/// Define the channels to be referenced
var referencedChannels = MessageReferencedChannels()
referencedChannels[0] = MessageReferencedChannel(id: "general", name: "general")
referencedChannels[1] = MessageReferencedChannel(id: "genius-support", name: "gen")

chat.getChannel(channelId: "support") {
switch $0 {
case let .success(channel):
channel?.sendText(
text: "Check out #general and #gen for more information!",
referencedChannels: referencedChannels
) {
switch $0 {
case .success:
show all 25 lines

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(
text: String,
limit: Int = 10,
completion: ((Swift.Result<[ChannelImpl], Error>) -> Void)? = nil
)

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
[ChannelImpl]Returned array of Channel objects.

Basic usage

Return five channels that have names starting with Sup.

/// Assuming you have a "chat" instance available
/// Invoke the "getChannelSuggestions" method to fetch channels with names starting with 'Sup'
chat.getChannelSuggestions(
text: "Sup",
limit: 5
) {
switch $0 {
case let .success(channels):
if !channels.isEmpty {
debugPrint("Fetched \(channels.count) channels with names starting with 'Sup':")
for channel in channels {
debugPrint("Channel ID: \(channel.id), Channel Name: \(channel.name ?? "")")
}
} else {
debugPrint("No channels found with names starting with 'Sup'")
show all 20 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.

/// Assuming you have a "channel" instance available
let messageTimetoken: Timetoken = 16200000000000000

/// Get the specific message using its timetoken
let messageTimetoken: Timetoken = 16200000000000000

/// Get the specific message using its timetoken
channel.getMessage(timetoken: messageTimetoken) { result in
switch result {
case let .success(message):
if let message = message {
debugPrint("Fetched message with timetoken: \(message.timetoken)")

if let referencedChannels = message.referencedChannels, !referencedChannels.isEmpty {
debugPrint("Message contains the following channel references:")
show all 28 lines
Last updated on