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(
    name: String?,
    custom: CustomObject?,
    description: String?,
    status: String?,
    type: ChannelType?,
    ): PNFuture<Channel>
  • updateChannel()

    chat.updateChannel(
    id: String,
    name: String?,
    custom: CustomObject?,
    description: String?,
    status: String?,
    type: ChannelType?,
    ): PNFuture<Channel>

Input

ParameterTypeRequired in update()Required in updateChannel()DefaultDescription
idStringNoYesn/aUnique channel identifier.
nameStringNoNon/aDisplay name for the channel.
customCustomObjectNoNon/aJSON object 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.
descriptionStringNoNon/aAdditional details about the channel.
statusStringNoNon/aTag that categorizes a channel by its state, like archived.
typeStringNoNon/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

TypeDescription
PNFuture<Channel>PNFuture containing the updated channel object with its metadata.

Basic usage

Update the description of the support channel.

  • update()

    // reference the "channel" object
    chat.getChannel("support").async {
    it.onSuccess { channel ->
    // invoke the "update()" method on the "channel" object
    channel.update(description = "Channel for CRM tickets").async {
    ... // handle success and failure
    }
    }.onFailure { ... /* handle failure */ }
    }
  • updateChannel()

    // reference the "chat" object and invoke the "updateChannel()" method
    chat.updateChannel(
    "support",
    description = "Channel for CRM tickets"
    ).async {
    ... // handle success and failure
    }

Get channel updates

You can receive updates when specific Channel object(s) are edited or removed on other clients using the following methods:

  • streamUpdates() checks updates on a single Channel object and it's tied to an instance of the Channel class.
  • streamUpdatesOn() checks updates on a Channel object list and it's tied to the Channel class.

Both methods accept a callback function as an argument. The Chat SDK invokes this callback whenever someone adds, changes, or removes channel metadata.

Underneath, these methods subscribe the current user to a channel and add an objects event listener to receive all objects events of type channel. These methods also return the unsubscribe function you can invoke to stop receiving objects events and unsubscribe from the channel.

Method signature

These methods take the following parameters:

  • streamUpdates()

    channel.streamUpdates(callback: (channel: Channel?) -> Unit): AutoCloseable
  • streamUpdatesOn()

    class Channel {
    companion object {
    fun streamUpdatesOn(
    channels: Collection<Channel>,
    callback: (channels: Collection<Channel>) -> Unit
    ): AutoCloseable
    }
    }

Input

ParameterTypeRequired in streamUpdates()Required in streamUpdatesOn()DefaultDescription
channelsCollection<Channel>NoYesn/aA collection of Channel objects for which you want to get updates.
callback(channel: Channel?) -> UnitYesNon/aFunction that takes a single Channel object. It defines the custom behavior to be executed when detecting channel changes.
callback(channels: Collection<Channel>) -> UnitNoYesn/aFunction that takes a set of Channel objects. It defines the custom behavior to be executed when detecting channel changes.

Output

TypeDescription
AutoCloseableInterface that lets you stop receiving channel-related updates (objects events) by invoking the close() method.

Basic usage

  • streamUpdates()

    Get updates on the support channel.

    val supportChannel: Channel

    ...

    val subscription = supportChannel.streamUpdates { updatedChannel ->
    println("-=Updated channel: $updatedChannel")
    }

    ...
    // always remember to call close to stop receiving updates:
    subscription.close()
  • streamUpdatesOn()

    Get updates on the support and incident-management channels.

    val supportChannel: Channel
    val incidentManagementChannel: Channel

    ...

    // create a list of channels to monitor
    val channelsToMonitor = listOf(supportChannel, incidentManagementChannel)

    // monitor updates on the specified channels
    Channel.streamUpdatesOn(channels = channelsToMonitor) { updatedChannels ->
    println("-=Updated channels: $updatedChannels")
    }

    ...
    // always remember to call close to stop receiving updates:
    show all 16 lines
Last updated on