How to optimize my telegram bot written in Python?
From my point of view you can use a visitor pattern for this with a simple dictionary, specially for your operations, here is a small example:
Insead of this
@bot.callback_query_handler(func=lambda call: True)
def tempo(call):

    # here a handle the queries launched both by main buttons and the inline keyboard 


    if call.data == &quot;demo_yes&quot;:

        keyboard = types.InlineKeyboardMarkup()
        ......

Use the following
tempo_operations = {&quot;demo_yes&quot; : demo_yes_function,
                    &quot;demo_no&quot; : demo_no_function, 
                    ....}

@bot.callback_query_handler(func=lambda call: True)
def tempo(call):

    if call.data in tempo_operations:
        tempo_operations[call.data]()
    else:
        print(&quot;Operation not supported&quot;)

Hope you can get the idea :)