Skip to content

Poudyn/PTClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PTClient

Framework for easier use of Telegram.Td

  • Set Delegate for get updates
  • Filter updates
    • Filter by type
    • Filter by type & linq
  • Get specific value from filtered update with RefToken
  • Uses methods with a specific type of return that are generated by PTClient.Generator
    • The return type is TdResult

Filter all updates

var filterAll = new Filter<Update>(x=>Console.WriteLine(x.GetType()));

Filter special update by linq

var filterByLinq = new Filter<UpdateAuthorizationState>(OnAuthorizationStateWaitTdlibParameters,
                                                     x => x.AuthorizationState.GetType() == typeof(AuthorizationStateWaitTdlibParameters));
                                                     
void OnAuthorizationStateWaitTdlibParameters(UpdateAuthorizationState state)
{
//do something
}

Get special value from update

var specialValue = new Filter<UpdateNewMessage, string>(x => Console.WriteLine(x), "Message.Content.Text.Text")
  • This filter gives you the text of the message

Get special value from filtered update

var specialValue = new Filter<UpdateNewMessage, string>(x => Console.WriteLine(x), x=>x.Message.ChatId == 00000000 , "Message.Content.Text.Text")
  • When a message is received from a chat with the ChatId 00000000, the text of the message will be provided to you

Add a disposable filter

 tdClient.AddDisposableFilter(new Filter<UpdateFile>(x => Console.WriteLine("Downloaded"), x => x.File.Id == 0000 && x.File.Local.IsDownloadingCompleted));
  • When the file with the ID 000 is downloaded, it tells you that the file was downloaded

Create Client

var filters = new List<IFilter>(//anyfilter):
tdClient = new TdClient(filters);
tdClient.Run();

Send a request without having to receive a response

TdlibParameters parameters = new()
{
//// parameters
};
tdClient.Send(new SetTdlibParameters(parameters));

Send request and receive result

TdResult<Ok> tdResult = await  tdClient.SetAuthenticationPhoneNumberAsync(new SetAuthenticationPhoneNumber
{
  PhoneNumber = "+1....."
});
if(tdResult.Successful)
{
  Console.WriteLine(tdResult.Result);
}
else
{
 Console.WriteLine($"Message : {tdResult.Error.Message} Code : {tdResult.Error.Code}");
}

About Me & This project

This was my first project and I tried to write a useful and easy project. If you have an idea or opinion, be sure to let me know Also, this project is based on version 1.7 of Telegram.Td, and if you have a higher version of Telegram.Td, share it with me to update the project. An example project will be available soon

Contact with me : Telegram

News : Telegram Channel

About

C#/.Net Core framework for Telegram.Td

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages