How to obtain user chat_id
in Telegram bot API?
The documentation says:
Integer | Unique identifier for the message recipient — User or GroupChat id
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.