I’m working on a Telegram bot using the telebot library, and I’m trying to update an inline button’s text after a user enters their input. I need a solution to ensure the button’s label changes accordingly.
Here’s a sample version of my code to illustrate my approach:
@bot.message_handler(commands=['start'])
def begin(message):
keyboard = types.InlineKeyboardMarkup()
login_btn = types.InlineKeyboardButton(text='Login', callback_data='login')
keyboard.add(login_btn)
bot.send_message(message.chat.id, "Main menu:", reply_markup=keyboard)
def ask_wallet(message):
keyboard = types.InlineKeyboardMarkup()
back_btn = types.InlineKeyboardButton(text='Back', callback_data='go_back')
keyboard.add(back_btn)
bot.edit_message_text(chat_id=message.chat.id, message_id=message.id,
text='Please enter your wallet address', reply_markup=keyboard)
bot.register_next_step_handler(message, process_wallet)
def process_wallet(message):
keyboard = types.InlineKeyboardMarkup()
back_btn = types.InlineKeyboardButton(text='Back', callback_data='go_back')
keyboard.add(back_btn)
bot.edit_message_text(chat_id=message.chat.id, message_id=message.id,
text='Invalid wallet address', reply_markup=keyboard)
@bot.callback_query_handler(func=lambda call: True)
def handle_buttons(call):
if call.data == 'login':
ask_wallet(call.message)
How can I implement the change so that the inline button’s label updates once the user inputs text?