发送到 Telegram Bot 的传入消息是否包含该机器人的任何 ID?
Does incoming message sent to Telegram Bot contain any id of that bot?
当我从电报机器人获得更新并将用户消息写入机器人时,我希望看到一些带有用户 ID 的机器人 ID,但是,我看到了这样的更新:
Update{update_id=515450315,
message=Message{message_id=117,
from=User{id=1234567890, first_name='Name', last_name='Surname', username='null'},
date=1470510167,
chat=Chat{id=1234567890, type=Private, first_name='Name', last_name='Surname', username='null', title='null'},
...
如文档所述,User
是消息的发送者(用户或机器人)。但在这种情况下,用户 ID 是实际用户 ID(不是机器人 ID),聊天 ID 由于某种原因等于用户 ID。那么有人知道如何在更新对象期间获取机器人 ID 吗?
这是一个 JSON
对象,当用户向机器人发送消息时,机器人会收到电报。(据我从你的问题中了解到)
这完全正常。你问为什么?
有两个原因:
1- When USER
send something to bot, at first Telegram
servers grab
it and resend it to bot
app on its own server. So this JSON
object
contains sender (user) id logically.(why?) It is user_id
and NOT
bot_id
because bot
receives message and should know who sent
it.This number(user_id) tell bot
about sender.
2- Why chat_id
and user_id
(sender) are equal? Because when user is
in private messaging with bot ,he/she sends to bot in private chat, so
these two numbers are equal but when user sends something in a group
that your bot is its member also, there are two different numbers:
chat_id
that represents group_id
here and user_id
(sender_id)
that tells to your bot who sent the message.
我们可以使用这两个数字的相等性检查来找出用户是在与机器人进行私人聊天还是在群组中发送。
而且我不知道任何从 Telegram
发送到 Bot
的 JSON 对象包含关于 bot_id
的任何字段。除了一些特定的方法,如 getMe
方法。(它 returns 关于你的机器人的基本信息)
当我从电报机器人获得更新并将用户消息写入机器人时,我希望看到一些带有用户 ID 的机器人 ID,但是,我看到了这样的更新:
Update{update_id=515450315,
message=Message{message_id=117,
from=User{id=1234567890, first_name='Name', last_name='Surname', username='null'},
date=1470510167,
chat=Chat{id=1234567890, type=Private, first_name='Name', last_name='Surname', username='null', title='null'},
...
如文档所述,User
是消息的发送者(用户或机器人)。但在这种情况下,用户 ID 是实际用户 ID(不是机器人 ID),聊天 ID 由于某种原因等于用户 ID。那么有人知道如何在更新对象期间获取机器人 ID 吗?
这是一个 JSON
对象,当用户向机器人发送消息时,机器人会收到电报。(据我从你的问题中了解到)
这完全正常。你问为什么? 有两个原因:
1- When
USER
send something to bot, at firstTelegram
servers grab it and resend it tobot
app on its own server. So thisJSON
object contains sender (user) id logically.(why?) It isuser_id
and NOTbot_id
becausebot
receives message and should know who sent it.This number(user_id) tellbot
about sender.2- Why
chat_id
anduser_id
(sender) are equal? Because when user is in private messaging with bot ,he/she sends to bot in private chat, so these two numbers are equal but when user sends something in a group that your bot is its member also, there are two different numbers:chat_id
that representsgroup_id
here anduser_id
(sender_id) that tells to your bot who sent the message.
我们可以使用这两个数字的相等性检查来找出用户是在与机器人进行私人聊天还是在群组中发送。
而且我不知道任何从 Telegram
发送到 Bot
的 JSON 对象包含关于 bot_id
的任何字段。除了一些特定的方法,如 getMe
方法。(它 returns 关于你的机器人的基本信息)