ChannelMessageClient
ChannelMessageClient =
TypedEventEmitter<ChannelMessageEvents> &object
Service client for managing messages within channels. Messages are the primary content units in text channels, supporting rich content with responses, attachments, reactions, and pins.
The client provides methods for creating, retrieving, editing, and deleting messages, as well as managing message reactions and pins. It also supports typing indicators and view time tracking for real-time presence features.
Access this client via rootServer.community.channelMessages.
Type Declaration
create()
create(
request:ChannelMessageCreateRequest):Promise<ChannelMessage>
Creates a new message in a channel.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | ChannelMessageCreateRequest | The message configuration including content and optional attachments. |
Returns
Promise<ChannelMessage>
A promise that resolves to the created ChannelMessage object.
Throws
RootApiException with errorCode set to NoPermissionToCreate if missing required permissions, NotFound if the channel does not exist, or RequestValidationFailed if the request is invalid.
Example
import {
ChannelGuid,
ChannelMessage,
ChannelMessageCreateRequest,
rootServer,
} from "@rootsdk/server-bot";
export async function createExample(
channelId: ChannelGuid,
): Promise<ChannelMessage> {
try {
// Set up the request
const request: ChannelMessageCreateRequest = {
channelId: channelId,
content: "Example Message",
attachmentTokenUris: undefined,
needsParentMessageNotification: false,
};
// Call the API
const message: ChannelMessage =
await rootServer.community.channelMessages.create(request);
return message;
} catch (error) {
// Detect error
throw error;
}
}
delete()
delete(
request:ChannelMessageDeleteRequest):Promise<void>
Deletes a message from a channel.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | ChannelMessageDeleteRequest | Identifies the channel and message to delete. |
Returns
Promise<void>
A promise that resolves when the delete operation completes.
Throws
RootApiException with errorCode set to NotFound if the message does not exist, or NoPermissionToDelete if missing required permissions.
Example
import {
ChannelGuid,
ChannelMessage,
ChannelMessageDeleteRequest,
MessageGuid,
rootServer,
} from "@rootsdk/server-bot";
export async function deleteExample(
channelId: ChannelGuid,
messageId: MessageGuid,
): Promise<void> {
try {
// Set up the request
const request: ChannelMessageDeleteRequest = {
id: messageId,
channelId: channelId,
};
// Call the API
await rootServer.community.channelMessages.delete(request);
} catch (error) {
// Detect error
throw error;
}
}
edit()
edit(
request:ChannelMessageEditRequest):Promise<ChannelMessage>
Edits an existing message's content.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | ChannelMessageEditRequest | Identifies the message and provides the updated content. |
Returns
Promise<ChannelMessage>
A promise that resolves to the updated ChannelMessage object.
Throws
RootApiException with errorCode set to NotFound if the message does not exist, or NoPermissionToEdit if missing required permissions.
Example
import {
ChannelGuid,
MessageGuid,
ChannelMessage,
ChannelMessageEditRequest,
rootServer,
} from "@rootsdk/server-bot";
export async function editExample(
messageId: MessageGuid,
channelId: ChannelGuid,
): Promise<ChannelMessage> {
try {
// Set up the request
const request: ChannelMessageEditRequest = {
id: messageId,
channelId: channelId,
content: "Edited Example Message",
uris: undefined,
};
// Call the API
const message: ChannelMessage =
await rootServer.community.channelMessages.edit(request);
return message;
} catch (error) {
// Detect error
throw error;
}
}
flag()
flag(
request:ChannelMessageFlagRequest):Promise<void>
Reports a message for moderation review.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | ChannelMessageFlagRequest | Identifies the message and the reason for flagging. |
Returns
Promise<void>
A promise that resolves when the flag operation completes.
Throws
RootApiException with errorCode set to NotFound if the message does not exist.
Example
import {
ChannelGuid,
ChannelMessageFlagRequest,
ContentFlagReason,
MessageGuid,
rootServer,
} from "@rootsdk/server-bot";
export async function flagExample(
channelId: ChannelGuid,
messageId: MessageGuid,
reason: ContentFlagReason,
): Promise<void> {
try {
// Set up the request
const request: ChannelMessageFlagRequest = {
channelId: channelId,
id: messageId,
reason: reason,
};
// Call the API
await rootServer.community.channelMessages.flag(request);
} catch (error) {
// Detect error
throw error;
}
}
get()
get(
request:ChannelMessageGetRequest):Promise<ChannelMessage>
Retrieves a single message by its ID.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | ChannelMessageGetRequest | Identifies the channel and message to retrieve. |
Returns
Promise<ChannelMessage>
A promise that resolves to the ChannelMessage object.
Throws
RootApiException with errorCode set to NotFound if the message does not exist, or NoPermissionToRead if missing required permissions.
Example
import {
ChannelGuid,
ChannelMessage,
ChannelMessageGetRequest,
MessageGuid,
rootServer,
} from "@rootsdk/server-bot";
export async function getExample(
channelId: ChannelGuid,
messageId: MessageGuid,
): Promise<ChannelMessage> {
try {
// Set up the request
const request: ChannelMessageGetRequest = {
channelId: channelId,
id: messageId,
};
// Call the API
const message: ChannelMessage =
await rootServer.community.channelMessages.get(request);
return message;
} catch (error) {
// Detect error
throw error;
}
}
list()
list(
request:ChannelMessageListRequest):Promise<ChannelMessageListResponse>
Lists messages in a channel with pagination support. Messages can be retrieved relative to a specific timestamp, fetching newer messages, older messages, or both directions.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | ChannelMessageListRequest | Specifies the channel, pagination direction, and reference timestamp. |
Returns
Promise<ChannelMessageListResponse>
A promise that resolves to a ChannelMessageListResponse containing messages and pagination information.
Throws
RootApiException with errorCode set to NotFound if the channel does not exist, or NoPermissionToRead if missing required permissions.
Example
import {
ChannelMessageListResponse,
ChannelGuid,
ChannelMessageListRequest,
MessageDirectionTake,
MessageGuid,
rootServer,
} from "@rootsdk/server-bot";
export async function listExample(
channelId: ChannelGuid,
): Promise<ChannelMessageListResponse> {
try {
// Set up the request
const request: ChannelMessageListRequest = {
channelId: channelId,
messageDirectionTake: MessageDirectionTake.Both,
dateAt: new Date(),
};
// Call the API
const messages: ChannelMessageListResponse =
await rootServer.community.channelMessages.list(request);
return messages;
} catch (error) {
// Detect error
throw error;
}
}
pinCreate()
pinCreate(
request:ChannelMessagePinCreateRequest):Promise<void>
Pins a message to the channel for easy access.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | ChannelMessagePinCreateRequest | Identifies the channel and message to pin. |
Returns
Promise<void>
A promise that resolves when the pin operation completes.
Throws
RootApiException with errorCode set to NotFound if the message does not exist, or NoPermissionToEdit if missing required permissions.
Example
import {
ChannelGuid,
ChannelMessagePinCreateRequest,
MessageGuid,
rootServer,
} from "@rootsdk/server-bot";
export async function pinCreateExample(
channelId: ChannelGuid,
messageId: MessageGuid,
): Promise<void> {
try {
// Set up the request
const request: ChannelMessagePinCreateRequest = {
channelId: channelId,
messageId: messageId,
};
// Call the API
await rootServer.community.channelMessages.pinCreate(request);
} catch (error) {
// Detect error
throw error;
}
}
pinDelete()
pinDelete(
request:ChannelMessagePinDeleteRequest):Promise<void>
Removes a pin from a message.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | ChannelMessagePinDeleteRequest | Identifies the channel and message to unpin. |
Returns
Promise<void>
A promise that resolves when the unpin operation completes.
Throws
RootApiException with errorCode set to NotFound if the message or pin does not exist, or NoPermissionToEdit if missing required permissions.
Example
import {
ChannelGuid,
ChannelMessagePinDeleteRequest,
MessageGuid,
rootServer,
} from "@rootsdk/server-bot";
export async function pinDeleteExample(
channelId: ChannelGuid,
messageId: MessageGuid,
): Promise<void> {
try {
// Set up the request
const request: ChannelMessagePinDeleteRequest = {
channelId: channelId,
messageId: messageId,
};
// Call the API
await rootServer.community.channelMessages.pinDelete(request);
} catch (error) {
// Detect error
throw error;
}
}
pinList()
pinList(
request:ChannelMessagePinListRequest):Promise<ChannelMessagePinListResponse>
Lists all pinned messages in a channel.
Parameters
| Parameter | Type | Description |
|---|---|---|
request | ChannelMessagePinListRequest | Identifies the channel to list pinned messages from. |
Returns
Promise<ChannelMessagePinListResponse>
A promise that resolves to a ChannelMessagePinListResponse containing pinned messages.
Throws
RootApiException with errorCode set to NotFound if the channel does not exist, or NoPermissionToRead if missing required permissions.
Example
import {
ChannelGuid,
ChannelMessagePinListRequest,
ChannelMessagePinListResponse,
MessageGuid,
rootServer,
} from "@rootsdk/server-bot";
export async function pinListExample(
channelId: ChannelGuid,
): Promise<ChannelMessagePinListResponse> {
try {
// Set up the request
const request: ChannelMessagePinListRequest = {
channelId: channelId,
};
// Call the API
const pinList = await rootServer.community.channelMessages.pinList(request);
return pinList;
} catch (error) {
// Detect error
throw error;
}
}