如何在单击旧内联按钮时创建新的内联键盘,而不是替换

问题描述 投票:0回答:1

我是python-telegram bot的新手,当我按下旧的内联键盘而不更换旧的键盘时,我想创建一个新的内联键盘。我使用“editMessageText”来处理回调查询。但它只用“reply_markup”替换了inlinekeyboard,但我想创建一个新的inlinekeyboard。如何解决这个问题呢?我在堆栈溢出中搜索了很多次。但是我现在还无法找到解决方案吗?请帮我解决问题!我的形象是

This is my start(CommandHandler)

def start(bot, update):
    bot.sendChatAction(update.message.chat_id, action=ChatAction.TYPING)
    bot.send_message(chat_id=update.message.chat_id, text=Message.CLAIM,parse_mode='html')
    reply_markup = telegram.InlineKeyboardMarkup([[telegram.InlineKeyboardButton("Check New Model",callback_data="New Model")],
                                                [telegram.InlineKeyboardButton("Reasses my Insurance",callback_data="Reasses")],
                                                [telegram.InlineKeyboardButton("File a Claim",callback_data="claim")]])

    bot.sendMessage(chat_id=update.message.chat_id, text="Choose the above one?", reply_markup=reply_markup)

This is my Callback Handler

def callback(bot,update):
   query=update.callback_query
   if query.data=="claim":


       reply_markup = telegram.InlineKeyboardMarkup([[telegram.InlineKeyboardButton("Vehicle",callback_data="vehicle")],
                                                    [telegram.InlineKeyboardButton("Personal Accident",callback_data="accident")],
                                                    [telegram.InlineKeyboardButton("Other",callback_data="other")]])
       bot.editMessageText(
                message_id = update.callback_query.message.message_id,
                chat_id = update.callback_query.message.chat.id,
                text = "Choose the one below",
                reply_markup=reply_markup
                )
python-3.x python-telegram-bot
1个回答
0
投票

根据它的名称,bot.edit_message_text用于编辑消息的文本。你需要使用bot.edit_message_reply_markupdocs)。

如果你想在现有键盘上添加一些按钮(如果我理解你的问题),只需将它包含在编辑中:

reply_markup = telegram.InlineKeyboardMarkup([
[telegram.InlineKeyboardButton("Check New Model",callback_data="New Model")],
[telegram.InlineKeyboardButton("Reasses my Insurance",callback_data="Reasses")],
[telegram.InlineKeyboardButton("File a Claim",callback_data="claim")],[telegram.InlineKeyboardButton("Vehicle",callback_data="vehicle")],[telegram.InlineKeyboardButton("Personal Accident",callback_data="accident")],
[telegram.InlineKeyboardButton("Other",callback_data="other")]
])
© www.soinside.com 2019 - 2024. All rights reserved.