tdlib_ex 0.44.0
tdlib_ex: ^0.44.0 copied to clipboard
A Dart wrapper and client for Telegram TDLib (tdjson) with generated API classes.
Note: The original author stopped maintaining this repository, so I fixed the code generation, set up a daily check against the latest Telegram protocol scheme, and automated source code updates.
tdlib_ex #
A Dart wrapper for tdlib. Contains generated (generator) schema classes of td_api.tl and a client that interacts with lib through ffi.
The current scheme file is located at data/td_api.tl, and its version is specified in TDLIB_VERSION.md.
Last versions #
See CHANGELOG.md
Legacy versions #
| Version | tdlib commit | td_api.tl revision |
|---|---|---|
| 1.8.39 | last commit | 18618ca |
| 1.8.29 | 6760ab3 | 44b548c |
| 1.8.26 | d7a31ad | b1b33cf |
| 1.8.21 | 32d37d9 | 404761c |
| 1.8.19 | 1a00bae | 986f1ab |
| 1.8.18 | 532fae5 | daf4801 |
| 1.8.15 | 3f91948 | 8893dc8 |
| 1.8.14 | 90171aa | 4041ecb |
| 1.8.13 | d5ed66a | c95598e |
| 1.8.11 | 1b99276 | 1543c41 |
| 1.8.9 | 5b8706c | 6cbe182 |
| 1.8.8 | f069453 | bbe37ee |
| 1.8.7 | 60c2975 | 92f8093 |
| 1.8.4 | 324fa2b | d489014 |
| 1.8.0 | 781d969 | c0385078 |
| 1.7.9 | 2dec79f | 8d7bda00 |
| 1.7.3 | 2a29b25 | - |
Table of Contents #
Integration example #
As an example of use, you can see the project telegram-flutter.
Example #
import 'package:tdlib_ex/td_client.dart';
import 'package:tdlib_ex/td_api.dart' as td;
Future<void> main() async {
final Client client = Client.create();
client.updates.listen((td.TdObject event) async {
print('update: ${event.toJson()}');
});
await client.initialize();
td.Ok result = client.execute<td.Ok>(td.SetLogVerbosityLevel(newVerbosityLevel: 0));
print('execute result: ${result.toJson()}');
td.Updates sendResult = await client.send<td.Updates>(td.GetCurrentState());
print('send result: ${sendResult.toJson()}');
}
Getting started with flutter example #
- Obtain
api_idandapi_hashat https://my.telegram.org - Build tdlib for your operating system following the instruction or download prebuilt binaries (see Prebuilt binaries section below).
- Open
example/lib/main.dartand place obtainedapi_idandapi_hashto appropriate methodsgetApiIdandgetApiHash. - Specify phone number and code in
getPhoneNumberandgetCodemethods. Attention, the phone number must be specified from the test DC. If you don't want to use the test DC and want to authenticate with your account, changeuseTestDctofalseinTdlibParameters. - cd
<repo folder>/example flutter run
Prebuilt binaries #
The original author stopped updating prebuilt binaries in 2024 (previously published on the releases page). For updated native binaries, please refer to the following repositories:
- tdlib.native releases
- Android binaries: android-libtdjson releases
- iOS/macOS binaries: ios-libtdjson releases
Follow the instructions below for each platform to configure your Flutter project to use tdlib.
Android #
Copy .so files from archive to example/android/app/main/jniLibs:
└── example
└── android
└── app
└── main
└── jniLibs
└── arm64-v8a
│ └── libtdjsonandroid.so
└── armeabi-v7a
│ └── libtdjsonandroid.so
└── x86
│ └── libtdjsonandroid.so
└── x86_64
└── libtdjsonandroid.so
- Open file
example/android/app/build.gradle
replace
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
by
sourceSets {
main {
java.srcDirs += 'src/main/kotlin'
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
iOS and macOS #
- Copy
libtdjson.dylibfrom archive toexample/ios - Copy
libtdjson.dylibfrom archive toexample/macos
└── example
└── ios
│ └── libtdjson.dylib
└── macos
└── libtdjson.dylib
- Open
Runner.xcworkspacein Xcode. - Add
.dylibfile to project. - Find
Frameworks, Libraries, and EmbeddedContent. - Against
libtdjson.dylibchooseEmbed & Sign. - Find
Signing & Capabilities. - In Section
App Sandbox (Debug and Profile)set trueOutgoing Connections (Client).
Windows #
- Copy files from archive to
example/windows/tdlib
└── example
└── windows
└── tdlib
└── libcrypto-1_1.dll
└── libssl-1_1.dll
└── tdjson.dll
└── zlib1.dll
- Open
example/windows/CMakeLists.txt. - Add below line
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}"):
# begin td
set(dll_path "${CMAKE_CURRENT_SOURCE_DIR}/tdlib")
install(FILES "${dll_path}/libcrypto-1_1.dll" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime)
install(FILES "${dll_path}/libssl-1_1.dll" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime)
install(FILES "${dll_path}/tdjson.dll" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime)
install(FILES "${dll_path}/zlib1.dll" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime)
# end td
Linux #
- Copy file from archive to
example/linux/tdlib
└── example
└── linux
└── tdlib
└── libtdjson.so
- Open
example/linux/CMakeLists.txt. - Add at the end of file:
# begin td
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/tdlib/libtdjson.so" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)
# end td
Web #
TBD
Code Generation #
If you need a specific version of TDLib that is not provided by this package, you can generate Dart classes for your required version:
- Fork this repository.
- Replace
data/td_api.tlwith thetd_api.tlfile (located attd/generate/scheme/td_api.tl) for your desired version from the TDLib repository.Note: You can find the corresponding
td_api.tlversion in theCMakeLists.txtfile of the TDLib repository. - Rebuild the generated Dart classes by running:
dart run generator/lib/src/main.dart && dart format lib - Ensure that the version of your native TDLib binary matches the version of
td_api.tlused for generation.
Note: Unfortunately, as the package maintainer, it is not feasible for me to build and provide binaries for all TDLib versions across all target platforms. You will need to find or build the ready-made native binaries yourself. Some useful links are available in the Prebuilt binaries section above.