
Turns callback-based Telegram TDLib API into suspending functions and flows, emitting typed updates, extension interfaces, and Compose-ready coroutine APIs with sensible defaults.
Telegram Flow is a Kotlin-first extension toolkit for TDLib that turns callback-based Telegram API calls into coroutines and flows. It keeps your client code concise while exposing idiomatic Compose- and coroutine-friendly APIs.
suspend instead of juggling callbacks.ViewModel scopes and state flows.Add the library dependency from Maven Central:
implementation(project(":libtd-ktx"))The libtd-ktx module exposes TDLib (com.github.tdlibx:td:1.8.56) as an API dependency, so no extra TDLib declaration is required.
The project ships a TDLib wrapper module (libtd-ktx) and a Compose sample under sample/ that demonstrates usage with Hilt and the Navigation 3 typed destination APIs.
TelegramFlow instance and keep it in a long-lived scope (e.g., via DI).val telegramFlow = TelegramFlow()
telegramFlow.attachClient()telegramFlow.authorizationStateFlow().collect { state ->
if (state is TdApi.AuthorizationStateWaitTdlibParameters) {
telegramFlow.setTdlibParameters(
databaseDirectory = "/data/user/0/<your.package>/files/td",
apiId = BuildConfig.TELEGRAM_APP_ID,
apiHash = BuildConfig.TELEGRAM_APP_HASH,
// ...other parameters
)
}
}telegramFlow.setAuthenticationPhoneNumber(phone, null)
telegramFlow.checkAuthenticationCode(code)
telegramFlow.checkAuthenticationPassword(password)Every TDLib update has a matching flow extension. Example: tracking user presence changes.
telegramFlow.userStatusFlow().collect { status ->
val user = telegramFlow.getUser(status.userId)
// update UI with latest user status
}For updates that only wrap a single value, the flow returns the inner type directly, e.g. authorizationStateFlow() emits TdApi.AuthorizationState instances.
Each TDLib function is exposed as a suspending extension on TelegramFlow:
suspend fun fetchSelf(): TdApi.User = telegramFlow.getMe()Explore the full API surface in the generated docs.
A minimal Compose sample lives in sample/app. It wires TelegramFlow with Hilt, demonstrates handling the authorization flow, and renders online users with Navigation Compose.
This project is distributed under the Apache 2.0 License. See LICENSE for details.
Telegram Flow is a Kotlin-first extension toolkit for TDLib that turns callback-based Telegram API calls into coroutines and flows. It keeps your client code concise while exposing idiomatic Compose- and coroutine-friendly APIs.
suspend instead of juggling callbacks.ViewModel scopes and state flows.Add the library dependency from Maven Central:
implementation(project(":libtd-ktx"))The libtd-ktx module exposes TDLib (com.github.tdlibx:td:1.8.56) as an API dependency, so no extra TDLib declaration is required.
The project ships a TDLib wrapper module (libtd-ktx) and a Compose sample under sample/ that demonstrates usage with Hilt and the Navigation 3 typed destination APIs.
TelegramFlow instance and keep it in a long-lived scope (e.g., via DI).val telegramFlow = TelegramFlow()
telegramFlow.attachClient()telegramFlow.authorizationStateFlow().collect { state ->
if (state is TdApi.AuthorizationStateWaitTdlibParameters) {
telegramFlow.setTdlibParameters(
databaseDirectory = "/data/user/0/<your.package>/files/td",
apiId = BuildConfig.TELEGRAM_APP_ID,
apiHash = BuildConfig.TELEGRAM_APP_HASH,
// ...other parameters
)
}
}telegramFlow.setAuthenticationPhoneNumber(phone, null)
telegramFlow.checkAuthenticationCode(code)
telegramFlow.checkAuthenticationPassword(password)Every TDLib update has a matching flow extension. Example: tracking user presence changes.
telegramFlow.userStatusFlow().collect { status ->
val user = telegramFlow.getUser(status.userId)
// update UI with latest user status
}For updates that only wrap a single value, the flow returns the inner type directly, e.g. authorizationStateFlow() emits TdApi.AuthorizationState instances.
Each TDLib function is exposed as a suspending extension on TelegramFlow:
suspend fun fetchSelf(): TdApi.User = telegramFlow.getMe()Explore the full API surface in the generated docs.
A minimal Compose sample lives in sample/app. It wires TelegramFlow with Hilt, demonstrates handling the authorization flow, and renders online users with Navigation Compose.
This project is distributed under the Apache 2.0 License. See LICENSE for details.