Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 222
ATheCoder Avatar asked Jan 15 '17 18:01

ATheCoder


People also ask

Can Telegram bot send SMS?

Telegram Bot is a WordPress plugin that allows you to send automatic messages, emails and SMS based on Telegram conversations and much more. You can use the Telegram Bot WordPress plugin to automate business workflows involving the messenger app.

Can a Telegram bot talk to another bot?

Bots talking to each other could potentially get stuck in unwelcome loops. To avoid this, we decided that bots will not be able to see messages from other bots regardless of mode.


2 Answers

  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.
like image 112
Andrey Radomanov Avatar answered Sep 19 '22 11:09

Andrey Radomanov


It is only possible to send messages to users whom have already used /start on your bot. When they start your bot, you can find update.message.from.user_id straight from the message they sent /start with, and you can find update.message.from.username using the same method. In order to send a message to "@Username", you will need them to start your bot, and then store the username with the user_id. Then, you can input the username to find the correct user_id each time you want to send them a message.

like image 23
Resin Drake Avatar answered Sep 20 '22 11:09

Resin Drake