One to One Conversations

Last Edit: Nov 27 2020

Creating Conversations

Channels can be used to create one to one conversations between users as well. In most cases, you want conversations to be unique and make sure that two users have only a channel.

You can achieve this by leaving the channel ID empty and provide channel type, members, and custom data. When you do so, the API will ensure that only one channel for the members you specified exists (the order of the members does not matter).

You cannot add/remove members for channels created this way.

const conversation = client.channel('messaging', {
    members: ['thierry', 'tommaso'],
});
                    

$conversation = $client->Channel('messaging', 'thierry-jenny', ['members'=>['thierry', 'jenny']]);
$state   = $conversation->create('thierry');
                    

client.channel("messaging", extraData: {"members": ["thierry", "tommaso"]});
                    

val members = listOf("thierry", "tomasso")
val channelType = "messaging"
ChatClient.instance().createChannel(channelType, members).enqueue {
    val newChannel = it.data()
}
                    

let john = User(id: "john")
let channel = Client.shared.channel(type: .messaging, members: [User.current, john])

// Create the channel on backend
channel.create { (result) in
    // handle result
}
                    

List<String> members = new ArrayList<>();
members.add("thierry");
members.add("tomasso");

String channelType = "messaging";

ChatClient.instance().createChannel(channelType, members).enqueue(new Function1<Result<Channel>, Unit>() {
    @Override
    public Unit invoke(Result<Channel> result) {
        Channel newChannel = result.data();
        return Unit.INSTANCE;
    }
});