Search code examples
python-3.xregextelegramtelebot

How to trigger CallBackQueryHandler returned by the user with a regex pattern?


I am creating a bot that has dynamic buttons and want to detect if the start of the callback query is classes_ and then allow me to further parse. How would I use regex or a built in pattern function to detect the beginning of a string?

@bot.callback_query_handler(func=lambda c: c.data == f'classes_'.startswith)
def callback_is_return(call: types.CallbackQuery):
    print('Found!')

I tried using ().startswith


Solution

  • Do this.

    @bot.callback_query_handler(func=lambda c: c.data.startswith('classes_'))