sochix / TLSharp

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

Join group by name #767

Open Eskat0n opened 6 years ago

Eskat0n commented 6 years ago

How can I join group by name only having hashless link (like https://t.me/WavePools)? I saw issue #591 and the method described there works well but only for links containing hashes.

MightyEvilPunk commented 6 years ago

Hello, Eskaton!

BTW, can you tell me about what hash is? All I see when look in telegram groups is links like you mentioned "https://t.me/WavePools" How do I obtain link with hash?

Eskat0n commented 6 years ago

Telegram bots can acquire link with hash using (invitation link) using Bot API's method exportChatInviteLink (https://core.telegram.org/bots/api#exportchatinvitelink). I don't know myself but somehow I'm 99% sure you can also do that using MTProto via TLSharp.

CheshireCaat commented 6 years ago

Just replace "https://t.me/" And your string will be "WavePools" Not use Bot API :) Work with user's searching for example:

var Update = await Api.SearchUserAsync("WavePools"); var ch = Update.Chats.Where(c => c.GetType() == typeof(TLChannel)).Cast<TLChannel>().FirstOrDefault();

and now you can join if you want it:

var request = new TLRequestJoinChannel() { Channel = new TLInputChannel() { AccessHash = (long)ch.AccessHash, ChannelId = ch.Id } }; and do this request :)

MightyEvilPunk commented 6 years ago

@CheshireCaat Cool!

Is there a way to join a public supergroup similar way?

CheshireCaat commented 6 years ago

@MightyEvilPunk Yes, if you know group invite link For example - https://t.me/joinchat/LINK_HASH If you have this link try this code: var inv_req = new TLRequestImportChatInvite() { Hash = hash_full }; TLUpdates chat = await Api.SendRequestAsync<TLUpdates>(inv_req); Where hash_full == your LINK_HASH from full Join Link Or you can try to find it with searchuserasync by group Title, but it does not always work

CheshireCaat commented 6 years ago

Often public super-groups have such link: https://t.me/groupname as well as just normal group Try my code from the first message for it

MightyEvilPunk commented 6 years ago

@CheshireCaat

Regarding your first response: No, I am talking about public, not private supergroup, so it has link like "https://t.me/groupname", not one with hash.

Regarding second: Yes I tried it and it does not work unfortunately. SearchUserAsync does find supergroup by name from link, but returns it as TLChannelForbidden If I try to generate TLRequestJoinChannel using returned data (TLChannelForbidden has AccessHash and Id as well as TLChannel) I get exception with "CHANNEL_PRIVATE" message on SendRequestAsync execution.

Do you know any workaround for this issue accidentally?

vuminhit commented 4 years ago

Join public group by name

TLFound dialogs = await client.SearchUserAsync("groupusername");
TLChannel chan = dialogs.Chats.Where(c => c.GetType() == typeof(TLChannel))
                        .Cast<TLChannel>()
                        .FirstOrDefault(c => c.Username == ("groupusername"));

 var request = new TLRequestJoinChannel() { Channel = new TLInputChannel() { AccessHash = chan.AccessHash.Value, ChannelId = chan.Id } };
            try
            {
                var Response = await client.SendRequestAsync<Boolean>(request);
            }
            catch (Exception ex)
            {
            }
ahron33 commented 4 years ago

TLFound dialogs = await client.SearchUserAsync("groupusername"); TLChannel chan = dialogs.Chats.Where(c => c.GetType() == typeof(TLChannel)) .Cast() .FirstOrDefault(c => c.Username == ("groupusername"));

var request = new TLRequestJoinChannel() { Channel = new TLInputChannel() { AccessHash = chan.AccessHash.Value, ChannelId = chan.Id } }; try { var Response = await client.SendRequestAsync(request); } catch (Exception ex) { }

where do i put my gorup link?

ahron33 commented 4 years ago

@MightyEvilPunk Yes, if you know group invite link For example - https://t.me/joinchat/LINK_HASH If you have this link try this code: var inv_req = new TLRequestImportChatInvite() { Hash = hash_full }; TLUpdates chat = await Api.SendRequestAsync<TLUpdates>(inv_req); Where hash_full == your LINK_HASH from full Join Link Or you can try to find it with searchuserasync by group Title, but it does not always work

how do i use it?

atrdev-rgb commented 3 years ago

///invite on hide

            var url = "https://t.me/joinchat/SaspY5xrHXlpViOE";
            var channelhash = url.Split("t.me/joinchat/")[1];

            var channelInfohash = client.SendRequestAsync<TLChatInvite>(new TLRequestCheckChatInvite { Hash = channelhash }).ConfigureAwait(false).GetAwaiter();
            while (!channelInfohash.IsCompleted)
            {
                Thread.Sleep(1000);
            }
            var channelhashres = channelInfohash.GetResult();

            var channelInfohash2 = client.SendRequestAsync<TLUpdates>(new TLRequestImportChatInvite { Hash = channelhash }).ConfigureAwait(false).GetAwaiter();
            while (!channelInfohash.IsCompleted)
            {
                Thread.Sleep(1000);
            }
            var channelhashres2 = channelInfohash2.GetResult();

///invite on public

var url = "https://t.me/qwertyuiop";
            var channelname = url.Split("t.me/")[1];
            var channelInfo = client.SendRequestAsync<TgSharp.TL.Contacts.TLResolvedPeer>(
                new TgSharp.TL.Contacts.TLRequestResolveUsername { Username = channelname }).ConfigureAwait(false).GetAwaiter();
            while (!channelInfo.IsCompleted)
            {
                Thread.Sleep(1000);
            }
            var channel = channelInfo.GetResult().Chats.ToList()[0] as TLChannel;

            var Request = new TgSharp.TL.Channels.TLRequestJoinChannel()
            {
                Channel = new TLInputChannel
                {
                    ChannelId = channel.Id,
                    AccessHash = (long)channel.AccessHash
                }
            };

            try
            {
                var Respons = client.SendRequestAsync<TLUpdates>(Request);
                while (!Respons.IsCompleted)
                {
                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                // Do stuff
            }