Skip to main content
This page contains Android SDK code examples for User Engagement extensions. For feature documentation, setup instructions, and extension settings, see User Engagement Extensions.

How to Use Extensions with SDK

1

Enable in Dashboard

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

Configure settings (if required)

Some extensions require API keys or additional configuration. Open the extension settings in the Dashboard.
3

Implement SDK methods

Use the code examples below to call extension APIs and extract extension data from messages.
4

Build your UI

Create UI components to display extension data (e.g., polls, stickers, GIFs).

Giphy

Add GIFs from Giphy to your conversations.
val url = "/v1/trending?offset=1&limit=15"

CometChat.callExtension("gifs-giphy", "GET", url, null,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(jsonObject: JSONObject) {
            // GIFs data from Giphy
        }
        override fun onError(e: CometChatException) {
            // Some error occurred
        }
    }
)

Search for GIFs

val query = "awesome"
val url = "/v1/search?offset=1&limit=15&query=$query"

CometChat.callExtension("gifs-giphy", "GET", url, null,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(jsonObject: JSONObject) {
            // GIFs data from Giphy
        }
        override fun onError(e: CometChatException) {
            // Some error occurred
        }
    }
)

Tenor

Add GIFs from Tenor to your conversations.
val url = "/v1/trending?offset=1&limit=15"

CometChat.callExtension("gifs-tenor", "GET", url, null,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(jsonObject: JSONObject) {
            // GIFs data from Tenor
        }
        override fun onError(e: CometChatException) {
            // Some error occurred
        }
    }
)

Search for GIFs

val query = "awesome"
val url = "/v1/search?offset=1&limit=15&query=$query"

CometChat.callExtension("gifs-tenor", "GET", url, null,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(jsonObject: JSONObject) {
            // GIFs data from Tenor
        }
        override fun onError(e: CometChatException) {
            // Some error occurred
        }
    }
)

Message Translation

Translate messages into 70+ languages.

Translate Message

val body = JSONObject()
val languages = JSONArray()
languages.put("ru")
languages.put("hi")

body.put("msgId", 12)
body.put("languages", languages)
body.put("text", "Hey there! How are you?")

CometChat.callExtension("message-translation", "POST", "/v2/translate", body,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(jsonObject: JSONObject) {
            // Result of translations
        }
        override fun onError(e: CometChatException) {
            // Some error occurred
        }
    }
)

Polls

Create and vote on polls in conversations.

Creating a Poll

val body = JSONObject()
val options = JSONArray()
options.put("Milk")
options.put("Cereal")

body.put("question", "Milk goes first or the cereal?")
body.put("options", options)
body.put("receiver", "cometchat-guid-1")
body.put("receiverType", "group")

CometChat.callExtension("polls", "POST", "/v2/create", body,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(jsonObject: JSONObject) {
            // On Success
        }
        override fun onError(e: CometChatException) {
            // On Failure
        }
    }
)

Voting in a Poll

val body = JSONObject()
body.put("vote", "3")
body.put("id", "d5441d53-c191-4696-9e92-e4d79da7463")

CometChat.callExtension("polls", "POST", "/v2/vote", body,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(jsonObject: JSONObject) {
            // Vote submitted successfully
        }
        override fun onError(e: CometChatException) {
            // Some error occurred
        }
    }
)

Getting Results

val pollId = "d5441d53-c191-4696-9e92-e4d79da7463"
val url = "/v2/results?id=$pollId"

CometChat.callExtension("polls", "GET", url, null,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(jsonObject: JSONObject) {
            // Poll results
        }
        override fun onError(e: CometChatException) {
            // Some error occurred
        }
    }
)

Stickers

Load and send stickers in conversations.

Loading Stickers

CometChat.callExtension("stickers", "GET", "/v1/fetch", null,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(responseObject: JSONObject) {
            // Stickers received here.
        }
        override fun onError(e: CometChatException) {
            // Some error occurred.
        }
    }
)

Stipop

Access Stipop’s sticker platform.
val lang = "en"
val limit = 20
val pageNumber = 1
val countryCode = "US"
val url = "/v1/trending?lang=$lang&limit=$limit&pageNumber=$pageNumber&countryCode=$countryCode"

CometChat.callExtension("stickers-stipop", "GET", url, null,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(responseObject: JSONObject) {
            // Stickers in response
        }
        override fun onError(e: CometChatException) {
            // Some error occurred
        }
    }
)

Search for Stickers

val lang = "en"
val limit = 20
val pageNumber = 1
val query = "happy"
val url = "/v1/search?lang=$lang&limit=$limit&pageNumber=$pageNumber&query=$query"

CometChat.callExtension("stickers-stipop", "GET", url, null,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(responseObject: JSONObject) {
            // Stickers in response
        }
        override fun onError(e: CometChatException) {
            // Some error occurred
        }
    }
)

Reminders

Set reminders for messages or custom events.

Set Message Reminders

val body = JSONObject()
body.put("about", 1)
body.put("isCustom", false)
body.put("timeInMS", 1638351344989L)

CometChat.callExtension("reminders", "POST", "/v1/reminder", body,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(responseObject: JSONObject) {
            // Reminder created successfully
        }
        override fun onError(e: CometChatException) {
            // Some error occurred
        }
    }
)

Set Personal Reminders

val body = JSONObject()
body.put("about", "Drinking water")
body.put("isCustom", true)
body.put("timeInMS", 1638351344989L)

CometChat.callExtension("reminders", "POST", "/v1/reminder", body,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(responseObject: JSONObject) {
            // Personal reminder created successfully
        }
        override fun onError(e: CometChatException) {
            // Some error occurred
        }
    }
)

List Reminders

CometChat.callExtension("reminders", "GET", "/v1/fetch", null,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(responseObject: JSONObject) {
            // Reminders list
        }
        override fun onError(e: CometChatException) {
            // Some error occurred
        }
    }
)

Delete Reminders

val body = JSONObject()
body.put("reminderId", "e9cda52a-3839-4fd5-a010-b70db136f0f1")

CometChat.callExtension("reminders", "DELETE", "/v1/reminder", body,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(responseObject: JSONObject) {
            // Reminder deleted successfully
        }
        override fun onError(e: CometChatException) {
            // Some error occurred
        }
    }
)