form_router = Router()
class Form(StatesGroup):
name = State()
kolvo = State()
cena = State()
@form_router.message(CommandStart())
async def commands_start(message: Message, state: FSMContext) -> None:
await state.set_state(Form.name)
await message.answer('Привет! Как тебя зовут?', reply_markup=ReplyKeyboardRemove())
@form_router.message(Form.name)
async def process_name(message: Message, state: FSMContext):
await state.update_data(name=message.text)
await message.answer('Выберите кнопку ниже', reply_markup=ReplyKeyboardMarkup(keyboard=[[KeyboardButton(text='Купить'),KeyboardButton(text='Продать'),]],resize_keyboard=True,))
if message.text == 'Продать':
await state.set_state(Form.kolvo)
await message.answer('Введи количество')
@form_router.message(Form.kolvo)
async def proc(message: Message, state: FSMContext):
await state.update_data(kolvo=message.text)
await state.set_state(Form.cena)
await message.answer('Введи цену')
@form_router.message(Form.cena)
async def ceeee(message: Message, state: FSMContext):
await state.update_data(cena=message.text)
data = await state.get_data()
name = data.get('name')
kolvo = data.get('kolvo')
cena = data.get('cena')
await message.answer(f'Имя: {name} Количество: {kolvo} Цена: {cena}')
async def main():
bot = Bot(token=TOKEN, parse_mode=ParseMode.HTML)
dp = Dispatcher()
dp.include_router(form_router)
await dp.start_polling(bot)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
asyncio.run(main())
@form_router.message(Form.name)
async def process_name(message: Message, state: FSMContext):
@form_router.message(Form.name)
async def process_name(message: Message, state: FSMContext):
await state.update_data(name=message.text)
await message.answer('Выберите кнопку ниже', reply_markup=ReplyKeyboardMarkup(keyboard=[[KeyboardButton(text='Купить'),KeyboardButton(text='Продать'),]],resize_keyboard=True,))
if message.text == 'Продать':
await state.set_state(Form.kolvo)
await message.answer('Введи количество')