On this page

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

icon

Under the hood


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

* required
ParameterDescription
params
Type: object
Default:
n/a
Optional parameters for the membership.
 → status
Type: string
Default:
n/a
Tag that categorizes the membership by its state.
 → type
Type: string
Default:
n/a
Tag that categorizes the membership by its function.
 → custom
Type: ObjectCustom
Default:
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

TypeDescription
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})
Last updated on