WTC.Abstractions.Account
1.0.1
dotnet add package WTC.Abstractions.Account --version 1.0.1
NuGet\Install-Package WTC.Abstractions.Account -Version 1.0.1
<PackageReference Include="WTC.Abstractions.Account" Version="1.0.1" />
paket add WTC.Abstractions.Account --version 1.0.1
#r "nuget: WTC.Abstractions.Account, 1.0.1"
// Install WTC.Abstractions.Account as a Cake Addin #addin nuget:?package=WTC.Abstractions.Account&version=1.0.1 // Install WTC.Abstractions.Account as a Cake Tool #tool nuget:?package=WTC.Abstractions.Account&version=1.0.1
WTelegramClient Account Handler
this small project intents to make it easier to work with multiple telegram accounts inside the WTelegramClient library, it offers multiple ways of constructing accounts as well as a nice little AccountBuilder
.
it also offers a AccountHandler
which can handle all your accounts and have some extra functionality.
use
simply install the library: dotnet add package WTC.Abstractions.Account
Create Accounts
you can create accounts from different ways
- from scratch:
var acc1 = new TelAccount("API_ID", "API_HASH", "PHONE");
var acc2 = new TelAccount("API_ID", "API_HASH", "PHONE", isUseTest: true);
here you can also pass your 2FA
password or firstName
& lastName
if you want. they are optional.
- using builder:
var acc3 = TelAccountBuilder.New()
.WithHash("")
.WithApiId("")
.WithPhone("")
.WithFirstName("")
.WithLastName("")
.WithTwoFactorAuth("")
.UseTestServers(true) //default to false
.Build();
note that some of there settings or optional, the required ones are:
var acc4 = TelAccountBuilder.New()
.WithHash("")
.WithApiId("")
.WithPhone("")
.Build();
after building a TelAccount
, you need to create a AccountHandler
to work with your Telegram Accounts.
Create Account Handler
creating a handler might be a bit more difficult if you are not sure with this type of design, take a look at this:
var accountHandler = await AccountBuilder
.CreateAccounts()
.FromAccount(acc1, () =>
{
Console.WriteLine("Enter The Code:");
return Console.ReadLine()!;
}, "acc1")
.BuildAsync();
calling .CreateAccounts()
gives us the opportunity to define every account that we have,
you can see the we are passing 3 arguments:
- the first one is your
TelAccount
structure that we defined earlier. - second is a
Func
that is responsible for handling authentication from the code you receive from Telegram. - third is your session file path AND the name of your client(the file name will be the name not the path), it defaults to
WTC.session
.
and after that we are doing .BuildAsync()
which obviously builds the handler for us.
important thing to remember here is that the BuildAsync
actually accepts a boolean that indicates whether we want to dispose the client after login or not.
.BuildAsync(true);
//or
.BuildAsync((name, client) => {
return name is "acc2";
})
you can also check for a specific condition on each client to decide if you want to dispose them or not..
you can chain multiple accounts and also, you can use the AccountBuilder
inside the handler:
var accountHandler = await AccountBuilder
.CreateAccounts()
.FromAccount(acc1, () =>
{
Console.WriteLine("Enter The Code:");
return Console.ReadLine()!;
}, "acc1")
.FromAccount(builder => builder
.WithHash("")
.WithApiId("")
.WithPhone("")
, () => "", "acc2")
.BuildAsync(true);
notice how we use builder on the second account.
now that you got your clients, you can access them:
- by client's name
var wClient = accountHandler.ByName("acc1");
-get all of them
var allClients = accountHandler.GetClients();
- iterate over them:
await accountHandler
.WithDelay(TimeSpan.FromSeconds(2))
.OnParallel()
.ForEachClientAsync((client, name) =>
{
client.OnUpdate += u =>
{
Console.WriteLine($"got an update from {name}.");
return Task.CompletedTask;
};
return Task.CompletedTask;
});
if you dont call OnParallel
your iteration will NOT be parallelized.
and also the WithDelay
call is optional.
the complete example is available here.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. net6.0-windows7.0 is compatible. net7.0 is compatible. 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. net7.0-windows7.0 is compatible. net8.0 is compatible. 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. net8.0-windows7.0 is compatible. |
-
net6.0
- WTelegramClient (>= 3.6.4)
-
net6.0-windows7.0
- WTelegramClient (>= 3.6.4)
-
net7.0
- WTelegramClient (>= 3.6.4)
-
net7.0-windows7.0
- WTelegramClient (>= 3.6.4)
-
net8.0
- WTelegramClient (>= 3.6.4)
-
net8.0-windows7.0
- WTelegramClient (>= 3.6.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.