Answer the question
In order to leave comments, you need to log in
How to implement user data entry in telegram bot in Python?
In general, I just started learning Python. I have long wanted to implement a telegram bot for placing orders. As a result, I ran into a problem: by pressing the "Place an order" button, the bot sends a message and requests personal data starting with full name (let's dwell on this for now). It is necessary that the bot understands that the name is written in the next message.
I'm trying to make the user write down their data starting with the full name and if the bot sees the full name in the message, then it saves the data in the FSM storage
I use aiogram and Telethon
Here is the source (do not judge strictly)
class CheckOut(StatesGroup):
waiting_buyer_name = State()
@dp.message_handler(Text(equals=["Оформить заказ", "/checkout"]))
async def checkout(message: types.Message):
await message.answer("Я начинаю собирать ваш заказ\nДля этого мне нужны Ваши данные\nЗапишите ваши ФИО <b>(начинайте сообщение с ФИО)</b>", reply_markup=types.ReplyKeyboardRemove())
await CheckOut.waiting_buyer_name.set()
async def checkout_choosen_name(message: types.Message, state: FSMContext):
if "фио" not in message.text.lower():
await message.answer("Скорее всего вы ввели Ваши данные в неправильном формате.\n Пожалуйста, Запишите ваши ФИО <b>(начинайте сообщение с ФИО)</b>")
return
await state.update_data(buyer_name_writen=message.text.lower())
Answer the question
In order to leave comments, you need to log in
I found the solution in the official documentation of aiogram. Everything seems to be clear there =)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question