I’m working on a project where I need to find Telegram user information based on phone numbers I already have.
Basically, I have a collection of phone numbers and I want to check if these people are on Telegram. If they are, I need to get their user_id and display_name details.
Can the Telegram Bot API help me do this lookup? I’m using PHP for my project.
yeah, totally get it! telegram’s all about privacy, so no direct lookup by phone numbers. they ve gotta hit your bot first for you to grab their user_id. kinda protects users, y’know?
Nope, Telegram’s Bot API doesn’t let you search for users by phone number. They did this on purpose to protect privacy and stop unauthorized lookups. The only way to get user info is when people actually interact with your bot - like sending messages, joining groups where your bot lives, or starting a chat. Once they do that, you can grab their user_id and display_name from the message data. If you need to link phone numbers to Telegram users, you’ll have to build something where users manually give you their Telegram username or chat with your bot while also entering their phone number in your app.
Unfortunately, you can’t do phone number lookups with the Telegram Bot API. They deliberately block this to prevent spam and protect privacy. I hit the same wall last year building a contact sync feature for a client. The Bot API only gives you user info when people actually message your bot or use commands. Your code looks fine, but you’ll need to flip the whole approach. Instead of searching by phone numbers, set up an opt-in system. Have users send a command to your bot with their phone number, then store that mapping in your own database. That way you can link phone numbers to Telegram user IDs when people actually consent to being contacted.