Manage channel updates
Update channel details and receive events whenever someone updates them.
Requires App Context
To store data about channels, you must enable App Context for your app's keyset in the Admin Portal.
Update channel details
You can edit the metadata of an existing channel with Update()
and UpdateChannel()
.
Both of them give the same output. The only difference is that you call a given method either on the Chat
(UpdateChannel()
) or the Channel
(Update()
) object. Depending on the object, these methods take a different set of input parameters - you either have to specify the channel ID you want to update or not because it's already known.
Method signature
These methods take the following parameters:
-
Update()
channel.Update(ChatChannelData updatedData)
public class ChatChannelData
{
public string ChannelName { get; set; } = string.Empty;
public string ChannelDescription { get; set; } = string.Empty;
public string ChannelCustomDataJson { get; set; } = string.Empty;
public string ChannelStatus { get; set; } = string.Empty;
public string ChannelType { get; set; } = string.Empty;
} -
UpdateChannel()
chat.UpdateChannel(
string channelId,
ChatChannelData updatedData
)
public class ChatChannelData
{
public string ChannelName { get; set; } = string.Empty;
public string ChannelDescription { get; set; } = string.Empty;
public string ChannelCustomDataJson { get; set; } = string.Empty;
public string ChannelStatus { get; set; } = string.Empty;
public string ChannelType { get; set; } = string.Empty;
}
Input
Parameter | Type | Required in Update() | Required in UpdateChannel() | Default | Description |
---|---|---|---|---|---|
channelId | string | No | Yes | n/a | Unique channel identifier. |
→ ChannelName | string | No | No | n/a | Display name for the channel. |
→ ChannelDescription | string | No | No | n/a | Additional details about the channel. |
→ ChannelCustomDataJson | string | No | No | n/a | JSON providing custom data about the channel. Values must be scalar only; arrays or objects are not supported. App Context filtering language doesn’t support filtering by custom properties. |
→ ChannelStatus | string | No | No | n/a | Tag that categorizes a channel by its state, like archived . |
→ ChannelType | string | No | No | n/a | Tag that categorizes a channel by its function, like offtopic . |
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
Output
These methods don't return data.
Basic usage
Update the description of the support
channel.
-
Update()
if (!chat.TryGetChannel("support", out var channel))
{
Console.WriteLine("Couldn't find channel!");
return;
};
var updatedChannelData = new ChatChannelData
{
ChannelDescription = "Channel for CRM tickets"
};
channel.Update(updatedChannelData); -
UpdateChannel()
var updatedChannelData = new ChatChannelData
{
ChannelDescription = "Channel for CRM tickets"
};
chat.UpdateChannel("support", updatedChannelData);
Get channel updates
These methods let you receive updates when specific Channel
objects are edited or removed on other clients:
StartListeningForUpdates()
— listen forChannel
object update information.OnChannelUpdate
— add a single event handler to a singleChannel
object update.AddListenerToChannelsUpdate()
— add a single event handler to eachChannel
object update from the provided list.
Method signature
These methods take the following parameters:
-
StartListeningForUpdates()
channel.StartListeningForUpdates()
-
OnChannelUpdate
// event on the Channel entity
Action<Channel> OnChannelUpdate
// needs a corresponding event handler
void EventHandler(Channel channel) -
AddListenerToChannelsUpdate()
chat.AddListenerToChannelsUpdate(
List<string> channelIds,
Action<Channel> listener
)
Input
Parameter | Type | Required in StartListeningForUpdates | Required in OnChannelUpdate | Required in AddListenerToChannelsUpdate() | Default | Description |
---|---|---|---|---|---|---|
channel | Channel | No | Yes | No | n/a | The channel object to handle the channel update event for. |
channelIds | List<string> | No | No | Yes | n/a | List of channels for which you want to get updates. |
listener | n/a | No | Yes | Yes | n/a | The definition of the custom behavior to be executed when detecting channel metadata changes. |
Output
These operations don't return any data.
Basic usage
-
StartListeningForUpdates()
andOnChannelUpdate
Get updates on the
support
channel.if (!chat.TryGetChannel("support", out var channel))
{
Console.WriteLine("Couldn't find channel!");
return;
};
channel.StartListeningForUpdates();
channel.OnChannelUpdate += OnChannelUpdateHandler; // or use lambda
void OnChannelUpdateHandler(Channel channel)
{
Console.WriteLine($"Channel updated: {channel.Id}");
} -
AddListenerToChannelsUpdate()
Get updates on the
support
andincident-management
channels.List<string> channelIds = new List<string> { "support", "incidentManagement" };
Action<Channel> listener = (Channel channel) =>
{
// Print the updated channel name
Console.WriteLine("Updated Channel Name: " + channel.Name);
};
chat.AddListenerToChannelsUpdate(channelIds, listener);