tdl-coroutines

Offers a Coroutines client for the Telegram Database Library, enabling asynchronous operations with generated Data Transfer Objects. Supports 159 update flows and 867 request methods.

Android JVMJVMKotlin/Native
GitHub stars3
Authorsg000sha256
Open issues10
LicenseApache License 2.0
Creation date11 months ago

Last activityabout 1 month ago
Latest release10.0.0 (about 1 month ago)

TDL Coroutines

Maven Central TDLib

Platform Android Platform JVM Platform iOS Platform macOS

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.

Gradle setup

repositories {
    mavenCentral()
}

Replace X.X.X with the version from the Maven Central badge.

dependencies {
    implementation("dev.g000sha256:tdl-coroutines:X.X.X")
}

Usage

[!CAUTION] The upstream TDLib library frequently introduces breaking changes even in patch versions. Since TDL Coroutines wraps TDLib, these changes propagate to this library as well. To minimize the impact, use named arguments for constructors and methods, as parameters may be added, renamed, or removed in future releases.

How to create a client

val client = TdlClient.create()

[!IMPORTANT] To start using TdlClient, you should first subscribe to important updates, and then call any request method.

How to subscribe to updates

The TdlClient provides 175 update flows and the allUpdates flow, which combines all update events.

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
        }
    }
}

How to send a request

The TdlClient provides 962 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>.

Android JVMJVMKotlin/Native
GitHub stars3
Authorsg000sha256
Open issues10
LicenseApache License 2.0
Creation date11 months ago

Last activityabout 1 month ago
Latest release10.0.0 (about 1 month ago)

TDL Coroutines

Maven Central TDLib

Platform Android Platform JVM Platform iOS Platform macOS

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.

Gradle setup

repositories {
    mavenCentral()
}

Replace X.X.X with the version from the Maven Central badge.

dependencies {
    implementation("dev.g000sha256:tdl-coroutines:X.X.X")
}

Usage

[!CAUTION] The upstream TDLib library frequently introduces breaking changes even in patch versions. Since TDL Coroutines wraps TDLib, these changes propagate to this library as well. To minimize the impact, use named arguments for constructors and methods, as parameters may be added, renamed, or removed in future releases.

How to create a client

val client = TdlClient.create()

[!IMPORTANT] To start using TdlClient, you should first subscribe to important updates, and then call any request method.

How to subscribe to updates

The TdlClient provides 175 update flows and the allUpdates flow, which combines all update events.

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
        }
    }
}

How to send a request

The TdlClient provides 962 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>.