Telegram Bot: Get Recent Group Message Senders UserIDs
In the previous post, we built a bot for first-message human verification.

This brings up the following requirement:
I already have many members in my group.
From their daily messages, you can tell none of them are bots.
But once I add this first-message verification bot to the group, every member would have to go through verification before their first message after this point in time. That would cause unnecessary trouble for these existing members.
Of course, this project also provides a verification list file called valid.yaml where you can manually add the userids of your group members.
Among these, only the userid is valid; the other information is meant to assist humans in managing this file and is not involved in the program's logic.
So, you can manually add the userids of your group members. Like this:
So, the requirement this article aims to address becomes:
Query the recent messages of a group and count the userids of message senders
Still developed with GPT
Query the most recent 1000 messages in a Telegram group.
Count the userids of the Telegram accounts that sent the messages
This group could be a public group or a private group
This time we have to use the Telethon library, which requires api_id and api_hash. You need to apply for them at https://my.telegram.org/apps
Uploaded to Github
Running result
A total of 85 users were counted
391932510
5612162712
5043772938
7287227103
6989120610
...omitted
From this result to valid.yaml, you still need to do a little bit of work yourself.
To match the yaml file format, you need to add a colon after each id:

I considered the meaning of this project as a standalone project, so I did not include the colon in the output.
If you think it is necessary, you can modify the program yourself. Adding this colon to the output is an easy thing to do.
Postscript
If you have a private group (for example, with ID 1231231231), when using this project, modify the ID in the file to -1001231231231
But it reports an error when executed.Then, you can choose one of the following options:
1. Use your group ID directly, 1231231231
2. Set your private group to public, save it. Then set it back to private.You will find that the group ID has changed, for example, to 4564564564
Then use -1004564564564
=========




