A Java Wrapper for TDLib/TDLight
Go to file
2020-11-22 02:45:13 +01:00
dependencies Update tdlight 2020-11-15 18:17:18 +01:00
example Quick fix 2020-10-23 04:45:49 +02:00
jenkins Update generate_tdapi.sh 2020-10-11 16:46:47 +02:00
src/main Remove again initialization lock 2020-11-15 23:38:30 +01:00
tdapi Update CMakeLists.txt 2020-10-11 16:32:30 +02:00
tdlib Updated tdlight natives 2020-11-22 02:45:13 +01:00
tdlight Updated tdlight natives 2020-11-22 02:45:13 +01:00
.gitignore Update .gitignore 2020-11-11 20:48:30 +01:00
.gitmodules Add tdapi generator 2020-10-07 15:20:59 +02:00
Jenkinsfile Update Jenkinsfile 2020-10-30 15:59:46 +01:00
jitpack.yml Updated jitpack.xml 2020-08-06 12:13:31 +02:00
JTDLIB_LICENSE Rewrite ReadMe 2020-08-20 12:18:04 +02:00
LICENSE Added missing license 2018-11-20 18:51:11 +01:00
README.md Update TDLight 2020-11-10 19:11:45 +01:00

TDLight Java

Build Status Release tag

A barebone java wrapper for TDLib (and TDLight)

This wrapper gives you direct access to TDLib API in Java.

Requirements

JVM: Oracle JVM or OpenJDK

Java versions: Java 8, 9, 10, 11, 12, 13, 14, 15

Operating system: Linux, Windows, macOS

Supported CPU architectures: amd64 (linux, windows, macos), aarch64 (linux)

Required libraries for linux: OpenSSL and zlib

Including TDLight Java in a project

There are two packages of TDLight:

The two packages are compatible, but while TDLight is focused on long term resources usage and speed, TDLib is more focused on stability.

Choose one of the two different TDLight packages and then follow the guide below.

Replace REPLACE_WITH_LATEST_VERSION with the latest version of tdlight, you can find it on the Releases tab on github.

For TDLight Java with optimized TDLight

Maven

Repository:

<repositories>
  <repository>
    <id>mchv</id>
    <name>MCHV Apache Maven Packages</name>
    <url>https://mvn.mchv.eu/repository/mchv/</url>
  </repository>
</repositories>

Dependency:

<dependency>
<groupId>it.tdlight</groupId>
<artifactId>tdlight-java</artifactId>
<version>REPLACE_WITH_LATEST_VERSION</version>
</dependency>

Gradle

repositories {
     maven { url "https://mvn.mchv.eu/repository/mchv/" }
}
dependencies {
     implementation 'it.tdlight:tdlight-java:REPLACE_WITH_LATEST_VERSION'
}

For TDLight Java with official TDLib

Maven

Repository:

<repositories>
  <repository>
    <id>mchv</id>
    <name>MCHV Apache Maven Packages</name>
    <url>https://mvn.mchv.eu/repository/mchv/</url>
  </repository>
</repositories>

Dependency:

<dependency>
<groupId>it.tdlight</groupId>
<artifactId>tdlib-java</artifactId>
<version>REPLACE_WITH_LATEST_VERSION</version>
</dependency>

Gradle

repositories {
     maven { url "https://mvn.mchv.eu/repository/mchv/" }
}
dependencies {
     implementation 'it.tdlight:tdlib-java:REPLACE_WITH_LATEST_VERSION'
}

Usage

Simple initialization of a native TDLib client

package it.tdlight.example;

import it.tdlight.common.TelegramClient;
import it.tdlight.tdlight.ClientManager;
import it.tdlight.common.Init;
import it.tdlight.common.Log;
import it.tdlight.common.TDLibException;

import it.tdlight.jni.TdApi;

public class Example {
    public static void main(String[] args) {
        // Initialize TDLight native libraries
        Init.start();

        // Create a client
        TelegramClient client = ClientManager.create(Example::onUpdate, Example::onUpdateError, Example::onError);

        // Here you can use the client.

        // Documentation of tdlib methods can be found here:
        // https://tdlight-team.github.io/tdlight-docs

        // A similar example on how to use tdlib can be found here:
        // https://github.com/tdlib/td/blob/master/example/java/org/drinkless/tdlib/example/Example.java
    }

    private static void onUpdate(TdApi.Object object) {
        TdApi.Update update = (TdApi.Update) object;
        System.out.println("Received update: " + update);
    }

    private static void onUpdateError(Throwable exception) {
        if (exception instanceof TDLibException) {
        	String errorMessage = ((TDLibException) exception).getErrorMessage();
            System.out.println("Received an error from updates: " + errorMessage);
        } else {
            System.out.println("Received an error from updates:");
            exception.printStackTrace();
        }
    }

    private static void onError(Throwable exception) {
        if (exception instanceof TDLibException) {
        	String errorMessage = ((TDLibException) exception).getErrorMessage();
            System.out.println("Received an error: " + errorMessage);
        } else {
            System.out.println("Received an error:");
            exception.printStackTrace();
        }
    }
}

TDLib methods documentation

TdApi class javadoc

TDLight extended features

TDLight Java with TDLight has some extended features, that you can see on the TDLight official repository.

This features are present only if you use the optimized TDLight package.

About

License

TDLight is licensed by Andrea Cavalli andrea@cavallium.it under the terms of the GNU Lesser General Public License 3

Libraries licenses

JTDlib is licensed by Ernesto Castellotti erny.castell@gmail.com under the terms of the GNU Lesser General Public License 3

TDLib is licensed by Aliaksei Levin levlam@telegram.org and Arseny Smirnov arseny30@gmail.com under the terms of the Boost Software License

OpenSSL is licensed under the terms of Apache License v2

Zlib is licensed under the terms of Zlib license