From 4c28d3868ca2b2131b6ac5fd9589fa2bdef02fb5 Mon Sep 17 00:00:00 2001 From: machka-pasla Date: Sat, 9 Aug 2025 09:43:02 +0300 Subject: [PATCH] Implement validation for broadcast message input in admin handler - Updated the broadcast message handler to trim whitespace from the input text and added a check for empty messages. - If the message is empty, an error response is sent to prompt the user for valid input, enhancing user experience and preventing empty broadcasts. --- bot/handlers/admin/broadcast.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bot/handlers/admin/broadcast.py b/bot/handlers/admin/broadcast.py index 7c701b3..aed5146 100644 --- a/bot/handlers/admin/broadcast.py +++ b/bot/handlers/admin/broadcast.py @@ -58,7 +58,7 @@ async def broadcast_message_prompt_handler( await state.set_state(AdminStates.waiting_for_broadcast_message) -@router.message(AdminStates.waiting_for_broadcast_message, F.text) +@router.message(AdminStates.waiting_for_broadcast_message) async def process_broadcast_message_handler( message: types.Message, state: FSMContext, @@ -76,9 +76,14 @@ async def process_broadcast_message_handler( _ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs) # Сохраняем в state исходный текст и entities - text = message.text or message.caption or "" + text = (message.text or message.caption or "").strip() entities = message.entities or message.caption_entities or [] + # Если текст пустой (например, прислали стикер/фото без подписи) — просим ввести текст + if not text: + await message.answer(_("admin_broadcast_error_no_message")) + return + await state.update_data( broadcast_text=text, broadcast_entities=entities,