Can I get a phone number by user id via Telegram Bot API?
Solution 1
It's possible with bots 2.0 check out bot api docs.
https://core.telegram.org/bots/2-0-intro#locations-and-numbers https://core.telegram.org/bots/api#keyboardbutton
Solution 2
No, unfortunately Telegram Bot API
doesn't return phone number. You should either use Telegram API methods instead or ask it explicitly from the user. You cannot get "friends" of a user as well.
You will definitely retrieve the following information:
userid
-
first_name
-
content
(whatever it is: text, photo, etc.) -
date
(unixtime) chat_id
If user configured it, you will also get last_name
and username
.
isxaker
Updated on July 05, 2022Comments
-
isxaker almost 2 years
I am using
Telegram Bot API
for sending instant messages to users. I have installed nuget package. This package is recommend by telegram developers.I have created a telegram bot and successfully got access to it by using code. When I send messsage to bot, bot gets some info about sender.
I need the phone numbers of users to identify them in our system and send the information back to them.
My question is Can i get a user phone number by
telegramUserId
?I'm doing it for user convenience. If I could to get a user phone number I should't have to ask for it from the user.
Now my command like this:
debt 9811201243
I want
debt
-
azerafati over 8 yearsbut if we explicitly ask the user for a phone number how could we make sure he doesn't send his own number and not someone else's?
-
Sergey Ivanov over 8 yearsThere is no integrated way to do this. One way to verify though, would be to send a code to this phone number and ask him to provide this code in the chat.
-
Groosha about 8 yearsYou're wrong. phone numbers are still unavailable to bots unless user explicitly sends it to bot using special command.
-
Groosha about 8 yearsWhy
unfortunately
? This prevents spammers from sending their crap to all users (just like WhatsApp) -
Danil Pyatnitsev about 8 yearsyou can check what is it. User can send itself phone number and also user can sand a contact. You need to compare user_id of sender of the message and user_id of contact. If it's the same that is real phone number of the user.
-
Groosha about 8 yearsYes, but
user can
means, that by default phone numbers are unavailable to bots.That's what I was saying. -
Danil Pyatnitsev about 8 yearsOk it's look like permission request in mobile app. If user grand access to number, bot can do, else - dear user, sorry, but bot can not do this things without phone number. You are right.
-
VSB almost 8 years@SergeyIvanov Is it possible to find user name, using userid?
-
Sergey Ivanov almost 8 yearsTo my knowledge, you can get it only if a user interact with your bot via Message content, i.e. you cannot provide user_id and username from Telegram Bot API.
-
cyrus2500 over 7 yearshelp me this link:stackoverflow.com/questions/41519495/…
-
cyrus2500 over 7 yearshelp me this link:stackoverflow.com/questions/41519495/…
-
LA_ about 7 yearsIf I request user's phone with request_contact - can I be sure that this is user's phone? Can not user send manually some other user's phone instead? For ex., by typing it instead of pressing button? Or even by using modified Telegram client?
-
Danil Pyatnitsev about 7 yearsI think, that you can be sure that it's actual user's number (if using official client), but I can mistake If bot ask for userphone and user answer to this request you, you get special type of message. and if user just send contact to bot, you also have a phone, but you can check, that it's forward user instead of actual user. Just try :)