Let users save important messages and revisit them later.
Extension settings
Enable Save Message
Go to Chat & Messaging —> Features, under Extentions and enable Save Message.
How does it work?
Save message extension provides you the ability to:
- Save messages: Allow users to save messages for later.
- Unsave messages: Remove saved messages when no longer needed.
- Fetch saved messages: Retrieve all saved messages for a user.
Saved messages are private and visible only to the user who saved them.
Choose Your Integration Method
Choose the integration method that best suits your needs:
UI Kit Builder
- Enable it in both Dashboard and UI Kit Builder settings, then you can use the Message Shortcuts extension in your custom chat experience.
- Enable it in both Dashboard and Widget Builder settings, then you can use the Message Shortcuts extension in your custom chat widget.
UI Kits
- Enable it in the Dashboard settings, then you can use the Message Shortcuts extension in your custom chat experience built with our UI Kits.
SDK
- Enable it in the Dashboard settings, then you can use the Message Shortcuts extension in your custom chat experience built with our SDK.
Code
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
});
import org.json.simple.JSONObject;
JSONObject body=new JSONObject();
body.put("msgId", 111);
CometChat.callExtension("save-message", "POST", "/v1/save", body,
new CometChat.CallbackListener < JSONObject > () {
@Override
public void onSuccess(JSONObject jsonObject) {
//On Success
}
@Override
public void onError(CometChatException e) {
//On Failure
}
});
CometChat.callExtension(slug: "save-message", type: .post, endPoint: "v1/save", body: ["msgId": 111] as [String : Any], onSuccess: { (response) in
// Success
}) { (error) in
// 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
});
import org.json.simple.JSONObject;
JSONObject body=new JSONObject();
body.put("msgId", 111);
CometChat.callExtension("save-message", "DELETE", "/v1/unsave", body,
new CometChat.CallbackListener < JSONObject > () {
@Override
public void onSuccess(JSONObject jsonObject) {
//On Success
}
@Override
public void onError(CometChatException e) {
//On Failure
}
});
CometChat.callExtension(slug: "save-message", type: .delete, endPoint: "v1/unsave", body: ["msgId": 111] as [String : Any], onSuccess: { (response) in
// Success
}) { (error) in
// 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
});
String URL = "/v1/fetch";
CometChat.callExtension("save-message", "GET", URL, null,
new CometChat.CallbackListener < JSONObject > () {
@Override
public void onSuccess(JSONObject jsonObject) {
// {savedMessages: []}
}
@Override
public void onError(CometChatException e) {
// Some error occured
}
});
CometChat.callExtension(slug: "save-message", type: .get, endPoint: "v1/fetch", body: nil, onSuccess: { (response) in
// {savedMessages: []}
}) { (error) in
// Some error occured
}
}