Anybody give a starter on how may I get information about users from my telegram bot. Imagine my bot in an admin user in my channel and I want to get my channel user list or
As others already mentioned, you can`t list channel users via Bot API.
But you can use MTProto API to login as a plain user and have programmatic access to everything you can see in desktop or mobile application.
To use MTProto, you need to login to https://my.telegram.org/ with your existing Telegram account and get credentials: api_id
and api_hash
.
Here is a working example of how to use Telethon python library to get list of Telegram channel/group users.
from telethon import TelegramClient, sync
api_id = 'FILL REAL VALUES HERE'
api_hash = 'FILL REAL VALUES HERE'
client = TelegramClient('xxx', api_id, api_hash).start()
# get all the channels that I can access
channels = {d.entity.username: d.entity
for d in client.get_dialogs()
if d.is_channel}
# choose the one that I want list users from
channel = channels[channel_name]
# get all the users and print them
for u in client.get_participants(channel):
print(u.id, u.first_name, u.last_name, u.username)
It is easy to search channels/users by name/phone/URL with client.get_entity().