【问题标题】:how do I get the latest messages from Telegram API?如何从 Telegram API 获取最新消息?
【发布时间】:2022-07-14 04:49:10
【问题描述】:

(首先,我想指出这并没有回答我的问题:How to get the latest/new messages from Telegram API

我正在构建一个历史对象来轮询来自频道/聊天的 20 条最新消息:

get_history = GetHistoryRequest(
        peer=input_peer,
        offset_id=0,
        offset_date=None,
        add_offset=0,
        limit=20,
        max_id=0,
        min_id=0,
        hash=0
    )

这里的 API:

https://core.telegram.org/api/offsets

提到 max_date 和 min_date。

我想获得最新消息,我应该使用limit=[number],offset_date=[same_number] 和max_date 作为当前的日期。但是,我无法从 API 文档中获取“max_date”应该如何表示。任何想法如何以及我在获取最新 20 条消息时的假设是否正确?

这也很有用:https://core.telegram.org/method/messages.getHistory

【问题讨论】:

    标签: json telegram


    【解决方案1】:

    有很多解决方案。我用pyrogram 做这个。

    from pyrogram import Client
    
    app = Client(
        "YOUR_BOT",
        api_id='YOUR_API_ID',
        api_hash='YOUR_API_HASH',
    )
    
    async def main():
        async with app:
            async for message in app.get_chat_history(chat_id, limit=20):
                print(message.text)
    
    app.run(main())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-04
      • 1970-01-01
      • 2019-10-11
      • 2017-11-28
      • 2017-12-08
      • 2020-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多