Join channels
Requires App Context
Enable App Context on your keyset in the Admin Portal to manage memberships.
Use join() to create a user's membership on a channel. To also receive messages, call onMessageReceived() separately.
Interactive demo
Check what a sample implementation could look like in a React app showcasing user-channel membership.
Want to implement something similar?
Read how to do that or go straight to the demo's source code.
Test it out
Choose whether you want to join or leave a given channel and wait until you get notified when that happens.
Method signature
join() creates a new Membership object that represents the user-channel relationship. Unlike previous versions, join() only sets membership. Use onMessageReceived() to subscribe to incoming messages.
This method takes the following parameters:
1channel.join(
2 params?: {
3 status?: string;
4 type?: string;
5 custom?: ObjectCustom
6 }
7): Promise<Membership>
Input
| Parameter | Description |
|---|---|
paramsType: objectDefault: n/a | Optional parameters for the membership. |
→ statusType: stringDefault: n/a | Tag that categorizes the membership by its state. |
→ typeType: stringDefault: n/a | Tag that categorizes the membership by its function. |
→ customType: ObjectCustomDefault: n/a | Any custom properties or metadata associated with the channel-user membership in the form of a JSON. Values must be scalar only; arrays or objects are not supported. App Context filtering language doesn’t support filtering by custom properties. |
Output
| Type | Description |
|---|---|
Promise<Membership> | Returned object containing all data on the newly created user-channel membership. |
Sample code
Join the support channel and mark this membership as premium to add information about your support plan.
1// reference the "channel" object
2const channel = await chat.getChannel("support")
3
4// join the channel and add metadata to the newly created membership
5const membership = await channel.join({
6 custom: { support_plan: "premium" }
7})
8
9// to also receive messages, call onMessageReceived() separately
10channel.onMessageReceived((message) => {
11 console.log("New message:", message.content.text)
12})