TDL Coroutines is a Kotlin Multiplatform library that provides a coroutine-based client for the
Telegram Database Library (TDLib). It simplifies sending requests and handling updates, making
integration with TDLib more straightforward and idiomatic for Kotlin and Kotlin Multiplatform projects.
repositories {
    mavenCentral()
}dependencies {
    implementation("dev.g000sha256:tdl-coroutines:5.0.0")
}Caution
The TDLib frequently includes breaking changes in its minor versions.
To reduce breaking changes when updating the TDL Coroutines library,
use named arguments for constructors and methods, as new parameters may be added in future releases.
val client = TdlClient.create()Important
To start using TdlClient, you should first subscribe to important updates, and then call any request method.
The TdlClient provides 165 update flows, as well as one that includes all updates.
coroutineScope.launch {
    client.authorizationStateUpdates.collect { updateAuthorizationState ->
        val authorizationState = updateAuthorizationState.authorizationState
        // TODO
    }
}coroutineScope.launch {
    client.allUpdates.collect { update ->
        when (update) {
            is UpdateAuthorizationState -> {
                val authorizationState = update.authorizationState
                // TODO
            }
            is UpdateOption -> {
                val name = update.name
                val value = update.value
                // TODO
            }
            // TODO
        }
    }
}The TdlClient provides 920 request methods.
coroutineScope.launch {
    val result = client.getAuthorizationState()
    when (result) {
        is TdlResult.Failure -> {
            val code = result.code
            val message = result.message
            // TODO
        }
        is TdlResult.Success -> {
            val authorizationState = result.result
            // TODO
        }
    }
}Tip
You can use the .toResult() extension to convert the TdlResult<T> into the standard Kotlin Result<T>.