Python 如何处理电报机器人的InlineKeyboardButtons回调

Python 如何处理电报机器人的InlineKeyboardButtons回调,python,telegram-bot,Python,Telegram Bot,如何处理内联键盘的回调?我试图在这里查看有关此主题的文档,但没有找到任何有助于我解决此问题的内容 这是我想要实现的,如果用户按下任何按钮,机器人就会知道按下了哪个按钮,并用它做些什么。这是我到目前为止的代码片段 from django_tgbot.decorators import processor from django_tgbot.state_manager import message_types, update_types, state_types from django_tgbot.

如何处理内联键盘的回调?我试图在这里查看有关此主题的文档,但没有找到任何有助于我解决此问题的内容

这是我想要实现的,如果用户按下任何按钮,机器人就会知道按下了哪个按钮,并用它做些什么。这是我到目前为止的代码片段

from django_tgbot.decorators import processor
from django_tgbot.state_manager import message_types, update_types, state_types
from django_tgbot.types.update import Update
from ..bot import state_manager
from ..models import TelegramState
from ..bot import TelegramBot


from django_tgbot.types.inlinekeyboardbutton import InlineKeyboardButton
from django_tgbot.types.inlinekeyboardmarkup import InlineKeyboardMarkup
from django_tgbot.types.keyboardbutton import KeyboardButton
from django_tgbot.types.replykeyboardremove import ReplyKeyboardRemove

from django_tgbot.types.replykeyboardmarkup import ReplyKeyboardMarkup



@processor(state_manager,success='asked_to_select_main_menu_options')
def main_manu_options(bot: TelegramBot, update: Update, state: TelegramState):
    chat_id = update.get_chat().get_id()

    bot.sendMessage(
        chat_id,
        text='What would you like to do?',
        reply_markup=InlineKeyboardMarkup.a(
            inline_keyboard=[
                [
                    InlineKeyboardButton.a('Parking',callback_data='PK'),
                ],
                [
                    InlineKeyboardButton.a('SBP', callback_data='SBP')
                ],
                [
                    InlineKeyboardButton.a('Land Rates',callback_data='LR')
                ],
                [
                    InlineKeyboardButton.a('Rent',callback_data='R')
                ],
                [
                    InlineKeyboardButton.a('Bill Payment',callback_data='B')
                ]
            ]
        )
    )

应使用InlineKeyboardButton的结果处理更新的处理器正在调用
CallbackQuery
,您应将其作为参数添加到
Update\u type
,请参见示例:

处理器(状态管理器,from\u states=state\u types.All,update\u types=[update\u types.CallbackQuery]) def handle_callback_查询(bot:TelegramBot,update,state): callback\u data=update.get\u callback\u query().get\u data() bot.answerCallbackQuery(update.get_callback_query().get_id(),text='callbackdata received:{}'。格式(callback_data)) 使用
InlineKeyboardButton
并利用库的bot的