close

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

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How can I send a message to someone with my telegram bot using their Username in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

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

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

    You can't send message to users using their username that is in form of @username, you can just send messages to channel usernames which your bot is administrator of it.

  2. send a message to someone with my telegram bot using their Username

Method 1

  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.

Method 2

You can’t send message to users using their username that is in form of @username, you can just send messages to channel usernames which your bot is administrator of it. Telegram bot api uses chat_id identifier for sending messages. If you want to achieve chat_id of users, you can use telegram-cli, but it’s not easy at all because that project is discontinued and you should debug it yourself. in your case you should do following command:

> resolve_username vahid_mas

and the output will be something like this:

{
  "user": {
    "username": "Vahid_Mas",
    "id": "$010000006459670b02c0c7fd66d44708",
    "last_name": "",
    "peer_type": "user",
    "print_name": "Vahid",
    "flags": 720897,
    "peer_id": 191322468,
    "first_name": "Vahid",
    "phone": "xxxxxxx"
  },
  "online": false,
  "event": "online-status",
  "state": -1,
  "when": "2017-01-22 17:43:16"
}

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read