How can I send a message to someone with my telegram bot using their Username

ATheCoder picture ATheCoder · Jan 15, 2017 · Viewed 68.8k times · Source

I am using the telepot python library, I know that you can send a message when you have someone's UserID(Which is a number). I wanna know if it is possible to send a message to someone without having their UserID but only with their username(The one which starts with '@'), Also if there is a way to convert a username to a UserID.

Answer

Andrey Radomanov picture Andrey Radomanov · Jun 7, 2018
  1. Post one message from User to the Bot.
  2. Open https://api.telegram.org/bot<Bot_token>/getUpdates page.
  3. Find this message and navigate to the result->message->chat->id key.
  4. Use this ID as the [chat_id] parameter to send personal messages to the User.