How make admin panel for adding question using aiogram

168 Views Asked by At

I make tg bot using aiogram, bot asks questions to user with this construction:


class FSM(StatesGroup):
    phone = State()
    type_real = State()
    number_bedrooms = State()
    emirate = State()
    area_name = State()
    building_name = State()
    furnished = State()
    size = State()
    bathrooms = State()
    balcony = State()
    rent_type = State()
    price_in_aed = State()
    photos = State()
    deposit = State()
    commission = State()
    owner = State()
    contacts = State()
    description = State()


@dp.message_handler(Text(equals='Продолжить'))
async def continue_func(message:types.Message):
    kb = types.ReplyKeyboardMarkup(resize_keyboard=True).row(types.KeyboardButton('Поделиться телефоном ☎️',request_contact=True))
    await message.answer('Give me phone number',reply_markup=kb)
    await FSM.phone.set()


@dp.message_handler(content_types=types.ContentType.CONTACT,state = FSM.phone)
async def phone_func(message:types.Message,state:FSMContext):
    async with state.proxy() as data:
        data['phone'] = message.contact.phone_number
        data['nick'] = message.from_user.username
    kb = types.ReplyKeyboardMarkup(resize_keyboard=True).row(types.KeyboardButton('Apartment')).row(types.KeyboardButton('Villa')).row(types.KeyboardButton('Townhouse'))
    await message.answer('Choose type of your real',reply_markup=kb)
    await FSM.next()

@dp.message_handler(state=FSM.type_real)
async def func(message:types.Message,state:FSMContext):
    async with state.proxy() as data:
        data['type_real'] = message.text
    kb = types.ReplyKeyboardMarkup(resize_keyboard=True).row(types.KeyboardButton('Studio'),types.KeyboardButton('Townhouse')).row(types.KeyboardButton('1 bedroom'),types.KeyboardButton('2 bedroom')).row(types.KeyboardButton('3 bedroom'),types.KeyboardButton('4 bedroom')).row(types.KeyboardButton('5 bedroom'),types.KeyboardButton('6+ bedroom'))
    await message.answer('Please specify number of bedrooms',reply_markup=kb)
    await FSM.next()
....

So here's my question: How make admin panel to add questions, how to add handlers for answers and add fields to class FSM?

One way, that I invented is generate code and write in other file, replacing " " on "_" and naming states in class in this way, but that file need to run it somehow, and stop previous file. It seems to me that this is a very stupid method, but I couldn’t think of anything else

0

There are 0 best solutions below