Telegram 机器人获取聊天信息 python
Telegram bot get chat informations python
关于电报机器人,我如何通过 url 像 getupdates (https://api.telegram.org/bot/getupdates
) 从特殊聊天(不是所有聊天,通过聊天 ID)获取 json 信息。
因为我从 getupdates 得到的信息很少,所以我想知道每个组和聊天中的一些信息,例如成员 ID 和消息 ID 等。
无法通过聊天 ID 专门过滤更新(API 不允许 ),如果不是您自己的代码,您仍然可以按类型过滤更新。
下面是一个关于如何仅过滤回调查询和消息的示例:
api.telegram.org/bot{token}/getUpdates?allowed_updates=["callback_query","message"]
注意:如 BotApi Documentation 中所写,即使您在 getUpdates
上传递 allowed_updates
参数,也只有新收到的更新会按照以下过滤器进行过滤:
Please note that this parameter doesn't affect updates created before
the call to the getUpdates, so unwanted updates may be received for a
short period of time.
此处列出了所有可能的更新类型:core.telegram.org/bots/api#update
知道聊天的ID,可以使用这些方法:
getChat - 获取有关聊天的最新信息。
- returns Chat 对象成功
getChatAdministrators - 获取聊天中的管理员列表。
- returns Array of ChatMember 成功。
getChatMembersCount - 获取聊天中的成员数量。
- returns
Int
成功
getChatMember - 获取有关聊天成员的信息。
- returns ChatMember 成功。
所有这些方法都需要chat_id
参数,可以是Integer或String类型。您可以指定聊天或频道用户名,例如 @channelusername
示例请求:
https://api.telegram.org/bot<API_TOKEN>/getChat?chat_id=<CHAT_ID>
关于电报机器人,我如何通过 url 像 getupdates (https://api.telegram.org/bot/getupdates
) 从特殊聊天(不是所有聊天,通过聊天 ID)获取 json 信息。
因为我从 getupdates 得到的信息很少,所以我想知道每个组和聊天中的一些信息,例如成员 ID 和消息 ID 等。
无法通过聊天 ID 专门过滤更新(API 不允许 ),如果不是您自己的代码,您仍然可以按类型过滤更新。
下面是一个关于如何仅过滤回调查询和消息的示例:
api.telegram.org/bot{token}/getUpdates?allowed_updates=["callback_query","message"]
注意:如 BotApi Documentation 中所写,即使您在 getUpdates
上传递 allowed_updates
参数,也只有新收到的更新会按照以下过滤器进行过滤:
Please note that this parameter doesn't affect updates created before the call to the getUpdates, so unwanted updates may be received for a short period of time.
此处列出了所有可能的更新类型:core.telegram.org/bots/api#update
知道聊天的ID,可以使用这些方法:
getChat - 获取有关聊天的最新信息。
- returns Chat 对象成功
getChatAdministrators - 获取聊天中的管理员列表。
- returns Array of ChatMember 成功。
getChatMembersCount - 获取聊天中的成员数量。
- returns
Int
成功
- returns
getChatMember - 获取有关聊天成员的信息。
- returns ChatMember 成功。
所有这些方法都需要chat_id
参数,可以是Integer或String类型。您可以指定聊天或频道用户名,例如 @channelusername
示例请求:
https://api.telegram.org/bot<API_TOKEN>/getChat?chat_id=<CHAT_ID>