0

Is the chat_id Telegram sends with inbound messages a stable identifier for the sender, or can chat_id vary for the same user between chats?

When my bot receives a message, the payload is in the format:

{message:
    {from: {id: 123456789, ...},
     chat: {id: 123456789, ...}}}

The two IDs match. Is message.from.id stable?

The documentation only states, "Unique identifier for the target chat or username of the target channel (in the format @channelusername)"

Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
  • If I understand your question, you should not use `chat_id` to 'identify' users. You should use there custom user_id. The chat_id could change after updating/downgrading the group. – 0stone0 May 11 '20 at 11:24
  • 1
    `chat_id` has nothing to do with users. In fact, the documentation you quoted defines it precisely as an unique identifier for a *chat* or *channel*, not an user. – Marco Bonelli May 11 '20 at 11:54
  • @0stone0 clarified my question – Petrus Theron May 11 '20 at 14:20
  • 1
    `from_id` is the ID of the user, `chat_id` is the id of the chat the message was send from. They match if you talk to the bot in a private channel, the'll be different if you talk to the same bot in a group chat. ([Not quite sure, but maybe this could help](https://stackoverflow.com/questions/59748008/telegram-bot-api-is-the-chat-id-unique-for-each-user-contacting-the-bot/59750179#59750179)) – 0stone0 May 11 '20 at 14:22
  • Thanks. So according to [this answer](https://stackoverflow.com/a/59750179/198927) `from.id` should be stable for a given user, even if they message one of my other bots? – Petrus Theron May 11 '20 at 14:25
  • Yes, `from_id` is the ID of the Telegram User, it does not matter to who the person is talking. So `from_id` could be used to identify a user, where `chat_id` shows where the user sends that message. (The'll match if it's a private channel, since the chat_id of a private channel is the id of the telegram user) – 0stone0 May 11 '20 at 14:28

0 Answers0