Creating Channels

Last Edit: Nov 27 2020

Both channel query and watch methods ensure that a channel exists and create one otherwise. If all you need is to ensure that a channel exists; then you can use channel create.

This is common for server-side integrations when you want to create channels based on business logic (ie. matching users, complex permission models, multi-tenant, ...)


await conversation.create();
                    

conversation.create('jlahey')
                    

let channel = Client.shared.channel(type: .messaging, id: "general")
channel.create { (result) in
    // handle result
}
                    

val channelType = "messaging"
val channelId = "id"
val extraData = emptyMap<String, Any>()

ChatClient.instance().createChannel(channelType, channelId, extraData).enqueue {
  val newChannel = it.data()
}
                    
When you use Chat API server-side you will not call setUser. In most cases you will need to pass the ID of the user related to the API call (ie. in this case the user that is creating the channel).