As the title says, is it possible to get userid using username?
I mean, I would like to add a feature to my bot that tells you the user id from an other user using his username.
Does Telegram API give an option to do this?
As the title says, is it possible to get userid using username?
I mean, I would like to add a feature to my bot that tells you the user id from an other user using his username.
Does Telegram API give an option to do this?
4
Answers
No. It’s not possible right now.
I believe what you mean by nickname is the
username
and userid is the uniqueid
as described in the API documentation.It is still possible to do a reverse lookup using a bot.This is possible with a boosted version of the Official Telegram API, known as PWRTelegram API
I quote from the documentation.
Update:
Here is a library I made for this purpose:
Update 2:
I no longer maintain the above library, you can however still resolve usernames with a td-cli binary.
You can use the pwrtelegram bot API to resolve usernames of bots and normal users.
It will automagically resolve the usernames you provide in the chat_id parameter using a built in mtproto client.
You can use usernames of bots and normal users in every method that requires the chat_id parameter, but to get info about a user/bot you can use the getChat method.
The solution by Mohammod Sohail is partially wrong.
There are ways to get a
user_id
fromusername
, but online tools mentioned above use more than the bot API. They have a telegram client running on their server.That said there is a trick to get a
user_id
fromusername
purely with bot API (doen’t always work).Lets say you are chatting with your friend
X
and you want to know hisuser_id
. To get theuser_id
, forward one of your conversations to your bot. The bot will get the message author’sfirst name
,username
,user_id
,timestamp
, and so on in JSON format. Now you can extract theuser_id
from that. Note that this also works even if the user does not have ausername
, or if its a channel or another bot.Here is an bot implementation of the above:
I’ve forwarded one of my friend’s message to the bot @get_id_bot
Then the bot returns the username and id of my friend’s account