tdlib-dart

September 21, 2025 · View on GitHub

⚠️ Archived

This repository is no longer maintained.

I am no longer interested in Dart and don’t have time to continue development or provide support.

tdlib-dart

A Dart wrapper for tdlib. Contains generated(generator) schema classes of td_api.tl and a client that interacts with lib through ffi.

Versiontdlib committd_api.tl revision
1.8.39last commit18618ca
1.8.296760ab344b548c
1.8.26d7a31adb1b33cf
1.8.2132d37d9404761c
1.8.191a00bae986f1ab
1.8.18532fae5daf4801
1.8.153f919488893dc8
1.8.1490171aa4041ecb
1.8.13d5ed66ac95598e
1.8.111b992761543c41
1.8.95b8706c6cbe182
1.8.8f069453bbe37ee
1.8.760c297592f8093
1.8.4324fa2bd489014
1.8.0781d969c0385078
1.7.92dec79f8d7bda00
1.7.32a29b25-

Table of Contents

Integration example

As an example of use, you can see the project telegram-flutter.

Example

import 'package:tdlib/td_client.dart';
import 'package:tdlib/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

  1. Obtain api_id and api_hash at https://my.telegram.org
  2. Build tdlib for your operating system following the instruction or download prebuild binaries. Following the instraction below for setup tdlib.
  3. Open example/lib/main.dart and place obtained api_id and api_hash to appropriate methods getApiId and getApiHash.
  4. Specify phone number and code in getPhoneNumber and getCode methods. 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, change useTestDc to false in TdlibParameters.
  5. cd <repo folder>/example
  6. flutter run

Prebuilt binaries

The tdlib binaries is built automatically using github actions and published on the releases page. Follow the instructions below for each platform to configure 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
  1. 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

  1. Copy libtdjson.dylib from archive to example/ios
  2. Copy libtdjson.dylib from archive to example/macos
└── example 
    └── ios 
    │   └── libtdjson.dylib
    └── macos
        └── libtdjson.dylib
  1. Open Runner.xcworkspace in Xcode.
  2. Add .dylib file to project.
  3. Find Frameworks, Libraries, and EmbeddedContent.
  4. Against libtdjson.dylib choose Embed & Sign.
  5. Find Signing & Capabilities.
  6. In Section App Sandbox (Debug and Profile) set true Outgoing Connections (Client).

Windows

  1. Copy files from archive to example/windows/tdlib
└── example 
    └── windows 
        └── tdlib 
            └── libcrypto-1_1.dll
            └── libssl-1_1.dll
            └── tdjson.dll
            └── zlib1.dll
  1. Open example/windows/CMakeLists.txt.
  2. 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

  1. Copy file from archive to example/linux/tdlib
└── example 
    └── linux 
        └── tdlib 
            └── libtdjson.so
  1. Open example/linux/CMakeLists.txt.
  2. 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