Telegram Bot: Can I retrieve a user's ID from their username?

I’m exploring whether it’s feasible to have a Telegram bot pull a user’s unique identification number simply by providing their username. My plan involves adding a feature that would return the user ID based on the given username. Does the Telegram API support retrieving user IDs in this manner?

hey, the telegram api dont allow getting a user id directly from their username. you need some prior interraction for the bot to get the id. so no direct way available

Based on my own trials while developing Telegram bots, the limitations of the API regarding user privacy are quite apparent. There isn’t a function that lets a bot directly convert a username into a user ID without any previous user interaction. In my projects, I discovered that you must first have a trigger from the user, such as initiating a chat, for their ID to be captured. This restriction enforces a stricter privacy model, preventing rough data scraping. It’s important to incorporate these limitations into your design from the start.

In my experience, the Telegram API does not permit retrieving a user’s ID solely based on the username. Although I have explored several methods, directly mapping a username to a unique identifier isn’t supported unless the user interacts with the bot. This limitation emphasizes Telegram’s approach to user privacy. The API requires some form of prior communication or explicit inclusion of the user with the bot to expose such sensitive information. Understanding these restrictions is crucial when designing features that need to access user-related details.