Is it possible to retrieve a user's phone number using their Telegram ID through the Bot API?

I’m working on a project using the Telegram Bot API to send messages to users. I’ve set up a bot and can receive info when users message it. But here’s the thing: I need to get the users’ phone numbers to match them in our system.

Is there a way to get a user’s phone number just from their Telegram ID? It would make things way easier for users if they didn’t have to type in their number manually.

Right now, users have to send commands like this:

check_balance 1234567890

But I’m hoping to simplify it to just:

check_balance

Has anyone figured out how to do this? Or is there another way to identify users without asking for their numbers directly? Any tips would be super helpful!

nah, u cant get phone numbers straight from telegram IDs. privacy stuff, ya know? but hey, theres other ways to make it work. maybe try askin users to share their contact once, then save that info for later. or use a login widget thing. just gotta get creative n respect peoples privacy at the same time

I’ve actually tackled a similar challenge in one of my projects. While it’s true you can’t directly get phone numbers from Telegram IDs, I found a workaround that might help.

What worked for me was implementing a one-time verification process. When a user first interacts with the bot, I’d ask them to send their phone number using Telegram’s ‘Share Contact’ feature. This only needs to be done once, and then I’d store the Telegram ID and phone number pair in my database.

From that point on, users could just use ‘check_balance’ as you wanted. The bot would look up their Telegram ID in the database to find the associated phone number.

It’s not perfect, but it struck a good balance between user convenience and respecting Telegram’s privacy policies. Just make sure to be transparent about data usage and get user consent.

Unfortunately, retrieving a user’s phone number directly from their Telegram ID through the Bot API isn’t possible due to privacy concerns. Telegram intentionally restricts access to sensitive user data like phone numbers.

However, there are alternative approaches you could consider. One option is to implement a login system where users authorize your bot through Telegram’s Login Widget. This can provide you with some user data, though not phone numbers.

Another method is to use a custom keyboard to prompt users to share their contact info voluntarily. This requires user consent but can be more seamless than manual number entry.

Ultimately, respecting user privacy while providing a smooth experience often requires creative solutions that work within Telegram’s guidelines.