Telegram bot API 是每个联系 bot 的用户的唯一 chat_id 吗?
Telegram bot API is the chat_id unique for each user contacting the bot?
我们正在使用 python API 电报机器人,需要能够识别用户。
每个连接机器人的用户的 chat_id 是唯一的吗?
我们可以相信 chat_id 是一致的吗?例如 same chat_id 会告诉我们这是同一个用户,每个与机器人连接的用户都会有一个 chat_id 在会话之间是一致的?
谢谢
Is the chat_id unique for each user connecting the bot?
是
chat_id
对于连接到您的 bot 的每个用户始终是唯一的。
如果同一用户向不同的机器人发送消息,它们将始终 'identify' 自己与他们独特的 id
.
请记住,getUpdates
显示用户 ID,以及聊天中的 ID。
{
"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
不会改变,即使组被转换为超级组
基于评论; private/group 聊天示例的小概览
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
}
}
}
我们正在使用 python API 电报机器人,需要能够识别用户。
每个连接机器人的用户的 chat_id 是唯一的吗?
我们可以相信 chat_id 是一致的吗?例如 same chat_id 会告诉我们这是同一个用户,每个与机器人连接的用户都会有一个 chat_id 在会话之间是一致的?
谢谢
Is the chat_id unique for each user connecting the bot?
是
chat_id
对于连接到您的 bot 的每个用户始终是唯一的。
如果同一用户向不同的机器人发送消息,它们将始终 'identify' 自己与他们独特的 id
.
请记住,getUpdates
显示用户 ID,以及聊天中的 ID。
{
"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
不会改变,即使组被转换为超级组
基于评论; private/group 聊天示例的小概览
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
}
}
}