Skip to main content

Installation

Follow the steps to set up and start using the Kotlin ADK in your project.

1. Install the ADK Package

Create a Kotlin project and install the ADK package:

implementation(project(":artlibrary"))

2. Import the ADK into your project

Import the ADK in your project files to use the features provided by ART:

import com.adk.artlibrary.ADK

3. Generate Client Secret

Once after gaining access to the ART Live Dashboard, generate the Client Secret and add it in the root of your project directory. The client credential JSON will look something like this:

{
"Client-ID": "xxxxxxxxxx",
"Client-Secret": "xxxxxxxxxxx",
"Org-Title": "YOUR_ORG",
"ProjectKey": "YOUR_PROJECT_KEY",
"Environment": "YOUR_ENV_NAME"
}
important

The adk-service.json needs to be updated with ProjectKey and Environment, manually. To learn how to obtain the values, click here

4. Authenticate

Once the Client Credentials are added to your project, the Client needs to be authenticated. To authenticate, user needs to generate passcode

val adk = Adk({
AuthToken: "YOUR_PASS_CODE", // Replace with your obtained passcode
Uri: "ws.arealtimetech.com", // Replace with ART server WebSocket URI
});

// Initiate the connection to the ART server
adk.connect();

6. Subscribe to Channel

A Channel is a communication pathway that provides passage for data transfer. Subscribing to channel will allow you to get started with using the realtime messaging in your application.

// Subscribe to your channel
val subscription = adk.subscribe("your-channel-name");

You can learn more about Channel Configuration from here

6. Push Messages

Messages are pushed to a channel using the push() ADK method. This method allows you to send various event types with associated data, and optionally target specific users or groups within the channel for more granular delivery.

// Define the message payload
val payload = { content: "Hello from ART ADK!" };

// Optionally define specific target users within the channel
val targetUsers = ["username1", "username2"];

// Push a "message" event with the payload and targeting options
try {
val response = subscription.push("message", payload, {
to: targetUsers, // Target specific recipients within the channel
})
Log.d("ART", "Message acknowledged by ART: $response")

} catch (error: Exception) {
Log.e("ART", "Failed to push message: $error")
}

7. Listen to All Events and Messages

The listen() method allows you to capture all events and messages published within the subscribed channel. This is a catch-all listener that delivers every incoming payload, regardless of event type.

// Listen to all events and messages in the channel
subcription.listen { data ->
Log.d("Received:" ,"$data")
}
note

You can refer the Quick Start Guide to understand the steps better.