Skip to main content
This page contains Android SDK code examples for Smart Chat features. For feature documentation, setup instructions, and configuration options, see Smart Chat Features.

How to Use AI Features with SDK

1

Enable in Dashboard

Login to CometChat Dashboard, select your app, then go to Chat & Messaging → Features and enable the AI feature.
2

Configure AI settings

Open the AI feature settings in the Dashboard to configure options like response style, language, etc.
3

Implement SDK methods

Use the code examples below to fetch AI-generated content.
4

Build your UI

Create UI components to display conversation starters, smart replies, and summaries.

Conversation Starter

Retrieve AI-generated initial messages to start conversations.
val receiveId = ""
val receiverType: String = CometChatConstants.RECEIVER_TYPE_USER
val configuration = JSONObject()
try {
    configuration.put("lastNMessages", 100)
} catch (e: JSONException) {
    throw RuntimeException(e)
}

CometChat.getConversationStarter(
    receiveId,
    receiverType,
    configuration,
    object : CallbackListener<List<String?>?>() {
        fun onSuccess(strings: List<String?>) {
            Log.e(TAG, strings.toString())
        }
        override fun onError(e: CometChatException) {
            Log.e(TAG, e.getMessage())
        }
    }
)

Smart Replies

Retrieve AI-generated reply suggestions based on conversation context.
val receiverId: String = "UID/GUID"
val receiverType: String = "user/group"
val configuration = JSONObject()
try {
    configuration.put("lastNMessages", 100)
} catch (e: JSONException) {
    throw RuntimeException(e)
}

CometChat.getSmartReplies(
    receiverId,
    CometChatConstants.RECEIVER_TYPE_USER,
    configuration,
    object : CallbackListener<HashMap<String, String>>() {
        override fun onSuccess(smartReplies: HashMap<String, String>) {
            for (s in smartReplies.keys) {
                Log.e(TAG, "Smart Reply: $s ${smartReplies[s]}")
            }
        }
        override fun onError(e: CometChatException) {
            Log.e(TAG, e.message)
        }
    }
)

Conversation Summary

Retrieve AI-generated summaries of conversations.
val receiverId = "UID/GUID"
val receiverType = CometChatConstants.RECEIVER_TYPE_USER
val configuration = JSONObject()

try {
    configuration.put("lastNMessages", 100)
} catch (e: JSONException) {
    throw RuntimeException(e)
}

CometChat.getConversationSummary(receiverId, receiverType, configuration,
    object : CometChat.CallbackListener<String>() {
        override fun onSuccess(s: String) {
            Log.e(TAG, s)
        }
        override fun onError(e: CometChatException) {
            Log.e(TAG, e.localizedMessage)
        }
})