Ably Chat is a set of purpose-built APIs for a host of chat features enabling you to create 1:1, 1:Many, Many:1 and Many:Many chat rooms for any scale. It is designed to meet a wide range of chat use cases, such as livestreams, in-game communication, customer support, or social interactions in SaaS products. Built on Ably's core service, it abstracts complex details to enable efficient chat architectures.
Everything you need to get started with Ably Chat for JVM and Android:
- Getting started: Chat with Kotlin (Android).
- Getting started: Chat with Kotlin (JVM).
- SDK and usage docs in Kotlin.
- SDK and usage docs in Android using Jetpack Compose.
- API documentation.
- Chat Example App.
- Play with the livestream chat demo.
Ably aims to support a wide range of platforms. If you experience any compatibility issues, open an issue in the repository or contact Ably support.
This SDK supports the following platforms:
| Platform | Support |
|---|---|
| Android | Android 7.0+ (API level 24+) |
| Java | Java 8+ |
Note
Key functionality such as sending and receiving messages is powered by the Ably Pub/Sub SDK. The Pub/Sub SDK is not bundled with the Chat SDK, so add it to your project yourself, as described in Installation.
The Ably Chat SDK is available on the Maven Central Repository. To include the dependency in your project, add the following to your build.gradle file:
For Groovy:
implementation 'com.ably.chat:chat:2.0.0'For Kotlin Script (build.gradle.kts):
implementation("com.ably.chat:chat:2.0.0")For Android (build.gradle.kts):
implementation("com.ably.chat:chat:2.0.0")
implementation("com.ably.chat:chat-extensions-compose:2.0.0")The Chat SDK is built on the Ably Pub/Sub SDK, which you add yourself by choosing the package for where your code runs. Depend on exactly one of them:
// Android apps and other end-user runtimes
implementation("io.ably.pubsub:device:2.0.0")
// Servers and other trusted backend environments
implementation("io.ably.pubsub:server:2.0.0")The following code connects to Ably's chat service, subscribes to a chat room, and sends a message to that room:
import com.ably.chat.createChatClient
import com.ably.chat.RoomOptions
import com.ably.chat.RoomStatus
import io.ably.pubsub.device.PubSubDevice
// Initialize Ably Pub/Sub client
val pubsubClient = PubSubDevice.clientBuilder()
.key("<your-ably-api-key>")
.clientId("your-client-id")
.build()
// Create a chat client
val chatClient = createChatClient(pubsubClient)
// Get a chat room
val room = chatClient.rooms.get("my-room", RoomOptions())
// Monitor room status
room.onStatusChange { statusChange ->
when (statusChange.current) {
RoomStatus.Attached -> println("Room is attached")
RoomStatus.Detached -> println("Room is detached")
RoomStatus.Failed -> println("Room failed: ${statusChange.error}")
else -> println("Room status: ${statusChange.current}")
}
}
// Attach to the room
room.attach()
// Subscribe to messages
val subscription = room.messages.subscribe { message ->
println("Received message: ${message.text}")
}
// Send a message
room.messages.send(text = "Hello, World!")The CHANGELOG.md contains details of the latest releases for this SDK. You can also view all Ably releases on changelog.ably.com.
Read the CONTRIBUTING.md guidelines to contribute to Ably or Share feedback or request a new feature.
For help or technical support, visit Ably's support page. You can also view the community-reported GitHub issues or raise one yourself.
