Add information to join a private chat or channel

Lonami 2017-06-10 10:04:30 +02:00
parent 778a01c9e1
commit 4a79c967dc
2 changed files with 29 additions and 15 deletions

@ -0,0 +1,29 @@
Note that [`Chat`](https://lonamiwebs.github.io/Telethon/constructors/chat.html)s are normal groups, and [`Channel`](https://lonamiwebs.github.io/Telethon/constructors/channel.html)s are a special form of [`Chat`](https://lonamiwebs.github.io/Telethon/types/chat.html)s, which can also be super-groups if their `megagroup` member is `True`.
## Joining a public channel
Once you have the [entity](Retrieving-an-entity) of the channel you want to join to, you can make use of the [`JoinChannelRequest`](https://lonamiwebs.github.io/Telethon/methods/channels/join_channel.html) to join such channel:
```python
from telethon.tl.functions.channels import JoinChannelRequest
from telethon.helpers import get_input_peer
input_channel = get_input_peer(channel)
client.invoke(JoinChannelRequest(input_channel))
# In the same way, you can also leave such channel
from telethon.tl.functions.channels import LeaveChannelRequest
client.invoke(LeaveChannelRequest(input_channel))
```
For more on channels, check the [`channels` namespace](https://lonamiwebs.github.io/Telethon/methods/channels/index.html).
## Joining a private chat or channel
If all you have is a link like this one: `https://t.me/joinchat/AAAAAFFszQPyPEZ7wgxLtd`, you already have enough information to join! The part after the `https://t.me/joinchat/`, this is, `AAAAAFFszQPyPEZ7wgxLtd` on this example, is the `hash` of the chat or channel. Now you can use [`ImportChatInviteRequest`](https://lonamiwebs.github.io/Telethon/methods/messages/import_chat_invite.html) as follows:
```python
from telethon.tl.functions.messages import ImportChatInviteRequest
updates = client.invoke(ImportChatInviteRequest('AAAAAEHbEkejzxUjAUCfYg'))
```

@ -1,15 +0,0 @@
Once you have the [entity](Retrieving-an-entity) of the channel you want to join to, you can make use of the [`JoinChannelRequest`](https://lonamiwebs.github.io/Telethon/methods/channels/join_channel.html) to join such channel:
```python
from telethon.tl.functions.channels import JoinChannelRequest
from telethon.helpers import get_input_peer
input_channel = get_input_peer(channel)
client.invoke(JoinChannelRequest(input_channel))
# In the same way, you can also leave such channel
from telethon.tl.functions.channels import LeaveChannelRequest
client.invoke(LeaveChannelRequest(input_channel))
```
For more on channels, check the [`channels` namespace](https://lonamiwebs.github.io/Telethon/methods/channels/index.html).