Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain Telegram chat_id for a specific user?

Tags:

telegram-bot

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

Integer | Unique identifier for the message recipient — User or GroupChat id

like image 473
Ameer Mousavi Avatar asked Jun 26 '15 17:06

Ameer Mousavi


People also ask

How can I get telegram Bot chat ID?

Type “ @RawDataBot ” and select “Telegram Bot Raw” from the drop-down list. Click on the “Start” button in the auto-reply message. The Telegram bot will send a message with your account info. Scroll down and find “Chat.” Your chat ID number is listed below, next to “id.

What is chat ID in Telegram?

Note the number next to "ID." The number next "ID" below "Chat" in Telegram Bot Raw's message is the chat ID for the entire group.


2 Answers

The message updates you receive via getUpdates or your webhook will contain the chat ID for the specific message. It will be contained under the message.chat.id key.

This seems like the only way you are able to retrieve the chat ID. So if you want to write something where the bot initiates the conversation you will probably have to store the chat ID in relation to the user in some sort of key->value store like MemCache or Redis.

I believe their documentation suggests something similar here, https://core.telegram.org/bots#deep-linking-example. You can use deep-linking to initiate a conversation without requiring the user to type a message first.

like image 109
Chris Brand Avatar answered Sep 21 '22 23:09

Chris Brand


I created a bot to get User or GroupChat id, just send the /my_id to telegram bot @get_id_bot.

It does not only work for user chat ID, but also for group chat ID.

To get group chat ID, first you have to add the bot to the group, then send /my_id in the group.

Here's the link to the bot.

like image 24
fredy kardian Avatar answered Sep 24 '22 23:09

fredy kardian