电报漫游器API对于每个与漫游器联系的用户而言,chat_id是唯一的吗? [英] Telegram bot API is the chat_id unique for each user contacting the bot?
问题描述
我们正在将python API用于电报机器人,并且需要能够识别用户.
We are using python API for telegram bots and need to be able to identify the user.
每个连接机器人的用户的chat_id是否唯一?
Is the chat_id unique for each user connecting the bot?
我们可以相信chat_id是一致的吗?例如,相同的chat_id会告诉我们这是同一用户,并且与漫游器连接的每个用户都将拥有一个在会话之间保持一致的chat_id?
Can we trust the chat_id to be consistent? e.g same chat_id will tell us that this is the same user, and each user connecting with the bot will have one chat_id that is consistent between sessions?
谢谢
推荐答案
每个连接机器人的用户的chat_id是否唯一?
Is the chat_id unique for each user connecting the bot?
是
chat_id
始终是唯一的.
如果同一用户向不同的漫游器发送消息,他们将始终使用其唯一的id
来标识"自己.
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
.
请记住,getUpdates
显示用户ID和聊天中的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!"
}
}
]
}
根据这篇文章,即使将组转换为超级组,chat.id
也不会更改
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 in private chat
{
"message": {
"from": {
"id": 12345678 <-- id from user_1
},
"chat": {
"id": 12345678, <-- send from private chat, so chat is equals to user_id
}
}
}
user_2 ---> bot_a in private chat
{
"message": {
"from": {
"id": 9876543 <-- id from user_2
},
"chat": {
"id": 9876543, <-- send from private chat, so chat is equals to user_id
}
}
}
user_1 ---> bot_a in group chat
{
"message": {
"from": {
"id": 12345678 <-- id from user_1
},
"chat": {
"id": 5646464, <-- send from group chat, so id is from groupchat
}
}
}
user_2 ---> bot_a in group chat
{
"message": {
"from": {
"id": 9876543 <-- id from user_2
},
"chat": {
"id": 5646464, <-- send from group chat, so id is from groupchat
}
}
}
这篇关于电报漫游器API对于每个与漫游器联系的用户而言,chat_id是唯一的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!