Create channels
Create channels (Channel
objects) of one of these types:
Requires App Context
To store data about channels, you must enable App Context for your app's keyset in the Admin Portal.
Create direct channel
Direct channels enable private conversations between two users, letting one person initiate the chat and send an invitation to another person for:
-
Personal conversations - you can engage in private conversations with friends, family, or colleagues, sharing personal updates, discussing sensitive matters, or planning social events.
-
Professional collaboration - you can use 1:1 chat to have focused discussions, exchange confidential information, provide feedback, or coordinate tasks with colleagues and business partners.
createDirectConversation()
is a method that:
- Creates a
direct
(one-on-one) channel type. - Sets channel membership for the channel owner (so that they can join the channel).
- Invites the other user to join the channel. As a result, an event of the
invite
type gets created. You can listen to these events in your chat app and notify the invited users.
If you call this method to create a channel for users that already had a conversation which was not deleted, this conversation is retrieved.
Receive messages
Note that you still have to call the connect()
method to subscribe to message event listeners and start receiving messages on the channel.
Method signature
This method takes the following parameters:
chat.createDirectConversation({ user, channelData, membershipData, }: {
user: User,
channelId?: string
channelData?: {
name?: string,
description?: string,
custom?: ObjectCustom
},
membershipData?: {
custom: ObjectCustom
}
}): Promise<{
channel: Channel,
hostMembership: Membership,
inviteeMembership: Membership,
show all 16 lines