Skip to main content

ChannelMessageClient

ChannelMessageClient: TypedEventEmitter<ChannelMessageEvents> & object

Type declaration

create()

Parameters

ParameterType
requestChannelMessageCreateRequest

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:

  • CreateMessageAttachment if message includes attachments
  • CreateMessageMention if 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:

  • CreateMessage on the channel

delete()

Parameters

ParameterType
requestChannelMessageDeleteRequest

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:

  • DeleteMessageOther if deleting messages created by others

Note: No permission required to delete your own messages

edit()

Parameters

ParameterType
requestChannelMessageEditRequest

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

ParameterType
requestChannelMessageFlagRequest

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

ParameterType
requestChannelMessageGetRequest

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

ParameterType
requestChannelMessageListRequest

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:

  • ViewMessageHistory if 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

ParameterType
requestChannelMessagePinCreateRequest

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:

  • ManagePinnedMessages on the channel

pinDelete()

Parameters

ParameterType
requestChannelMessagePinDeleteRequest

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:

  • ManagePinnedMessages on the channel

pinList()

Parameters

ParameterType
requestChannelMessagePinListRequest

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

ParameterType
requestChannelMessageReactionCreateRequest

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:

  • CreateMessageReaction on the channel

reactionDelete()

Parameters

ParameterType
requestChannelMessageReactionDeleteRequest

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:

  • CreateMessageReaction on the channel

Note: Can only delete reactions created by your code

setTypingIndicator()

Parameters

ParameterType
requestChannelMessageSetTypingIndicatorRequest

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

ParameterType
requestChannelMessageSetViewTimeRequest

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;
}
}