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 | Required in Update() | Required in UpdateChannel() | Description |
|---|---|---|---|
channelIdType: stringDefault: n/a | No | Yes | Unique channel identifier. |
→ ChannelNameType: stringDefault: n/a | No | No | Display name for the channel. |
→ ChannelDescriptionType: stringDefault: n/a | No | No | Additional details about the channel. |
→ ChannelCustomDataJsonType: stringDefault: n/a | No | No | 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. |
→ ChannelStatusType: stringDefault: n/a | No | No | Tag that categorizes a channel by its state, like archived. |
→ ChannelTypeType: stringDefault: n/a | No | No | 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
An awaitable Task.
Sample code
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"
};
await channel.Update(updatedChannelData); -
UpdateChannel()var updatedChannelData = new ChatChannelData
{
ChannelDescription = "Channel for CRM tickets"
};
await chat.UpdateChannel("support", updatedChannelData);
Get channel updates
These methods let you receive updates when specific Channel objects are edited or removed on other clients:
SetListeningForUpdates()— listen forChannelobject update information.OnChannelUpdate— add a single event handler to a singleChannelobject update.AddListenerToChannelsUpdate()— add a single event handler to eachChannelobject update from the provided list.
Method signature
These methods take the following parameters:
-
SerListeningForUpdates()channel.SetListeningForUpdates(bool listen) -
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 | Required in SetListeningForUpdates | Required in OnChannelUpdate | Required in AddListenerToChannelsUpdate() | Description |
|---|---|---|---|---|
listenType: boolDefault: n/a | Yes | n/a | n/a | Bool specifying whether to listen to Channel object updates. |
channelIdsType: List<string>Default: n/a | No | No | Yes | List of channels for which you want to get updates. |
listenerType: n/a Default: n/a | No | Yes | Yes | The definition of the custom behavior to be executed when detecting channel metadata changes. |
Output
An awaitable Task.
Sample code
-
SetListeningForUpdates()andOnChannelUpdateGet updates on the
supportchannel.if (!chat.TryGetChannel("support", out var channel))
{
Console.WriteLine("Couldn't find channel!");
return;
};
channel.SetListeningForUpdates(true);
channel.OnChannelUpdate += OnChannelUpdateHandler; // or use lambda
void OnChannelUpdateHandler(Channel channel)
{
Console.WriteLine($"Channel updated: {channel.Id}");
} -
AddListenerToChannelsUpdate()Get updates on the
supportandincident-managementchannels.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);