ChannelClient
ChannelClient:
TypedEventEmitter<ChannelEvents> &object
Represents the client service for managing channels.
Type declaration
create()
Creates a new channel based on the provided request.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | ChannelCreateRequest | The request object containing details for the channel to be created. |
Returns
Promise<Channel>
A promise that resolves to the created channel.
Throws
An error if the channel creation fails.
Example
import {
Channel,
ChannelCreateRequest,
ChannelGroupGuid,
ChannelType,
rootServer,
} from "@rootsdk/server-bot";
export async function createExample(
channelGroupId: ChannelGroupGuid,
): Promise<Channel> {
try {
// Set up the request
const request: ChannelCreateRequest = {
channelGroupId: channelGroupId,
channelType: ChannelType.Text,
iconTokenUri: undefined,
name: "MyChannelName",
description: "My Channel Description",
useChannelGroupPermission: true,
};
// Call the API
const channel: Channel =
await rootServer.community.channels.create(request);
return channel;
} catch (error) {
// Detect error
throw error;
}
}
delete()
Deletes a channel based on the provided request and triggers event handlers for permission updates.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | ChannelDeleteRequest | The request object containing the details of the channel to be deleted. |
eventHandlers? | { channel.deleted: ChannelDeletedHandler; channelGroup.deleted: ChannelGroupDeletedHandler; } | Handlers for any community permission update events. |
eventHandlers.channel.deleted? | ChannelDeletedHandler | - |
eventHandlers.channelGroup.deleted? | ChannelGroupDeletedHandler | - |
Returns
Promise<void>
A promise that resolves once the channel is deleted.
Throws
An error if the channel deletion fails.
Example
import {
Channel,
ChannelDeleteRequest,
ChannelGuid,
ChannelGroupGuid,
ChannelType,
rootServer,
} from "@rootsdk/server-bot";
export async function deleteExample(
channelGroupId: ChannelGroupGuid,
channelId: ChannelGuid,
): Promise<void> {
try {
// Set up the request
const request: ChannelDeleteRequest = {
id: channelId,
};
// Call the API
await rootServer.community.channels.delete(request);
} catch (error) {
// Detect error
throw error;
}
}
edit()
Edits an existing channel based on the provided request and triggers event handlers for permission updates.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | ChannelEditRequest | The request object containing the channel edit details. |
eventHandlers? | { channel.deleted: ChannelDeletedHandler; channel.edited: ChannelEditedHandler; channelGroup.deleted: ChannelGroupDeletedHandler; } | Handlers for any community permission update events. |
eventHandlers.channel.deleted? | ChannelDeletedHandler | - |
eventHandlers.channel.edited? | ChannelEditedHandler | - |
eventHandlers.channelGroup.deleted? | ChannelGroupDeletedHandler | - |
Returns
Promise<void>
A promise that resolves once the channel is edited.
Throws
An error if the channel edit fails.
Example
import {
Channel,
ChannelEditRequest,
ChannelGuid,
ChannelGroupGuid,
rootServer,
} from "@rootsdk/server-bot";
export async function editExample(channelId: ChannelGuid): Promise<void> {
try {
// Set up the request
const request: ChannelEditRequest = {
id: channelId,
updateIcon: false,
iconTokenUri: undefined,
name: "MyNewChannelName",
description: "My New Channel Description",
useChannelGroupPermission: true,
};
// Call the API
await rootServer.community.channels.edit(request);
} catch (error) {
// Detect error
throw error;
}
}
get()
Fetches a channel using the provided request.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | ChannelGetRequest | The request object containing the details of the channel to be fetched. |
Returns
Promise<Channel>
A promise that resolves to the fetched channel.
Throws
An error if the channel retrieval fails.
Example
import {
Channel,
ChannelGetRequest,
ChannelGuid,
ChannelGroupGuid,
rootServer,
} from "@rootsdk/server-bot";
export async function getExample(
channelId: ChannelGuid,
): Promise<Channel> {
try {
// Set up the request
const request: ChannelGetRequest = {
id: channelId,
};
// Call the API
const channel: Channel = await rootServer.community.channels.get(request);
return channel;
} catch (error) {
// Detect error
throw error;
}
}
list()
Lists all channels based on the provided request.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | ChannelListRequest | The request object containing the parameters for listing channels. |
Returns
Promise<Channel[]>
A promise that resolves to an array of sorted channels.
Throws
An error if the channel listing fails.
Example
import {
Channel,
ChannelGroupGuid,
ChannelGuid,
ChannelListRequest,
rootServer,
} from "@rootsdk/server-bot";
export async function listExample(
channelGroupId: ChannelGroupGuid,
): Promise<Channel[]> {
try {
// Set up the request
const request: ChannelListRequest = {
channelGroupId: channelGroupId,
};
// Call the API
const channels: Channel[] =
await rootServer.community.channels.list(request);
return channels;
} catch (error) {
// Detect error
throw error;
}
}
move()
Moves a channel based on the provided request and triggers event handlers if any permissions are updated.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | ChannelMoveRequest | The request object containing the details of the channel to be moved. |
eventHandlers? | { channel.edited: ChannelEditedHandler; channelGroup.deleted: ChannelGroupDeletedHandler; } | Handlers for any community permission update events. |
eventHandlers.channel.edited? | ChannelEditedHandler | - |
eventHandlers.channelGroup.deleted? | ChannelGroupDeletedHandler | - |
Returns
Promise<void>
A promise that resolves once the channel move is complete.
Throws
An error if the channel move fails.
Example
import {
Channel,
ChannelMoveRequest,
ChannelGuid,
ChannelGroupGuid,
rootServer,
} from "@rootsdk/server-bot";
export async function moveExample(
channelId: ChannelGuid,
oldChannelGroupId: ChannelGroupGuid,
newChannelGroupId: ChannelGroupGuid,
beforeChannelId?: ChannelGuid,
): Promise<void> {
try {
// Set up the request
const request: ChannelMoveRequest = {
id: channelId,
oldChannelGroupId: oldChannelGroupId,
newChannelGroupId: newChannelGroupId,
beforeChannelId: beforeChannelId,
};
// Call the API
await rootServer.community.channels.move(request);
} catch (error) {
// Detect error
throw error;
}
}