/ SDKs / JavaScript
SDKs
Chat SDKs JavaScript v4
Chat SDKs JavaScript
Chat SDKs
JavaScript
Version 4

Update a message

Copy link

A user can update any of their own text and file messages sent using UserMessageUpdateParams and FileMessageUpdateParams. An error is returned if a user attempts to update another user's messages. In addition, channel operators can update any messages sent in a channel.

User message

Copy link
JavaScriptTypeScript
const params = {
    message: NEW_TEXT_MESSAGE,
    customType: NEW_CUSTOM_TYPE,
    data: NEW_DATA,
};
const updatedMessage = await channel.updateUserMessage(MESSAGE_ID, params);

File message

Copy link
JavaScriptTypeScript
const params = {
    customType: NEW_CUSTOM_TYPE,
};
const updatedMessage = await channel.updateFileMessage(MESSAGE_ID, params);

If a message is updated, the onMessageUpdated() method in the channel event handler is invoked on all channel participants' devices including the one that updated the message.

Open channel

Copy link
JavaScriptTypeScript
const channelHandler = new OpenChannelHandler({
    onMessageUpdated: (channel, message) => {
        // ...
    }
});

sb.openChannel.addOpenChannelHandler(UNIQUE_HANDLER_ID, channelHandler);

Group channel

Copy link
JavaScriptTypeScript
const channelHandler = new GroupChannelHandler({
    onMessageUpdated: (channel, message) => {
        // ...
    },
});

sb.groupChannel.addGroupChannelHandler(UNIQUE_HANDLER_ID, channelHandler);