ChannelMessageClient
ChannelMessageClient:
TypedEventEmitter<ChannelMessageEvents> &object
Type declaration
create()
Parameters
| Parameter | Type |
|---|---|
request | ChannelMessageCreateRequest |
Returns
Promise<ChannelMessage>
Example
import {
ChannelGuid,
ChannelMessage,
ChannelMessageCreateRequest,
rootServer,
} from "@rootsdk/server-app";
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;
}
}
Authorization
Declare the following permissions in your manifest:
"permissions": {
"channel": {
"CreateMessage": true
}
}
Depending on your usage, you may also need to declare:
CreateMessageAttachmentif message includes attachmentsCreateMessageMentionif message mentions @All, @Here, or a non-mentionable role
The community must also create channel access rules that give your code any needed visibility but don't deny these permissions via an overlay:
CreateMessageon the channel
delete()
Parameters
| Parameter | Type |
|---|---|
request | ChannelMessageDeleteRequest |
Returns
Promise<void>
Example
import {
ChannelGuid,
ChannelMessage,
ChannelMessageDeleteRequest,
MessageGuid,
rootServer,
} from "@rootsdk/server-app";
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;
}
}
Authorization
Depending on your usage, you may also need to declare:
DeleteMessageOtherif deleting messages created by others
Note: No permission required to delete your own messages
edit()
Parameters
| Parameter | Type |
|---|---|
request | ChannelMessageEditRequest |
Returns
Promise<ChannelMessage>
Example
import {
ChannelGuid,
MessageGuid,
ChannelMessage,
ChannelMessageEditRequest,
rootServer,
} from "@rootsdk/server-app";
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;
}
}
Authorization
Note: Can only edit messages created by your code; no permission required
flag()
Parameters
| Parameter | Type |
|---|---|
request | ChannelMessageFlagRequest |
Returns
Promise<void>
Example
import {
ChannelGuid,
ChannelMessageFlagRequest,
ContentFlagReason,
MessageGuid,
rootServer,
} from "@rootsdk/server-app";
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()
Parameters
| Parameter | Type |
|---|---|
request | ChannelMessageGetRequest |
Returns
Promise<ChannelMessage>
Example
import {
ChannelGuid,
ChannelMessage,
ChannelMessageGetRequest,
MessageGuid,
rootServer,
} from "@rootsdk/server-app";
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()
Parameters
| Parameter | Type |
|---|---|
request | ChannelMessageListRequest |
Returns
Promise<ChannelMessageListResponse>
Example
import {
ChannelMessageListResponse,
ChannelGuid,
ChannelMessageListRequest,
MessageDirectionTake,
MessageGuid,
rootServer,
} from "@rootsdk/server-app";
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;
}
}
Authorization
Depending on your usage, you may also need to declare:
ViewMessageHistoryif listing messages sent before the code was added to the channel
Note: Without ViewMessageHistory, results are limited to messages sent after the code was added to the channel
pinCreate()
Parameters
| Parameter | Type |
|---|---|
request | ChannelMessagePinCreateRequest |
Returns
Promise<void>
Example
import {
ChannelGuid,
ChannelMessagePinCreateRequest,
MessageGuid,
rootServer,
} from "@rootsdk/server-app";
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;
}
}
Authorization
Declare the following permissions in your manifest:
"permissions": {
"channel": {
"ManagePinnedMessages": true
}
}
The community must also create channel access rules that give your code any needed visibility but don't deny these permissions via an overlay:
ManagePinnedMessageson the channel
pinDelete()
Parameters
| Parameter | Type |
|---|---|
request | ChannelMessagePinDeleteRequest |
Returns
Promise<void>
Example
import {
ChannelGuid,
ChannelMessagePinDeleteRequest,
MessageGuid,
rootServer,
} from "@rootsdk/server-app";
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;
}
}
Authorization
Declare the following permissions in your manifest:
"permissions": {
"channel": {
"ManagePinnedMessages": true
}
}
The community must also create channel access rules that give your code any needed visibility but don't deny these permissions via an overlay:
ManagePinnedMessageson the channel
pinList()
Parameters
| Parameter | Type |
|---|---|
request | ChannelMessagePinListRequest |
Returns
Promise<ChannelMessagePinListResponse>
Example
import {
ChannelGuid,
ChannelMessagePinListRequest,
ChannelMessagePinListResponse,
MessageGuid,
rootServer,
} from "@rootsdk/server-app";
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;
}
}
reactionCreate()
Parameters
| Parameter | Type |
|---|---|
request | ChannelMessageReactionCreateRequest |
Returns
Promise<ChannelMessageReaction>
Example
import {
ChannelGuid,
ChannelMessageReactionCreateRequest,
ChannelMessageReaction,
MessageGuid,
rootServer,
} from "@rootsdk/server-app";
export async function reactionCreateExample(
channelId: ChannelGuid,
messageId: MessageGuid,
shortcode: string,
): Promise<ChannelMessageReaction> {
try {
// Set up the request
const request: ChannelMessageReactionCreateRequest = {
channelId: channelId,
messageId: messageId,
shortcode: shortcode,
};
// Call the API
const reaction =
await rootServer.community.channelMessages.reactionCreate(request);
return reaction;
} catch (error) {
// Detect error
throw error;
}
}
Authorization
Declare the following permissions in your manifest:
"permissions": {
"channel": {
"CreateMessageReaction": true
}
}
The community must also create channel access rules that give your code any needed visibility but don't deny these permissions via an overlay:
CreateMessageReactionon the channel
reactionDelete()
Parameters
| Parameter | Type |
|---|---|
request | ChannelMessageReactionDeleteRequest |
Returns
Promise<void>
Example
import {
ChannelGuid,
ChannelMessageReactionDeleteRequest,
ChannelMessageReaction,
MessageGuid,
rootServer,
} from "@rootsdk/server-app";
export async function reactionDeleteExample(
channelId: ChannelGuid,
messageId: MessageGuid,
shortcode: string,
): Promise<void> {
try {
// Set up the request
const request: ChannelMessageReactionDeleteRequest = {
channelId: channelId,
messageId: messageId,
shortcode: shortcode,
};
// Call the API
await rootServer.community.channelMessages.reactionDelete(request);
} catch (error) {
// Detect error
throw error;
}
}
Authorization
Declare the following permissions in your manifest:
"permissions": {
"channel": {
"CreateMessageReaction": true
}
}
The community must also create channel access rules that give your code any needed visibility but don't deny these permissions via an overlay:
CreateMessageReactionon the channel
Note: Can only delete reactions created by your code
setTypingIndicator()
Parameters
| Parameter | Type |
|---|---|
request | ChannelMessageSetTypingIndicatorRequest |
Returns
Promise<void>
Example
import {
ChannelGuid,
ChannelMessageSetTypingIndicatorRequest,
rootServer,
} from "@rootsdk/server-app";
export async function setTypingIndicatorExample(
channelId: ChannelGuid,
isTyping: boolean,
): Promise<void> {
try {
// Set up the request
const request: ChannelMessageSetTypingIndicatorRequest = {
channelId: channelId,
isTyping: isTyping,
};
// Call the API
await rootServer.community.channelMessages.setTypingIndicator(request);
} catch (error) {
// Detect error
throw error;
}
}
setViewTime()
Parameters
| Parameter | Type |
|---|---|
request | ChannelMessageSetViewTimeRequest |
Returns
Promise<void>
Example
import {
ChannelGuid,
ChannelMessageSetViewTimeRequest,
MessageGuid,
rootServer,
} from "@rootsdk/server-app";
export async function setViewTimeExample(
channelId: ChannelGuid,
): Promise<void> {
try {
// Set up the request
const request: ChannelMessageSetViewTimeRequest = {
channelId: channelId,
};
// Call the API
await rootServer.community.channelMessages.setViewTime(request);
} catch (error) {
// Detect error
throw error;
}
}