예제 #1
0
파일: Process.cs 프로젝트: FWTLOld/Telegram
            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));
            }
예제 #2
0
파일: GetMe.cs 프로젝트: FWTLOld/Telegram
            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>()));
            }
예제 #3
0
            public async Task <bool> HandleAsync(Query query)
            {
                IClientApi client = await _telegramService.BuildAsync(query.UserId);

                await TelegramRequest.HandleAsync(() =>
                {
                    return(client.AuthService.LogoutAsync());
                });

                return(true);
            }
예제 #4
0
            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);
            }
예제 #5
0
            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);
            }
예제 #6
0
            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")
                //};
            }
예제 #7
0
            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);
            }
예제 #8
0
        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)));
            }
        }
예제 #9
0
            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);
            }