Created
May 10, 2017 12:12
-
-
Save Kylmakalle/3b09f6b58ddb03ef9e98c116fc050f3a to your computer and use it in GitHub Desktop.
Get info about Telagram chat participants using https://github.com/LonamiWebs/Telethon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from telethon import TelegramClient | |
from telethon.tl.functions.channels import GetParticipantsRequest | |
from telethon.tl.types import ChannelParticipantsRecent | |
from telethon.utils import get_input_peer | |
api_id = 123456 # Use your own values here. https://my.telegram.org | |
api_hash = '0123456789abcdef0123456789abcdef' | |
phone_number = '+34600000000' | |
client = TelegramClient('%sessionname%', api_id, api_hash) # feel free to edit %sessionname% as you want | |
client.connect() # logining and connecting to Telegram servers | |
if not client.is_user_authorized(): # authorization (if there is no .session file created before) | |
client.send_code_request(phone_number) | |
client.sign_in(phone_number, input('Enter the code: ')) | |
# Using built-in methods | |
dialogs, entities = client.get_dialogs(count=10) # getting info about first 10 chats | |
result = client.invoke( | |
GetParticipantsRequest(get_input_peer(entities[6]), # Getting 7th chat participants | |
filter=ChannelParticipantsRecent(), | |
# List of filters https://lonamiwebs.github.io/Telethon/types/channel_participants_filter.html | |
offset=0, # getting info from 0th user | |
limit=5) # limiting number of users in a request | |
) | |
info = result | |
print(info.users[3]) # prints info about 4th %filtered% Chat participant | |
# Example: (user (ID: 0xd10d979a) = (is_self=None, contact=None, mutual_contact=None, deleted=None, bot=None, bot_chat_history=None, bot_nochats=None, verified=None, restricted=None, min=None, bot_inline_geo=None, id=100761605, access_hash=-2961737078536444064, first_name=Pavel, last_name=Davydov, username=paveldavydov, phone=None, photo=(userProfilePhoto (ID: 0xd559d8c8) = (photo_id=432767798623709098, photo_small=(fileLocation (ID: 0x53d69076) = (dc_id=2, volume_id=710237640, local_id=19652, secret=******************(maybe there is really something secret, dunno))), photo_big=(fileLocation (ID: 0x53d69076) = (dc_id=2, volume_id=710237640, local_id=19654, secret=*******************)))), status=(userStatusOffline (ID: 0x8c703f) = (was_online=1494417103)), bot_info_version=None, restriction_reason=None, bot_inline_placeholder=None)) | |
# Here is an id, access_hash, name and another info (that you might don't need) |
client(GetParticipantsRequest(peer, ChannelParticipantsRecent(), offset=offset, limit=200, hash=0))
I found that that hash argument should equal zero. Don't ask why - IDK ¯\_(ツ)_/¯
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
code is based on outdated Telethon API -.-