Search code examples
pythonpython-decoratorspy-telegram-bot-api

PyTelegrambotApi — @callback_query_handler doesn't turn to the next step of the bot


I'm using PyTelegrambotApi to create a bot.

Requesting and receiving data appears to work; however, when I'm using the inline keyboard and create callback_query_handler to handle the user's choice the callback does not appear to fire.

Once the user has made a choice, the user should be asked for a price, but as it stands I have to send a message to the bot to trigger it. The bot will stay frozen until I send a random message - for example "Hey?" - and only then the bot starts the next step.

@bot.callback_query_handler(func=lambda call: True)
def user_answer(call):
    user[call.message.chat.id].city_id = call.data #creates dict from received data
    bot.register_next_step_handler(call.message, get_price) # <-- stuck at this point

The next step is:

def get_price(message):
    bot.send_message(message.chat.id, 'What's the price?')
    bot.register_next_step_handler(message, save_price)

Can somebody assist me to figure it out, please?

Thank you in advance!


Solution

  • I found a way to resolve this problem.

    Instead of register the next step, I just called function and it works well.