How to limit who can send messages to my Telegram bot

I have a Telegram bot that receives photos and displays them right away in a slideshow. Since the images appear instantly without any review, I want to control who can interact with my bot. I need to set up some kind of user filtering so only specific people or group members can send content to it. What’s the best way to implement this restriction? I’m worried about random users sending inappropriate content that would show up in the presentation.

Another approach you might consider is using Telegram groups with proper admin controls. Create a private group, add your bot to it, and only invite trusted users who can send photos. This way you leverage Telegram’s built-in permission system rather than coding everything yourself. The bot can monitor the group for new photos and add them to your slideshow automatically. I’ve used this method for a similar project and it worked really well - much easier than maintaining user lists in code and you get better control over who joins.

You can implement authorization middleware that checks incoming messages against predefined criteria before processing them. I handled a similar situation by creating a decorator function that validates users based on username patterns or membership in specific channels. The bot can check if a user belongs to a particular channel using the getChatMember API call - this works well if you already have a community or organization channel. Another option is requiring users to provide an access code when they first interact with the bot, which you can distribute privately to trusted individuals. This method scales better than hardcoded ID lists since you don’t need to update code every time someone new needs access.

the simple way is to filter user IDs in your bot’s code. make a whitelist of allowed IDs and ignore others. just have the users send /start so you can log their IDs.