def chunks(l, n):
n = max(1, n)
return list((l[i:i + n] for i in range(0, len(l), n)))
def create_markup(group_id, update):
buttons = []
if group_id == 0:
buttons += ['кнопка1','кнопка2',...]
elif group_id == 1:
buttons += ['кнопка1','кнопка2',...]
...
keyboard = [KeyboardButton(button) for button in buttons]
if len(keyboard) > 3:
keyboard = chunks(keyboard, 3)
else:
keyboard = [keyboard]
markup = ReplyKeyboardMarkup(keyboard, resize_keyboard=True)
return markup
def second_step(update, context):
if text == '...':
markup = create_markup(group_id=0, update=update)
context.bot.send_message(chat_id=update.message.chat_id,
text='...',
reply_markup=markup)
elif text == '...':
markup = create_markup(group_id=1, update=update)
context.bot.send_message(chat_id=update.message.chat_id,
text='...',
reply_markup=markup)