> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Smart Replies (Legacy)

> Smart Replies (Legacy) — CometChat documentation.

<Warning>
  **Legacy Notice**: This extension is already included as part of the core messaging experience (AI) and is scheduled for deprecation in the near future.

  Please note: Legacy extensions are no longer actively maintained and will not receive feature updates or enhancements.
</Warning>

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](https://app.cometchat.com/login) 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.

<Tabs>
  <Tab title="JSON">
    ```json theme={null}
    "@injected": {
      "extensions": {
        "smart-reply": {
              "reply_positive": "<possible positive response>",
              "reply_neutral": "<possible neutral response>",
              "reply_negative": "<possible negative response>",
              "category": "<category>"
        }
      }
    }
    ```
  </Tab>
</Tabs>

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:

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b/gHkTur1I2BmQKdRR/images/05875e52-1623199856-40f23b5912ca4398c7cb3606da47d785.png?fit=max&auto=format&n=gHkTur1I2BmQKdRR&q=85&s=223c9c6a6190f48da16bf82abf121f1b" width="726" height="1216" data-path="images/05875e52-1623199856-40f23b5912ca4398c7cb3606da47d785.png" />
</Frame>

<Tabs>
  <Tab title="JavaScript">
    ```js theme={null}
    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"];
        }
      }
    }
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    JSONObject metadata = message.getMetadata();
    if (metadata != null) {
     JSONObject injectedObject = metadata.getJSONObject("@injected");
     if (injectedObject != null && injectedObject.has("extensions")) {
      JSONObject extensionsObject = injectedObject.getJSONObject("extensions");
      if (extensionsObject != null && extensionsObject.has("smart-reply")) {
       JSONObject smartReply = extensionsObject.getJSONObject("smart-reply");
       String reply_positive = smartReply.getString("reply_positive");
       String reply_neutral = smartReply.getString("reply_neutral");
       String reply_negative = smartReply.getString("reply_negative");
       String category = smartReply.getString("category");

      }
     }
    }
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    if (metadata != null) {
      if (metadata.has("@injected")) {
        val injectedJSONObject = metadata.getJSONObject("@injected")
        if (injectedJSONObject != null && injectedJSONObject.has("extensions")) {
        val extensionsObject = injectedJSONObject.getJSONObject("extensions")
        if (extensionsObject.has("smart-reply")) {
        val smartReplyObject = extensionsObject.getJSONObject("smart-reply")
        if (smartReplyObject.has("reply_positive"))
        val reply_positive = smartReplyObject.getString("reply_positive")
        if (smartReplyObject.has("reply_neutral"))
        val reply_neutral = smartReplyObject.getString("reply_neutral")
        if (smartReplyObject.has("reply_negative"))
        val reply_negative = smartReplyObject.getString("reply_negative")
        if (smartReplyObject.has("category"))
        val category = smartReplyObject.getString("category")               
          }
        }
      }
    }
    ```
  </Tab>

  <Tab title="Swift">
    ```swift theme={null}
    var metadata : [String : Any]? = textMessage.metaData
    if metadata != nil {
                
      var injectedObject : [String : Any]? = (metadata?["@injected"] as? [String : Any])!
                
      if injectedObject != nil && (injectedObject!["extensions"] != nil){
                    
        var extensionsObject : [String : Any]? = injectedObject?["extensions"] as? [String : Any]
                    
        if extensionsObject != nil && extensionsObject?["smart-reply"] != nil {
                        
          var smartReply = extensionsObject?["smart-reply"] as! [String :  Any]
          let reply_positive = smartReply["reply_positive"]
          let reply_neutral = smartReply["reply_neutral"]
          let reply_negative = smartReply["reply_negative"]
          let category = smartReply["category"]
        }
      }
    }
    ```
  </Tab>
</Tabs>
