Skip to main content

Smart Replies

The Smart Reply extension allows you to show quick reply options to a user so that they can easily respond to a message. We will always suggest 3 options; one positive, one neutral and one negative. We also add a category, in case you want to skip some suggestions.

Extension settings

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

How does it work?

When a user sends a message, our Smart Reply extension will add metadata while the message is in-flight. The recipient will receive the message with metadata suggesting the responses.

At the recipients' end, from the message object, you can fetch the metadata by calling the getMetadata() method. Using this metadata, you can fetch suggested responses for the message.

"@injected": {
"extensions": {
"smart-reply": {
"reply_positive": "<possible positive response>",
"reply_neutral": "<possible neutral response>",
"reply_negative": "<possible negative response>",
"category": "<category>"
}
}
}

If the data is missing, it means that the extension has timed out.

Implementation

Using the Smart Reply extension, you can build a UI like this:

Image
var metadata = message.getMetadata();
if (metadata != null) {
var injectedObject = metadata["@injected"];
if (injectedObject != null && injectedObject.hasOwnProperty("extensions")) {
var extensionsObject = injectedObject["extensions"];
if (
extensionsObject != null &&
extensionsObject.hasOwnProperty("smart-reply")
) {
var smartReplyObject = extensionsObject["smart-reply"];
var reply_positive = smartReplyObject["reply_positive"];
var reply_neutral = smartReplyObject["reply_neutral"];
var reply_negative = smartReplyObject["reply_negative"];
var category = smartReplyObject["category"];
}
}
}