Skip to main content

Update a message

Update the content of a sent message in a community subchannel. The updated content replaces the original for all participants.

Update a message

Use the static BaseChannel.modifyMessage method:

TypeScript
import { CommunitySubChannel, BaseChannel, Message, TextMessageContent } from '@nexconn/chat';

const channel = new CommunitySubChannel('<communityId>', '<subChannelId>');

// First retrieve the message object you want to modify
const query = BaseChannel.createMessagesQuery({
channelIdentifier: channel.identifier,
startTime: Date.now(),
pageSize: 20,
isAscending: false,
});
const { code, data: page } = await query.loadNextPage();

if (code === 0 && page.data.length > 0) {
const message = page.data[0] as Message<TextMessageContent>;
const { code: modifyCode } = await BaseChannel.modifyMessage<TextMessageContent>({
messageId: message.messageId,
channelIdentifier: channel.identifier,
content: { text: 'Updated content' }, // Plain content object
});
if (modifyCode === 0) {
console.log('Message updated');
} else {
console.log('Update failed. Code:', modifyCode);
}
}

Parameters

ParameterTypeRequiredDescription
messageIdstringYesThe server-assigned message ID of the message to update
channelIdentifierChannelIdentifierYesThe identifier of the channel the message belongs to
contentTYesThe new message content as a plain object
info
  • Content moderation (profanity filter, IM content moderation) applies to the updated content.
  • Updated messages are saved to the server-side history.