WTelegramClient 0.7.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package WTelegramClient --version 0.7.1
                    
NuGet\Install-Package WTelegramClient -Version 0.7.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WTelegramClient" Version="0.7.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WTelegramClient" Version="0.7.1" />
                    
Directory.Packages.props
<PackageReference Include="WTelegramClient" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WTelegramClient --version 0.7.1
                    
#r "nuget: WTelegramClient, 0.7.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WTelegramClient@0.7.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WTelegramClient&version=0.7.1
                    
Install as a Cake Addin
#tool nuget:?package=WTelegramClient&version=0.7.1
                    
Install as a Cake Tool

WTelegramClient

Telegram client library written 100% in C# and .NET Core

How to use

⚠️ This library relies on asynchronous C# programming (async/await) so make sure you are familiar with this before proceeding.

After installing WTelegramClient through Nuget, your first Console program will be as simple as:

static Task Main(string[] _)
{
    using var client = new WTelegram.Client();
    await client.ConnectAsync();
    var user = await client.UserAuthIfNeeded();
    Console.WriteLine($"We are logged-in as {user.username ?? user.first_name + " " + user.last_name} (id {user.id})");
}

When run, this will prompt you interactively for your App api_id and api_hash (that you obtain through Telegram's API development tools page) and try to connect to Telegram servers.

Then it will attempt to sign-in as a user for which you must enter the phone_number and the verification_code that will be sent to this user (for example through SMS or another Telegram client app the user is connected to).

If the verification succeeds but the phone number is unknown to Telegram, the user might be prompted to sign-up (accepting the Terms of Service) and enter their first_name and last_name.

And that's it, you now have access to the full range of Telegram services, mainly through calls to await client.CallAsync(...)

Saved session

If you run this program again, you will notice that the previous prompts are gone and you are automatically logged-on and ready to go.

This is because WTelegramClient saves (typically in the encrypted file bin\WTelegram.session) its state and the authentication keys that were negociated with Telegram so that you needn't sign-in again every time.

That file path is configurable, and under various circumstances (changing user or server address) you may want to change it or simply delete the existing session file in order to restart the authentification process.

Non-interactive configuration

Your next step will probably be to provide a configuration to the client so that the required elements (in bold above) are not prompted through the Console but answered by your program.

For that you need to write a method that will provide the answer, and pass it on the constructor:

static string Config(string what)
{
    if (what == "api_id") return "YOUR_API_ID";
    if (what == "api_hash") return "YOUR_API_HASH";
    if (what == "phone_number") return "+12025550156";
    if (what == "verification_code") { Console.Write("Code: "); return Console.ReadLine(); }
    if (what == "first_name") return "John"; // if sign-up is required
    if (what == "last_name") return "Doe";   // if sign-up is required
    return null;
}
...
using var client = new WTelegram.Client(Config);

There are other configuration items that are queried to your method but returning null let WTelegramClient choose a default adequate value.

The configuration items shown above are the only ones that have no default values and are required to be provided by your method.

The constructor also takes another optional delegate parameter that will be called for any other Update and other information/status/service messages that Telegram sends unsollicited, independently of your API requests.

Finally, if you want to redirect the library logs to your logger instead of the Console, you can install a delegate in the WTelegram.Helpers.Log static property. Its int argument is the log severity, compatible with the classic LogLevel enum

Example of API call

ℹ️ The Telegram API makes extensive usage of base and derived classes, so be ready to use the various syntaxes C# offer to check/cast base classes into the more useful derived classes (is, as, case DerivedType )

To find which derived classes are available for a given base class, the fastest is to check our TL.Schema.cs source file as they are listed in groups.

The Telegram API object classes are defined in the TL namespace, and the request classes (API functions) usable with client.CallAsync are under the TL.Fn static class.

Below is an example of calling the messages.getAllChats API function and enumerating the various groups/channels the user is in:

using TL;
...
var chatsBase = await client.CallAsync(new Fn.Messages_GetAllChats { });
if (chatsBase is not Messages_Chats { chats: var chats }) throw new Exception("hu?");
Console.WriteLine("This user has joined the following:");
foreach (var chat in chats)
    switch (chat)
    {
        case Chat smallgroup when (smallgroup.flags & Chat.Flags.deactivated) == 0:
            Console.WriteLine($"{smallgroup.id}:  Small group: {smallgroup.title} with {smallgroup.participants_count} members");
            break;
        case Channel channel when (channel.flags & Channel.Flags.broadcast) != 0:
            Console.WriteLine($"{channel.id}: Channel {channel.username}: {channel.title}");
            break;
        case Channel group:
            Console.WriteLine($"{group.id}: Group {group.username}: {group.title}");
            break;
    }

Other things to know

An invalid API request can result in a RpcException being raised, reflecting the error code and status text of the problem.

Beyond CallAsync, the Client class offers a few other methods to simplify the sending of files, medias or messages.

The other configuration items that you can override include: session_pathname, server_address, device_model, system_version, app_version, system_lang_code, lang_pack, lang_code

Development status

The library is already well usable for many scenarios involving automated steps based on API requests/responses.

Here are the main expected developments:

  • Encrypt session file
  • Support SignUp of unregistered users
  • Improve code Generator (import of TL-schema JSONs)
  • Improve Nuget deployment experience (debug symbols? XML documentation?)
  • Convert API functions classes to real methods and serialize structures without using Reflection
  • Separate task/thread for reading/handling update messages independently from CallAsync
  • Support MTProto 2.0
  • Support users with 2FA enabled
  • Support secret chats end-to-end encryption & PFS
  • Support all service messages

Build Status NuGet version

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (12)

Showing the top 5 NuGet packages that depend on WTelegramClient:

Package Downloads
WTelegramBot

Telegram Bot API (local server) library providing more extended features Release Notes: Made it easier to use MTProxy with WTelegramBotClient(Options)

WTelegramClient.Extensions.Updates

Extensions over WtelegramClient For Dealing With Updates

GKit.TelegramHost

Package Description

MTProto

A MTProto client library based on wiz0u/WTelegramClient

ProfitSniper.Profitview

Package Description

GitHub repositories (5)

Showing the top 5 popular GitHub repositories that depend on WTelegramClient:

Repository Stars
AlexWan/OsEngine
Open Source algo trading platform
yiyungent/KnifeHub
🧰 简单易用的效率工具平台
Riniba/TelegramMonitor
Telegram监听关键词|TG抓需求|实时监测频道|telegram关键词监控|电报|tg关键词监控|telegram监控机器人|主动获取|消息订阅|telegram消息监控|tg自动发送消息|telegram群消息接收|关键词报警|多群监控|自动化群管理|telegram数据分析 Telegram Keyword Listening | TG Demand Capture | Real-Time Channel Monitoring | Telegram Keyword Monitoring | Telegram | TG Keyword Monitoring | Telegram Monitoring Bot | Active Retrieval | Subscription
moeacgx/Telegram-Panel
Telegram多账号多功能管理面板
DamianMorozov/OpenTgResearcher
OpenTgResearcher - tool for analyzing Telegram chats and downloading their content
Version Downloads Last Updated
4.4.3 2,870 4/3/2026
4.4.3-dev.3 51 4/3/2026
4.4.3-dev.1 44 4/3/2026
4.4.2 8,028 3/6/2026
4.4.2-dev.4 54 3/6/2026
4.4.2-dev.3 47 3/6/2026
4.4.2-dev.2 44 3/6/2026
4.4.2-dev.1 48 3/6/2026
4.4.1 9,335 2/3/2026
4.4.1-dev.2 70 2/3/2026
4.4.0 7,963 1/3/2026
4.3.16-dev.3 68 1/3/2026
4.3.15 2,956 12/19/2025
4.3.15-dev.2 248 12/16/2025
4.3.15-dev.1 238 12/16/2025
4.3.14 6,800 11/15/2025
4.3.14-dev.3 132 11/15/2025
4.3.14-dev.1 267 11/13/2025
4.3.13 1,620 11/11/2025
0.7.1 1,936 8/8/2021
Loading failed