Skip to main content

Save Message

Extension settings

  1. Login to the CometChat and select your app.
  2. Go to the Extensions section and enable the Save message extension.

How does it work?

Save message extension provides you the ability to:

  1. Save messages
  2. Unsave messages
  3. Fetch all the saved messages by the user.

Saved messages are private and are visible to the user who has saved them.

1. Save a message

To save a message, use the callExtension method provided by the SDK to make an HTTP POST request with the parameters as shown below. You need to pass the msgId of the message that has to be saved.

CometChat.callExtension('save-message', 'POST', 'v1/save', {
"msgId": 111
}).then(response => {
// { success: true }
})
.catch(error => {
// Error occured
});

2. Unsave a message

To unsave a message, use the callExtension method provided by the SDK to make an HTTP DELETE request with the parameters as shown below. You need to pass the msgId of the message that needs to be unsaved.

CometChat.callExtension('save-message', 'DELETE', 'v1/unsave', {
"msgId": 111
}).then(response => {
// { success: true }
})
.catch(error => {
// Error occured
});

3. Fetch saved messages

To fetch the saved messages for a user, use the callExtension method provided by the SDK to make an HTTP GET request with the query parameters as shown below.

const URL = `v1/fetch`;
CometChat.callExtension('save-message', 'GET', URL, null).then(response => {
// {savedMessages: []}
})
.catch(error => {
// Error occured
});