How to obtain user chat_id
in Telegram bot API? The documentation says:
Integer | Unique identifier for the message recipient — User or GroupChat 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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With