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 to be noticed when a new user joins. How can I do that.
Telegram’s documents are so unorganized.
So far I have looked at these:
- https://core.telegram.org/bots
- https://core.telegram.org/bots/api
- https://core.telegram.org/bots/samples
- https://core.telegram.org/bots/faq
But none of these really helps.
6
Answers
Telegram Bot doesn’t keep anything about your users. You should save by yourself all users which communicate with your bot. For example, store their IDs in database.
In case of Channel – you can get this information from Channel’s members list.
If you need to be notified – your bot should store users somewhere and check if user is a new one.
Bot can’t get access to channel users list via api.
One have two possibilities to achieve this:
There is not any api for Telegram bot to access channel or group users.
If access to group users is important for you, I suggest you to use Telegram-CLI. You can access to all Telegran user account’s API so you have access to all of your group’s users data.
https://github.com/vysheng/tg
In order to get user list, you need to use telegram API.
Telegram API is fairly complicated. There are some clients which can get the job done much faster.
For python, there is Telethon, and the method to get channel users is:
get_full_channel
.In order to get user list, you need to use telegram API.
Telegram API is fairly complicated. There are some clients which can get the job done much faster.
For python, there is Telethon, and the code to get channel users is:
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
andapi_hash
.Here is a working example of how to use Telethon python library to get list of Telegram channel/group users.
It is easy to search channels/users by name/phone/URL with client.get_entity().