Find out my own user ID for sending a message with Telegram API
Asked Answered
C

5

22

For Telegram, how can I find out my own user id (chat_id) for use with the Telegram API?

I want to send myself a message via the Telegram API, like this:

https://api.telegram.org/bot<BOTID>/sendMessage
Chloroform answered 20/9, 2015 at 20:30 Comment(0)
W
30

Send a message to your bot then retrieve the update with:

https://api.telegram.org/bot<BOTID>/getUpdates

In the json string returned you will find you chat_id/user_id.
In single chat with the bot chat_id is equal to user_id.
Now you can send your message with:

https://api.telegram.org/bot<BOTID>/sendMessage?chat_id="yourchatid"&text="Hello!"
Wallace answered 25/9, 2015 at 8:27 Comment(0)
C
11

You could use Json Dump Bot.

The relevant section of the output will be similar to:

{
  "message": {
    "from": {
      "id": WHAT_YOU_ARE_LOOKING_FOR,
      "is_bot": false,
      "first_name": "Paolo",
      "language_code": "it"
    }
  }
}

or: https://t.me/userinfobot - just forward message to get his id

Chilly answered 5/10, 2018 at 13:53 Comment(0)
U
2

The easier way is to go to the web version of Telegram and go to the chat whose ID you want to know. It'll be in the URL which is in form:

https://web.telegram.org/#/im?p=u<ID>_<something>

For groups this works too, but their IDs are negative, so if URL looks like

https://web.telegram.org/#/im?p=g1234567

then group chat ID is -1234567.

Urey answered 27/2, 2018 at 2:0 Comment(1)
Do you have any idea what is <something>?Hippocrates
H
2

On Android (or rather Lineage) I was able to look up the user_id under "Settings > Accounts > Telegram"

Holter answered 4/2, 2020 at 15:7 Comment(0)
I
0

The placeholder is actually a token, not a key. Surely you already know what that is and can use it?

https://core.telegram.org/bots/api#authorizing-your-bot

Irrupt answered 20/9, 2015 at 21:39 Comment(1)
Sorry, some guy edited my question. I want to know not BOTID, but user_id (chat_id)Chloroform

© 2022 - 2024 — McMap. All rights reserved.