LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!
https://docs.telethon.dev
MIT License
9.94k stars 1.4k forks source link

How to add user to super group #103

Closed atabaki closed 7 years ago

atabaki commented 7 years ago

How can implement add members functionality in supergroups same as telegram desktop Suppose i,m not the creator of that supergroup. Using AddChatUserRequest leads to invalid_chat_id Using InviteToChannelRequest need admin privillages

But as u can test, in telegram desktop you can join to one supergroup and add members without admin permission What method must be used to achieve this functionality?

Lonami commented 7 years ago

You know those links which look like https://t.me/joinchat/AAAAAFFszQPyPEZ7wgxLtd (that's a non-existing example)? Well, the part after the joinchat/ is the hash of the group. You can use ImportChatInviteRequest to join to such chat.

atabaki commented 7 years ago

No Wee need to add another user not my own account RequestImportChatInvite is for adding me to one chat (superGroup) i need add you (for example) to super group with id and accessHash

Lonami commented 7 years ago

Then you're probably talking about AddChatUserRequest.

Edit: Yes, you're talking about that (just confirmed). Remember to use the documentation search, it's the same thing I do.

Edit 2: Okay then, my bad… I really should have read more carefully what you wrote. Still of use.

atabaki commented 7 years ago

Thanks For your Replay But When u use "AddChatUserRequest" (as mentioned before) The "INVALID_CHAT_ID" Error Will occur because super groups are Channel Type and Therefor have Channel Id and Channel Access Hash When We pass Channel.Id as Chat_Id in AddChatUserRequest , "Invalid_chat_id" Error has raisen

Lonami commented 7 years ago

Make sure you're using get_input_peer:

from telethon.helpers import get_input_peer

You need to pass an InputPeerChat, not the Chat itself.

atabaki commented 7 years ago

in scheme.tl we have: messages.addChatUser#f9a0aa09 chat_id:int user_id:InputUser fwd_limit:int = Updates;

chat_id must be int

lastest layer: https://raw.githubusercontent.com/telegramdesktop/tdesktop/dev/Telegram/Resources/scheme.tl

Lonami commented 7 years ago

chat_id must be int

Er, yeah, sorry. Still need to use the get_input_peer for the user though.

Lonami commented 7 years ago

InviteToChannelRequest?

Edit: Okay, you did mention that already, but really, it's everything I can find.

atabaki commented 7 years ago

it's for admin of super groups but how telegram desktop implement this

Lonami commented 7 years ago

Well, I cannot add users to a super group I'm not the admin of. The option doesn't even show. So Telegram Desktop does not implement that. You need permission, of course.

atabaki commented 7 years ago

No In Super Groups You can add your friends but it's not necessary to be admin try now

Lonami commented 7 years ago

In Super Groups You can add your friends but it's not necessary to be admin

No, I am in a super group and I can not add my friends, or contacts. I just can't. I don't have permission to do so. Also I'm using Telegram Desktop 1.1.7, which is the latest stable, and I just can't add users to a super group I don't have permission to!

Now, if you see the button to add users, then that's a different story, and you should have permission to use some request to add them.

atabaki commented 7 years ago

Try This link as example https://telegram.me/joinchat/CuMcGD2yXIohSMyJ1RbYHw

Lonami commented 7 years ago

Well, you have a link, then only the person you want to add can use the link to join. You can't just force them to join unless you have permission, as I said.

atabaki commented 7 years ago

try bot instead of user and add bot u can add easily in tdesktop but in api you can not

atabaki commented 7 years ago

Well, you have a link, then only the person you want to add can use the link to join

No need to be join from link. Check it

Lonami commented 7 years ago

try bot instead of user and add bot u can add easily in tdesktop

How can I add a bot to a channel if I only have the link? I either need to be the owner or, not sure if bots can decide to join the channel…

Lonami commented 7 years ago

No need to be join from link. Check it

I checked the link from Telegram Desktop, and yes, a super group shows. But how would that let me add someone else? I don't understand how you can add someone else with just a link and from Telegram Desktop. Not even if it's a bot, you'd need to tell the bot the link, right?

atabaki commented 7 years ago

you first join to group and then by click on group info you can see add members button then search bot name and add it

Lonami commented 7 years ago

I made a super group. I joined by a link. And yes I can add other users. But I can't remove them which is a bit of a non-sense… Anyway I'm not sure what request Telegram Desktop uses, but it has to exist, and it will be on the online documentation.

Lonami commented 7 years ago

Wait you mentioned you used InviteToChannelRequest and got an INVALID_CHAT_ID. Are you using what I mentioned above?

Edit: Something like:

from telethon.tl.functions.channels import InviteToChannelRequest
from telethon.helpers import get_input_peer

client.invoke(InviteToChannelRequest(
    get_input_peer(channel),
    [get_input_peer(user)]
))
atabaki commented 7 years ago

No when we used "InviteToChannelRequest" admin permission error showed not invalid_chat_Id

atabaki commented 7 years ago

Hi Lonami Some super groups allow to add without their permission and some not It seems that Chat Member must be added by addchatuserrequest and (supergroup)Channel member must be added by InviteToChannelRequest Thanks Again

Lonami commented 7 years ago

Okay thanks for telling us how you solved it and glad you clarified it how it works for yourself too.

Frogbr commented 6 years ago

I'd like to know how to add members in supergroup please could you explain me in a supergroup on the telegram, using python.

daha7 commented 10 months ago

how can I add a bot to the channel? I am using node js. Tried using the channels.inviteToChannel method, but I get a USER_BOT error that says the bot can only be the channel administrator. This is what I need to implement. Any ideas how to do it? Thanks