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

ParameterTypeRequired in Update()Required in UpdateChannel()DefaultDescription
channelIdstringNoYesn/aUnique channel identifier.
 → ChannelNamestringNoNon/aDisplay name for the channel.
 → ChannelDescriptionstringNoNon/aAdditional details about the channel.
 → ChannelCustomDataJsonstringNoNon/aJSON 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.
 → ChannelStatusstringNoNon/aTag that categorizes a channel by its state, like archived.
 → ChannelTypestringNoNon/aTag 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 for Channel object update information.
  • OnChannelUpdate — add a single event handler to a single Channel object update.
  • AddListenerToChannelsUpdate() — add a single event handler to each Channel 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

ParameterTypeRequired in StartListeningForUpdatesRequired in OnChannelUpdateRequired in AddListenerToChannelsUpdate()DefaultDescription
channelChannelNoYesNon/aThe channel object to handle the channel update event for.
channelIdsList<string>NoNoYesn/aList of channels for which you want to get updates.
listenern/aNoYesYesn/aThe definition of the custom behavior to be executed when detecting channel metadata changes.

Output

These operations don't return any data.

Basic usage

  • StartListeningForUpdates() and OnChannelUpdate

    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 and incident-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);
Last updated on