8

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?

Aven Desta
  • 2,114
  • 12
  • 27
Abdelilah El Aissaoui
  • 4,204
  • 2
  • 27
  • 47

4 Answers4

5

I believe what you mean by nickname is the username and userid is the unique id 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.

Resolving of usernames not only with channels and groups but also with normal users and bots

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.

Mohamed Sohail
  • 1,659
  • 12
  • 23
5

The solution by Mohammod Sohail is partially wrong.

There are ways to get a user_id from username, 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 from username purely with bot API (doen't always work).

Lets say you are chatting with your friend X and you want to know his user_id. To get the user_id, forward one of your conversations to your bot. The bot will get the message author's first name, username, user_id, timestamp, and so on in JSON format. Now you can extract the user_id from that. Note that this also works even if the user does not have a username, 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

GET ID BOT

Aven Desta
  • 2,114
  • 12
  • 27
3

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.

Danogentili
  • 664
  • 7
  • 13
1

No. It's not possible right now.

ihoru
  • 1,905
  • 1
  • 16
  • 15