How to optimize my telegram bot written in Python? I have written a fairly simple bot that provides information or additional choice based on the user's query. It runs well and does the job, however, I was wondering how can I optimize my code and use the telebot better?
Currently the main action happens in the query handler and something tells me that I am missing possible efficiency gains (when I will attempt to build more choices for example). Below is the code, simplified for demonstration purposes:
import telebot
from telebot import types

token = bottoken

bot = telebot.TeleBot(token)

@bot.message_handler(commands=['start'])
def welcome(message):

    # here i give the main choice that is always visible to the user

    markup = types.ReplyKeyboardMarkup(resize_keyboard=False)
    item1 = types.KeyboardButton(&quot;Button1&quot;)
    item2 = types.KeyboardButton(&quot;Button2&quot;)

    markup.add(item1, item2)

    bot.send_message(message.chat.id, &quot;Welcome message&quot;.format(message.from_user, bot.get_me()),
        parse_mode='html', reply_markup=markup)


@bot.message_handler(content_types=['text'])
def main_choice(message):

    # here i develop each of the main choices and redirect to the callback handler

    if message.text == 'Button1':

        # Forward to callback handler

            markup = types.InlineKeyboardMarkup()
            item1 = types.InlineKeyboardButton(&quot;Yes&quot;, callback_data = 'demo_yes')
            item2 = types.InlineKeyboardButton(&quot;No&quot;, callback_data = 'demo_no')

            markup.add(item1, item2)

            bot.send_message(message.chat.id, 'Some text', reply_markup=markup)


    elif message.text == 'Button2':

        # some logic

    else :
        bot.send_message(message.chat.id, 'Sorry, i dont understand. You can use /help to check how i work')


@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()
        item1 = types.InlineKeyboardButton(&quot;Text1&quot;, callback_data = 'call1')
        item2 = types.InlineKeyboardButton(&quot;Text2&quot;, callback_data = 'call2')
        keyboard.add(item1,item2)

        bot.send_message(call.message.chat.id, 'message', reply_markup = keyboard)

    elif call.data == &quot;demo_no&quot;:

        kkeyboard = types.InlineKeyboardMarkup()
        item1 = types.InlineKeyboardButton(&quot;Text3&quot;, callback_data = 'call3')
        item2 = types.InlineKeyboardButton(&quot;Text4&quot;, callback_data = 'call4')
        keyboard.add(item1,item2)

        bot.send_message(call.message.chat.id, 'message', reply_markup = keyboard)

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

        keyboard = types.InlineKeyboardMarkup()
        item1 = types.InlineKeyboardButton(&quot;Text5&quot;, callback_data = 'another_call1')
        item2 = types.InlineKeyboardButton(&quot;Text6&quot;, callback_data = 'another_call2')
        keyboard.add(item1,item2)

        bot.send_message(call.message.chat.id, 'message', reply_markup = keyboard)

    elif call.data == &quot;call2&quot;:

        kkeyboard = types.InlineKeyboardMarkup()
        item1 = types.InlineKeyboardButton(&quot;Text7&quot;, callback_data = 'another_call3')
        item2 = types.InlineKeyboardButton(&quot;Text8&quot;, callback_data = 'another_call4')
        keyboard.add(item1,item2)

        bot.send_message(call.message.chat.id, 'message', reply_markup = keyboard)
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 :)