Editing Messages

You can only perform edit and delete operations on your own messages. Once the operation is complete, the message's editedAt will be set to the current time. This allows you to provide UI to the user to inform the user of specific messages that has been edited, if needed. An optional completion block can be provided to notify you of operation success.

Edit Message

To edit the message, you need to pass the following parameters:

  • messageId (String) - ID of the message to edit/update

  • data (String) - new message

import { MessageRepository } from '@amityco/js-sdk';

try {
  await MessageRepository.updateMessage({ 
    messageId: 'messageId', 
    data: { text: 'new text' },
  );
  console.log('message is updated');
} catch (error) {
  console.error('can not update message', error);
}

Delete Message

For deleting a message, you need to pass the ID of the message to delete.

import { MessageRepository } from '@amityco/js-sdk';

try {
  await MessageRepository.deleteMessage('messageId');
  console.log('message is deleted');
} catch (error) {
  console.error('can not delete message', error);
}

A full chatroom example

In this code example, we'll demonstrate the creation of messages with text, image or file and the display of them in a single chat room.

Storybook Sample

Known Limitation

Missing Previous Page with Real-time Event when filter is applied

When a filter is applied, if you have already reached the first page and there is a real-time event, you may not be able to go further. You need to recreate the LiveCollection or refresh the cache to address this.

Last updated