sochix / TLSharp

Telegram client library implemented in C#
1k stars 380 forks source link

How do I get users of a chat? #854

Closed borseno closed 5 years ago

borseno commented 5 years ago

How do I get users of a chat? Not of a CHANNEL, but of a group chat.

that's how i get a chat I need. //find chat by title var chat = dialogs.Chats .Where(c => c.GetType() == typeof(TLChat)) .Cast() .FirstOrDefault(c => c.Title == ChatTitle);

Now I want to get the list of users of that chat. How do I get there? TLChat does not contain a property that returns the list of users in that group chat

borseno commented 5 years ago

I found how to do it with a group chat, I'll send the code later

AndreyWh commented 5 years ago

I found how to do it with a group chat, I'll send the code later

Can u pls send it? I'll be grateful

AndreyWh commented 5 years ago
var dialogs = (TLDialogs)await client.GetUserDialogsAsync();
            var main = dialogs.Chats.ToList().Where(c => c.GetType() == typeof(TLChat))
                        .Cast<TLChat>()
                        .FirstOrDefault(c => c.Title == ("GROUP_NAME"));
            var req = new TLRequestGetFullChat
            {
                ChatId = main.Id
            };
            var res = await client.SendRequestAsync<TeleSharp.TL.Messages.TLChatFull>(req);
            var chatUsers = res.Users.ToList();
            foreach(var chatUser in chatUsers)
            {
                var user = chatUser as TLUser; // to get user id
                await client.SendMessageAsync(new TLInputPeerUser() { UserId = user.Id }, "<MESSAGE>");
            }

Maybe it could be useful for someone