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()1channel.update(
2 name: String?,
3 custom: CustomObject?,
4 description: String?,
5 status: String?,
6 type: ChannelType?,
7): PNFuture<Channel> -
updateChannel()1chat.updateChannel(
2 id: String,
3 name: String?,
4 custom: CustomObject?,
5 description: String?,
6 status: String?,
7 type: ChannelType?,
8): PNFuture<Channel>
Input
| Parameter | Required in update() | Required in updateChannel() | Description |
|---|---|---|---|
idType: StringDefault: n/a | No | Yes | Unique channel identifier. |
nameType: StringDefault: n/a | No | No | Display name for the channel. |
customType: CustomObjectDefault: n/a | No | No | JSON 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. |
descriptionType: StringDefault: n/a | No | No | Additional details about the channel. |
statusType: StringDefault: n/a | No | No | Tag that categorizes a channel by its state, like archived. |
typeType: 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
| Type | Description |
|---|---|
PNFuture<Channel> | PNFuture containing the updated channel object with its metadata. |
Sample code
Update the description of the support channel.
-
update()1// reference the "channel" object
2chat.getChannel("support").async {
3 it.onSuccess { channel ->
4 // invoke the "update()" method on the "channel" object
5 channel.update(description = "Channel for CRM tickets").async {
6 ... // handle success and failure
7 }
8 }.onFailure { ... /* handle failure */ }
9} -
updateChannel()1// reference the "chat" object and invoke the "updateChannel()" method
2chat.updateChannel(
3 "support",
4 description = "Channel for CRM tickets"
5).async {
6 ... // handle success and failure
7}
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 singleChannelobject and it's tied to an instance of theChannelclass.streamUpdatesOn()checks updates on aChannelobject list and it's tied to theChannelclass.
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()1channel.streamUpdates(callback: (channel: Channel?) -> Unit): AutoCloseable -
streamUpdatesOn()1class Channel {
2 companion object {
3 fun streamUpdatesOn(
4 channels: Collection<Channel>,
5 callback: (channels: Collection<Channel>) -> Unit
6 ): AutoCloseable
7 }
8}
Input
| Parameter | Required in streamUpdates() | Required in streamUpdatesOn() | Description |
|---|---|---|---|
channelsType: Collection<Channel>Default: n/a | No | Yes | A collection of Channel objects for which you want to get updates. |
callbackType: (channel: Channel?) -> UnitDefault: n/a | Yes | No | Function that takes a single Channel object. It defines the custom behavior to be executed when detecting channel changes. |
callbackType: (channels: Collection<Channel>) -> UnitDefault: n/a | No | Yes | Function that takes a set of Channel objects. It defines the custom behavior to be executed when detecting channel changes. |
Output
| Type | Description |
|---|---|
AutoCloseable | Interface that lets you stop receiving channel-related updates (objects events) by invoking the close() method. |
Sample code
-
streamUpdates()Get updates on the
supportchannel.1val supportChannel: Channel
2
3...
4
5val subscription = supportChannel.streamUpdates { updatedChannel ->
6 println("-=Updated channel: $updatedChannel")
7}
8
9...
10// always remember to call close to stop receiving updates:
11subscription.close() -
streamUpdatesOn()Get updates on the
supportandincident-managementchannels.
show all 16 lines1val supportChannel: Channel
2val incidentManagementChannel: Channel
3
4...
5
6// create a list of channels to monitor
7val channelsToMonitor = listOf(supportChannel, incidentManagementChannel)
8
9// monitor updates on the specified channels
10Channel.streamUpdatesOn(channels = channelsToMonitor) { updatedChannels ->
11 println("-=Updated channels: $updatedChannels")
12}
13
14...
15// always remember to call close to stop receiving updates: