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

304 天前
 yaocf

通过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"
                }
            ]
        ]
    }
}
669 次点击
所在节点    Telegram
2 条回复
yaocf
304 天前
找到了,可能是算是新手吧,api 文档中的 tg 专业名词太多了。
https://docs.pyrogram.org/api/methods/request_callback_answer

如题示例:
```python
await app.request_callback_answer(_id, message.id, "checkin", 0)
```
最后的 timeout 参数不知道该怎么填,不过效果已经达到了。
yaocf
304 天前
@yaocf pyrogram 的代码注释对这个方法的说明就是:This is the equivalent of clicking an inline button containing callback data.

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1011111

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX