Join an open channel
A user must join an open channel before sending or receiving messages. Joining an open channel connects the user to the channel and optionally fetches recent message history.
Join an open channel
TypeScript
import { OpenChannel } from '@nexconn/chat';
const channel = new OpenChannel('<open-channel-id>');
const result = await channel.enterChannel({
messageCount: 10,
extra: 'source=campaign',
});
if (result.isOk) {
console.log('Joined open channel:', result.data.memberCount);
console.log('Joined at:', result.data.enterTime);
} else {
console.log('Join failed. Code:', result.code);
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
messageCount | number | Yes | Number of recent messages to fetch when joining. |
extra | string | No | Optional business context data to send with the enter request. |
Return value
enterChannel() returns Promise<NCResult<OpenChannelEnterResponseInfo>>.
| Field | Type | Description |
|---|---|---|
isOk | boolean | Whether the enter request succeeded. |
code | number | Status code. 0 means success. |
data | OpenChannelEnterResponseInfo | undefined | Open channel info returned after a successful join. |
OpenChannelEnterResponseInfo
| Field | Type | Description |
|---|---|---|
createTime | number | Channel creation timestamp in milliseconds |
memberCount | number | Current number of members in the channel |
isAllChannelMuted | boolean | Whether the entire channel is muted |
isCurrentUserMuted | boolean | Whether the current user is muted globally |
isCurrentChannelMuted | boolean | Whether the current user is muted in this channel |
isCurrentChannelInAllowlist | boolean | Whether the current user is in this channel's mute allowlist |
enterTime | number | Timestamp when the current user joined the channel |
info
- If the connection is interrupted unexpectedly and then restored, the SDK automatically attempts to rejoin previously joined open channels.
- If the user disconnects intentionally, the SDK exits open channels automatically.
- By default, a user can join only one open channel at a time.