Skip to content

Commit 6c5c720

Browse files
Merge pull request #4 from akrafts-gpt/master
Version 1.8.56
2 parents 5595717 + 504f1cf commit 6c5c720

204 files changed

Lines changed: 18861 additions & 3625 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Sample app release build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
env:
15+
TELEGRAM_APP_ID: ${{ secrets.TELEGRAM_APP_ID }}
16+
TELEGRAM_APP_HASH: ${{ secrets.TELEGRAM_APP_HASH }}
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Set up JDK 17
22+
uses: actions/setup-java@v4
23+
with:
24+
distribution: temurin
25+
java-version: 17
26+
27+
- name: Setup Gradle
28+
uses: gradle/actions/setup-gradle@v3
29+
30+
- name: Build Release APK
31+
run: ./gradlew --no-daemon clean :sample:app:assembleRelease
32+
33+
- name: Upload Build Artifact
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: release-artifacts
37+
path: sample/app/build/outputs/apk/release/app-release.apk
38+
retention-days: 1
39+
40+
distribute:
41+
needs: build
42+
runs-on: ubuntu-latest
43+
permissions:
44+
contents: write
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@v4
48+
49+
- name: Download Build Artifact
50+
uses: actions/download-artifact@v4
51+
with:
52+
name: release-artifacts
53+
path: sample/app/build/outputs/apk/release
54+
55+
- name: Install Firebase CLI
56+
run: |
57+
npm install -g firebase-tools
58+
firebase --version
59+
60+
- name: Upload to Firebase (Manual CLI)
61+
env:
62+
FIREBASE_APP_ID: ${{ secrets.FIREBASE_APP_ID }}
63+
CREDENTIAL_CONTENT: ${{ secrets.FIREBASE_CREDENTIAL_FILE_CONTENT }}
64+
GOOGLE_APPLICATION_CREDENTIALS: service-account.json
65+
run: |
66+
echo "$CREDENTIAL_CONTENT" > service-account.json
67+
68+
# CHANGED: Explicitly using app-release.apk
69+
APK_PATH="sample/app/build/outputs/apk/release/app-release.apk"
70+
71+
if [ ! -f "$APK_PATH" ]; then
72+
echo "Error: APK not found at $APK_PATH"
73+
ls -R sample/app/build/outputs/apk/
74+
exit 1
75+
fi
76+
77+
# 2. LOGIC: Determine release notes based on event type
78+
if [ "${{ github.event_name }}" == "pull_request" ]; then
79+
NOTES="PR #${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}"
80+
else
81+
NOTES="Master Release: ${{ github.sha }}"
82+
fi
83+
84+
firebase appdistribution:distribute "$APK_PATH" \
85+
--app "$FIREBASE_APP_ID" \
86+
--groups "testers" \
87+
--release-notes "$NOTES" \
88+
--debug
89+
90+
- name: Publish GitHub release
91+
if: github.event_name == 'push'
92+
uses: softprops/action-gh-release@v1
93+
with:
94+
tag_name: release-${{ github.run_number }}
95+
name: Release build #${{ github.run_number }}
96+
body: |
97+
Automated Release build for commit ${{ github.sha }} on master.
98+
This release contains the sample Compose client APK built from sample/app's Release variant.
99+
prerelease: false
100+
files: sample/app/build/outputs/apk/release/app-release.apk
101+
env:
102+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ hs_err_pid*
8989
bin/
9090
gen/
9191
release/
92+
build/
9293

9394
# Gradle files
9495
.gradle/

Readme.md

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,81 @@
1-
# Telegram Flow
1+
# Telegram Flow for TDLib
22

3-
Kotlin Coroutines extensions for Telegram API [TDLib](https://github.com/tdlib/td) (Telegram Database
4-
library)
3+
[![](hhttps://jitpack.io/v/akrafts-gpt/td-ktx.svg)](https://jitpack.io/v/#akrafts-gpt/td-ktx)
54

6-
## Using library
5+
Telegram Flow is a Kotlin-first extension toolkit for [TDLib](https://github.com/tdlib/td) 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.
76

8-
The main class of the library is [TelegramFlow]. It converts Telegram Updates handlers to the
9-
Kotlin Coroutine Flows and Telegram callback-style Functions to Kotlin Coroutine suspend functions
7+
## Features
8+
- **Coroutine wrappers** for every TDLib function so you can `suspend` instead of juggling callbacks.
9+
- **Flow-based updates** that emit strongly typed Telegram updates with sensible defaults.
10+
- **Extension interfaces** to organize API access around Telegram entities (users, chats, messages, etc.).
11+
- **Compose-ready**: works seamlessly with `ViewModel` scopes and state flows.
1012

11-
### Start using
13+
## Setup
14+
Add the library dependency from Maven Central:
1215

13-
1. Create instance of [TelegramFlow]
14-
2. You can collect flow of TdApi.Objects from the TelegramFlow instance and its [flow extensions].
15-
3. Call [attachClient] function of the [TelegramFlow] instance to connect it to the Telegram Client.
16-
4. Now you can use numerous [extension functions] to send data to the Telegram API and collect data
17-
from [flow extensions]
18-
19-
### Using Flows
16+
```kotlin
17+
implementation(project(":libtd-ktx"))
18+
```
2019

21-
[Any update](https://core.telegram.org/tdlib/getting-started#handling-updates) listed in TdApi can be collected by corresponding flow extension of the [TelegramFlow].
20+
The `libtd-ktx` module exposes TDLib (`com.github.tdlibx:td:1.8.56`) as an API dependency, so no extra TDLib declaration is required.
2221

23-
```Kotlin
24-
telegramFlow.userStatusFlow().collect { status: TdApi.UpdateUserStatus ->
25-
// collect UpdateUserStatus from Telegram
26-
}
27-
```
22+
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.
2823

29-
For the Updates where there is the only field available inside, Update class is suppress by the flow extension and return data itself, for example:
24+
## Getting started
25+
1. Create a single `TelegramFlow` instance and keep it in a long-lived scope (e.g., via DI).
26+
2. Attach a TDLib client once at startup:
3027

31-
```Kotlin
32-
telegramFlow.authorizationStateFlow().collect { state: TdApi.AuthorizationState ->
33-
// collect AuthorizationState instead of TdApi.UpdateAuthorizationState since there is no other data inside
28+
```kotlin
29+
val telegramFlow = TelegramFlow()
30+
telegramFlow.attachClient()
31+
```
32+
33+
3. Provide required TDLib parameters when prompted by the authorization state flow:
34+
35+
```kotlin
36+
telegramFlow.authorizationStateFlow().collect { state ->
37+
if (state is TdApi.AuthorizationStateWaitTdlibParameters) {
38+
telegramFlow.setTdlibParameters(
39+
databaseDirectory = "/data/user/0/<your.package>/files/td",
40+
apiId = BuildConfig.TELEGRAM_APP_ID,
41+
apiHash = BuildConfig.TELEGRAM_APP_HASH,
42+
// ...other parameters
43+
)
44+
}
3445
}
3546
```
3647

37-
### Using Functions
48+
4. Send authentication information with coroutine calls:
3849

39-
[Any funcrion](https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_function.html) listed in TdApi can be called via corresponding coroutine extension
50+
```kotlin
51+
telegramFlow.setAuthenticationPhoneNumber(phone, null)
52+
telegramFlow.checkAuthenticationCode(code)
53+
telegramFlow.checkAuthenticationPassword(password)
54+
```
55+
56+
## Collecting updates
57+
Every TDLib update has a matching flow extension. Example: tracking user presence changes.
4058

41-
```Kotlin
42-
suspend fun sendCode(code: String) {
43-
api.checkAuthenticationCode(code) // send TdApi.CheckAuthenticationCode(code) to the Client
59+
```kotlin
60+
telegramFlow.userStatusFlow().collect { status ->
61+
val user = telegramFlow.getUser(status.userId)
62+
// update UI with latest user status
4463
}
4564
```
4665

47-
### Using extensions interfaces
66+
For updates that only wrap a single value, the flow returns the inner type directly, e.g. `authorizationStateFlow()` emits `TdApi.AuthorizationState` instances.
4867

49-
Library provides [extension interfaces](https://tdlibx.github.io/td-ktx/docs/libtd-ktx/kotlinx.telegram.extensions/index.html) to access specific Telegram Object's extensions. This allows you to use the library full potential
68+
## Calling Telegram functions
69+
Each TDLib function is exposed as a suspending extension on `TelegramFlow`:
5070

51-
```Kotlin
52-
class YourTelegramClass : UserKtx {
53-
// Instance of the TelegramFlow connecting extensions to the API
54-
override val api = TelegramFlow()
55-
// Flow that returns updates of the user as a full UserInfo
56-
val fullInfoFlow: Flow<TdApi.UserFullInfo> = api.userFlow().map { user ->
57-
user.getFullInfo() // call TdApi.GetUserFullInfo(userId) with id of the user instance
58-
}
59-
}
71+
```kotlin
72+
suspend fun fetchSelf(): TdApi.User = telegramFlow.getMe()
6073
```
61-
All possible extensions for Telegram entities can be accessed via [TelegramKtx]. List and description of available extension interfaces can be found [here](https://tdlibx.github.io/td-ktx/docs/libtd-ktx/kotlinx.telegram.extensions/index.html)
6274

63-
[TelegramFlow]: https://tdlibx.github.io/td-ktx/docs/libtd-ktx/kotlinx.telegram.core/-telegram-flow/index.html
64-
[flow extensions]: https://tdlibx.github.io/td-ktx/docs/libtd-ktx/kotlinx.telegram.flows/index.html
65-
[attachClient]: https://tdlibx.github.io/td-ktx/docs/libtd-ktx/kotlinx.telegram.core/-telegram-flow/attach-client.html
66-
[extension functions]: https://tdlibx.github.io/td-ktx/docs/libtd-ktx/kotlinx.telegram.coroutines/index.html
67-
[TelegramKtx]: https://tdlibx.github.io/td-ktx/docs/libtd-ktx/kotlinx.telegram.extensions/-telegram-ktx/index.html
75+
Explore the full API surface in the [generated docs](https://tdlibx.github.io/td-ktx/docs/libtd-ktx/).
76+
77+
## Samples
78+
A minimal Compose sample lives in [`sample/app`](sample/app). It wires `TelegramFlow` with Hilt, demonstrates handling the authorization flow, and renders online users with Navigation Compose.
79+
80+
## License
81+
This project is distributed under the Apache 2.0 License. See [LICENSE](LICENSE) for details.

app/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/build.gradle

Lines changed: 0 additions & 94 deletions
This file was deleted.

app/src/main/java/com/telegramflow/example/data/local/TelegramCredentials.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)