How to obtain Telegram chat_id for a specific user?

前端 未结 7 1494
自闭症患者
自闭症患者 2020-12-01 02:36

How to obtain user chat_id in Telegram bot API? The documentation says:

Integer | Unique identifier for the message recipient — User or G

7条回答
  •  温柔的废话
    2020-12-01 03:01

    First, post a message in a chat where your bot is included (channel, group mentioning the bot, or one-to-one chat). Then, just run:

    curl https://api.telegram.org/bot/getUpdates | jq
    

    Feel free to remove the | jq part if your dont have jq installed, it's only useful for pretty printing. You should get something like this:

    You can see the chat ID in the returned json object, together with the chat name and associated message.

提交回复
热议问题