Skip to content Skip to sidebar Skip to footer

Telegram Bot Api Is The Chat_id Unique For Each User Contacting The Bot?

We are using python API for telegram bots and need to be able to identify the user. Is the chat_id unique for each user connecting the bot? Can we trust the chat_id to be consiste

Solution 1:

Is the chat_id unique for each user connecting the bot?

Yes

chat_id will always be unique for each user connecting to your bot. If the same user sends messages to different bots, they will always 'identify' themselves with their unique id.

Keep in mind that getUpdates shows the users id, and the id from the chat.

{
    "ok": true,
    "result": [
        {
            "update_id": 1234567,
            "message": {
                "message_id": 751,
                "from": {
                    "id": 12122121,                     <-- user.id"is_bot": false,
                    "first_name": "Me",
                    "last_name": "&",
                    "username": "&&&&",
                    "language_code": "en"
                },
                "chat": {
                    "id": -104235244275,                <-- chat_id"title": "Some group",
                    "type": "supergroup"
                },
                "date": 1579999999,
                "text": "Hi!"
            }
        }
    ]
}

According to this post, that chat.id will not change, even if the group is converted to a supergroup

Based on comment; small overvieuw of private/group chat example

user_1 ---> bot_a     inprivate chat
{
    "message": {
        "from": {
            "id": 12345678          <-- id from user_1
        },
        "chat": {
            "id": 12345678,         <-- send fromprivate chat, so chat isequals to user_id
        }
    }
}

user_2 ---> bot_a     inprivate chat
{
    "message": {
        "from": {
            "id": 9876543          <-- id from user_2
        },
        "chat": {
            "id": 9876543,         <-- send fromprivate chat, so chat isequals to user_id
        }
    }
}

user_1 ---> bot_a     ingroup chat
{
    "message": {
        "from": {
            "id": 12345678         <-- id from user_1
        },
        "chat": {
            "id": 5646464,         <-- send fromgroup chat, so id isfrom groupchat
        }
    }
}

user_2 ---> bot_a     ingroup chat
{
    "message": {
        "from": {
            "id": 9876543          <-- id from user_2
        },
        "chat": {
            "id": 5646464,         <-- send fromgroup chat, so id isfrom groupchat
        }
    }
}

Post a Comment for "Telegram Bot Api Is The Chat_id Unique For Each User Contacting The Bot?"