Skip to content
C#/.NET Core bindings for TDLib (Telegram MTProto API)
C#
Branch: master
Clone or download

Latest commit

x2bool Merge pull request #35
Upgrade to 1.6 API
Latest commit 6ff96f3 Feb 21, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Samples/TdLib.Samples.GetChats Adding sample project Jan 9, 2020
TDLib.Api Bump package version to 1.6.0 Feb 21, 2020
TDLib.Tests Bump package version to 1.6.0 Feb 21, 2020
TDLib
.gitignore Initial Mar 5, 2018
LICENSE Add license Sep 4, 2018
README.md Mention extension methods in README Feb 21, 2020
TDLib.sln Adding sample project Jan 9, 2020

README.md

TDLib

.NET bindings for TDLib (Telegram Database Library): https://github.com/tdlib/td

  • Generated API bindings
  • .NET Core and .NET Standard support

Installation

Install via NuGet: TDLib

NuGet

Dependencies

You're recommended to use precompiled version of TDLib native artifacts from NuGet: TDLib.Native

NuGet

Note that tdlib.native is not a dependency of TDLib, so you may choose to build the binaries yourself and provide them at the runtime.

To do that, build TDLib and put the compiled library into your project's output directory

  • tdjson.dll (Windows) (optionally accompanied by other DLL files from the build directory if you want to bundle OpenSSL and ZLib dependencies as well)
  • libtdjson.dylib (MacOS)
  • libtdjson.so (Linux)

Using json client

TdJsonClient is a wrapper around native JSON APIs. Use it to send/receive data as strings.

using TdLib;

var json = ""; // json data
double timeout = 1.0; // 1 second

using (var jsonClient = new TdJsonClient())
{
    jsonClient.Send(json); // send request
    var result = jsonClient.Receive(timeout); // receive response
}

Using strongly typed APIs

This library contains generated classes for objects and functions. JSON serialization and deserialization is handled automatically. Use TdClient to asynchronously execute functions.

using TdLib;

using (var client = new TdClient())
{
    try
    {
        // asynchronously execute function
        TdApi.Ok ok = await client.ExecuteAsync(new TdApi.SetAuthenticationPhoneNumber
        {
            PhoneNumber = phoneNumber
        });

        // or use extension method
        ok = await client.SetAuthenticationPhoneNumberAsync(phoneNumber);

        // do something...
    }
    catch (ErrorException e)
    {
        TdApi.Error error = e.Error;

        // handle error...
    }
}
You can’t perform that action at this time.