From 92ca5a9ac112db86f193dbee1107404fd6126263 Mon Sep 17 00:00:00 2001 From: solarin Date: Fri, 3 Apr 2020 17:35:18 +0400 Subject: [PATCH] + GetFullChat to get the info of a chat + GetAllChats to get all available user's chats + MakeAuthBotAsync to authenticate a bot instead of a user --- TLSharp.Core/TelegramClient.cs | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index cee8c00..d4906a8 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -434,6 +434,69 @@ namespace TLSharp.Core .ConfigureAwait(false); } + /// + /// Authenticates a Bot + /// + /// The token of the bot to authenticate + /// + /// The TLUser descriptor + public async Task MakeAuthBotAsync(string botAuthToken, CancellationToken token = default(CancellationToken)) + { + if (String.IsNullOrWhiteSpace(botAuthToken)) + { + throw new ArgumentNullException(nameof(botAuthToken)); + } + + var request = new TLRequestImportBotAuthorization() { BotAuthToken = botAuthToken, ApiId = apiId, ApiHash = apiHash }; + + await RequestWithDcMigration(request, token).ConfigureAwait(false); + + OnUserAuthenticated(((TLUser)request.Response.User)); + + return ((TLUser)request.Response.User); + } + + /// + /// Gets the full information of a specified chat + /// + /// The ID of the chat we want the info of + /// + /// + public async Task GetFullChat(int chatId, CancellationToken token = default(CancellationToken)) + { + var req = new TLRequestGetFullChat() { ChatId = chatId }; + var fchat = await SendRequestAsync(req).ConfigureAwait(false); + + return fchat; + } + + /// + /// Gets the list of chats opened by the authenticated user. + /// Throws an exception if the authenticated user is a bot. + /// + /// + /// The list of chats opened by the authenticated user + public async Task GetAllChats(CancellationToken token = default(CancellationToken)) + { + return await GetAllChats(null, token); + } + + /// + /// Gets the list of chats opened by the authenticated user except the passed ones. + /// Throws an exception if the authenticated user is a bot. + /// + /// The IDs of the chats that we don't want to be returned + /// + /// The list of chats opened by the authenticated user + public async Task GetAllChats(int[] exceptIds = null, CancellationToken token = default(CancellationToken)) + { + var ichats = new TeleSharp.TL.TLVector(); // we can't pass a null argument to the TLRequestGetChats + if (exceptIds != null) + Array.ForEach(exceptIds, x => ichats.Add(x)); + var chatInfo = await SendRequestAsync(new TLRequestGetChats() { Id = ichats }).ConfigureAwait(false); + return chatInfo; + } + /// /// Serch user or chat. API: contacts.search#11f812d8 q:string limit:int = contacts.Found; ///