private async Task ValidateRequestAsync <TResult>(IRequest <TResult> request, Command command, CustomContext context) { IClientApi client = await _telegramService.BuildAsync(command.UserId); var result = (await TelegramRequest.HandleAsync(() => { return(client.CustomRequestsService.SendRequestAsync(request)); }, context)); }
public async Task <Result> HandleAsync(Query query) { IClientApi client = await _telegramService.BuildAsync(query.UserId); TUserFull result = await TelegramRequest.HandleAsync(() => { return(client.UsersService.GetCurrentUserFullAsync()); }); return(new Result(result.User.As <TUser>())); }
public async Task <bool> HandleAsync(Query query) { IClientApi client = await _telegramService.BuildAsync(query.UserId); await TelegramRequest.HandleAsync(() => { return(client.AuthService.LogoutAsync()); }); return(true); }
public async Task <string> HandleAsync(Query query) { string hashedPhoneId = HashHelper.GetHash(query.PhoneNumber); IClientApi client = await _telegramService.BuildAsync(hashedPhoneId).ConfigureAwait(false); ISentCode result = await TelegramRequest.HandleAsync(() => { return(client.AuthService.SendCodeAsync(query.PhoneNumber)); }).ConfigureAwait(false); return(result.PhoneCodeHash); }
public async Task <TUser> HandleAsync(Query query) { string hashedPhoneId = HashHelper.GetHash(query.PhoneNumber); IClientApi client = await _telegramService.BuildAsync(hashedPhoneId).ConfigureAwait(false); var sentCode = new TSentCode() { PhoneCodeHash = query.SentCode }; TUser result = await TelegramRequest.HandleAsync(() => { return(client.AuthService.SignInAsync(query.PhoneNumber, sentCode, query.Code)); }).ConfigureAwait(false); return(result); }
public async Task <bool> HandleAsync(Query query) { IClientApi client = await _telegramService.BuildAsync(query.UserId); byte[] result = (await TelegramRequest.HandleAsync(() => { return(client.FileService.DownloadFullFileAsync(query.Location)); })); return(true); //return new FileInfo() //{ // Content = result, // Name = _guidService.New().ToString("n") //}; }
public async Task <List <Chat> > HandleAsync(Query query) { IClientApi client = await _telegramService.BuildAsync(query.UserId); TDialogs result = (await TelegramRequest.HandleAsync(() => { return(client.MessagesService.GetUserDialogsAsync()); })).As <TDialogs>(); var chats = new List <Chat>(); foreach (IChat chat in result.Chats) { chats.AddWhenNotNull(ChatParser.ParseChat(chat)); } return(chats); }
public async Task ForPeer(int id, PeerType peerType, string userId, int offset, int maxId) { IInputPeer peer = GetPeer(id, peerType); IClientApi client = await _telegramService.BuildAsync(userId); IMessages history = await TelegramRequest.HandleAsync(() => { return(client.MessagesService.GetHistoryAsync(peer, offset, maxId, 100)); }); List <Message> messages = MessagesParser.Parse(history, id, peerType); await _eventHub.SendAsync(messages); if (messages.Count > 0) { BackgroundJob.Schedule <GetMessages>( job => job.ForPeer(id, peerType, userId, offset + 100, 0), TimeSpan.FromSeconds(_randomService.Random.Next(5, 20))); } }
public async Task <List <Contact> > HandleAsync(Query query) { IClientApi client = await _telegramService.BuildAsync(query.UserId); TContacts result = (await TelegramRequest.HandleAsync(() => { return(client.ContactsService.GetContactsAsync()); })); List <Contact> contacts = result.Users.Select(c => { var user = c.As <TUser>(); return(new Contact() { FirstName = user.FirstName, Id = user.Id, LastName = user.LastName, UserName = user.Username }); }).ToList(); return(contacts); }