V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yaocf
V2EX  ›  Telegram

通过 pyrogram 回复 对方机器人发送的 InlineKeyboardMarkup 消息

  •  
  •   yaocf · 333 天前 · 703 次点击
    这是一个创建于 333 天前的主题,其中的信息可能已经有所发展或是发生改变。

    通过pyrogramget_history,读取到对方机器人发送的如下message,有没有方法可以通过pyrogramapi,模拟点击reply_markup中的签到(checkin)按钮?

    以下的四个好像都不对,尤其是那个 query_id ,这个是发送方随机生成的吗(用来标识便于把结果和请求对应起来)?

    await app.send_inline_bot_result(_id, message.chat.id, "checkin", reply_to_message_id=message.id, )
    await message.reply_inline_bot_result(message.id, "checkin")
    await message.edit_reply_markup(message.reply_markup.inline_keyboard[1][0])
    await app.answer_callback_query(message.id, "checkin")
    
    {
        "_": "Message",
        "id": 99075,
        "from_user": {
            "_": "User",
            "id": *********,
            "is_self": false,
            "is_contact": false,
            "is_mutual_contact": false,
            "is_deleted": false,
            "is_bot": true,
            "is_verified": false,
            "is_restricted": false,
            "is_scam": false,
            "is_fake": false,
            "is_support": false,
            "is_premium": false,
            "first_name": "333",
            "username": "******",
            "dc_id": 5,
            "photo": {
                "_": "ChatPhoto",
                "small_file_id": "AQADBQAEuDEbbLBJVQAQAgAD3e8ZlAEAA4qgtQNkdRPaAAQeBA",
                "small_photo_unique_id": "AgAEuDEbbLBJVQ",
                "big_file_id": "AQADBQAEuDEbbLBJVQAQAwAD3e8ZlAEAA4qgtQNkdRPaAAQeBA",
                "big_photo_unique_id": "AgAEuDEbbLBJVQ"
            }
        },
        "date": "2024-01-23 17:25:58",
        "chat": {
            "_": "Chat",
            "id": *********,
            "type": "ChatType.BOT",
            "is_verified": false,
            "is_restricted": false,
            "is_scam": false,
            "is_fake": false,
            "is_support": false,
            "username": "******",
            "first_name": "333",
            "photo": {
                "_": "ChatPhoto",
                "small_file_id": "AQADBQAEuDEbbLBJVQAQAgAD3e8ZlAEAA4qgtQNkdRPaAAQeBA",
                "small_photo_unique_id": "AgAEuDEbbLBJVQ",
                "big_file_id": "AQADBQAEuDEbbLBJVQAQAwAD3e8ZlAEAA4qgtQNkdRPaAAQeBA",
                "big_photo_unique_id": "AgAEuDEbbLBJVQ"
            },
            "dc_id": 5
        },
        "mentioned": false,
        "scheduled": false,
        "from_scheduled": false,
        "has_protected_content": false,
        "text": "🌟请选择您要使用的功能",
        "outgoing": false,
        "reply_markup": {
            "_": "InlineKeyboardMarkup",
            "inline_keyboard": [
                [
                    {
                        "_": "InlineKeyboardButton",
                        "text": "💰 [充值使用付费功能] ",
                        "callback_data": "recharge"
                    },
                    {
                        "_": "InlineKeyboardButton",
                        "text": "🤖 [ Bot 功能使用说明] ",
                        "callback_data": "guide"
                    }
                ],
                [
                    {
                        "_": "InlineKeyboardButton",
                        "text": "🎁 [签到] ",
                        "callback_data": "checkin"
                    },
                    {
                        "_": "InlineKeyboardButton",
                        "text": "🌟 [个人信息] ",
                        "callback_data": "personal_info"
                    }
                ]
            ]
        }
    }
    
    yaocf
        1
    yaocf  
    OP
       332 天前
    找到了,可能是算是新手吧,api 文档中的 tg 专业名词太多了。
    https://docs.pyrogram.org/api/methods/request_callback_answer

    如题示例:
    ```python
    await app.request_callback_answer(_id, message.id, "checkin", 0)
    ```
    最后的 timeout 参数不知道该怎么填,不过效果已经达到了。
    yaocf
        2
    yaocf  
    OP
       332 天前
    @yaocf pyrogram 的代码注释对这个方法的说明就是:This is the equivalent of clicking an inline button containing callback data.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2530 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 05:40 · PVG 13:40 · LAX 21:40 · JFK 00:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.