smart-bot-factory 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of smart-bot-factory might be problematic. Click here for more details.

@@ -46,6 +46,7 @@ class BotBuilder:
46
46
  self.prompt_loader: Optional[PromptLoader] = None
47
47
  self.router_manager: Optional[RouterManager] = None
48
48
  self._telegram_routers: List = [] # Список Telegram роутеров
49
+ self._start_handlers: List = [] # Список обработчиков on_start
49
50
 
50
51
  # Флаги инициализации
51
52
  self._initialized = False
@@ -326,6 +327,37 @@ class BotBuilder:
326
327
 
327
328
  logger.info(f"✅ Зарегистрировано {len(telegram_routers)} Telegram роутеров")
328
329
 
330
+ def on_start(self, handler):
331
+ """
332
+ Регистрирует обработчик, который вызывается после стандартной логики /start
333
+
334
+ Обработчик получает доступ к:
335
+ - user_id: int - ID пользователя Telegram
336
+ - session_id: str - ID созданной сессии
337
+ - message: Message - Объект сообщения от aiogram
338
+ - state: FSMContext - Контекст состояния
339
+
340
+ Args:
341
+ handler: Async функция с сигнатурой:
342
+ async def handler(user_id: int, session_id: str, message: Message, state: FSMContext)
343
+
344
+ Example:
345
+ @bot_builder.on_start
346
+ async def my_start_handler(user_id, session_id, message, state):
347
+ keyboard = InlineKeyboardMarkup(...)
348
+ await message.answer("Выберите действие:", reply_markup=keyboard)
349
+ """
350
+ if not callable(handler):
351
+ raise TypeError(f"Обработчик должен быть callable, получен {type(handler)}")
352
+
353
+ self._start_handlers.append(handler)
354
+ logger.info(f"✅ Зарегистрирован обработчик on_start: {handler.__name__}")
355
+ return handler # Возвращаем handler для использования как декоратор
356
+
357
+ def get_start_handlers(self) -> List:
358
+ """Получает список обработчиков on_start"""
359
+ return self._start_handlers.copy()
360
+
329
361
  def get_router_manager(self) -> RouterManager:
330
362
  """Получает менеджер роутеров событий"""
331
363
  return self.router_manager
@@ -374,6 +406,7 @@ class BotBuilder:
374
406
  handlers_module.admin_manager = self.admin_manager
375
407
  handlers_module.analytics_manager = self.analytics_manager
376
408
  handlers_module.conversation_manager = self.conversation_manager
409
+ handlers_module.start_handlers = self._start_handlers # Передаем обработчики on_start
377
410
  logger.info("✅ Глобальные переменные установлены в handlers")
378
411
  except Exception as e:
379
412
  logger.warning(f"⚠️ Не удалось установить глобальные переменные в handlers: {e}")
@@ -277,6 +277,23 @@ async def user_start_handler(message: Message, state: FSMContext):
277
277
 
278
278
  logging.info(f"✅ Приветственное сообщение успешно сохранено в БД для сессии {session_id}")
279
279
 
280
+ # ВЫЗЫВАЕМ ПОЛЬЗОВАТЕЛЬСКИЕ ОБРАБОТЧИКИ on_start
281
+ start_handlers = get_global_var('start_handlers')
282
+ if start_handlers:
283
+ logger.info(f"🔔 Вызов {len(start_handlers)} пользовательских обработчиков on_start")
284
+ for handler in start_handlers:
285
+ try:
286
+ await handler(
287
+ user_id=message.from_user.id,
288
+ session_id=session_id,
289
+ message=message,
290
+ state=state
291
+ )
292
+ logger.info(f"✅ Обработчик on_start '{handler.__name__}' выполнен успешно")
293
+ except Exception as handler_error:
294
+ logger.error(f"❌ Ошибка в обработчике on_start '{handler.__name__}': {handler_error}")
295
+ # Продолжаем выполнение остальных обработчиков
296
+
280
297
  except Exception as e:
281
298
  logger.error(f"Ошибка при обработке user /start: {e}")
282
299
  await send_message(message, "Произошла ошибка при инициализации. Попробуйте позже.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: smart-bot-factory
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Библиотека для создания умных чат-ботов
5
5
  Author-email: Kopatych <kopatych@example.com>
6
6
  License: MIT
@@ -33,12 +33,12 @@ smart_bot_factory/core/router_manager.py,sha256=dUwesog-oHk1U2EDdS8p0e4MTSkwtx5_
33
33
  smart_bot_factory/core/states.py,sha256=AOc19_yAsDW_8md-2oiowjBhuW3bwcsmMxszCXWZZTQ,355
34
34
  smart_bot_factory/core/telegram_router.py,sha256=LcPLOd87Y4Y4YN6TBXVAtmpSp8gAK2otgMI4YS5f5tk,2091
35
35
  smart_bot_factory/creation/__init__.py,sha256=IgDk8GDS3pg7Pw_Et41J33ZmeZIU5dRwQdTmYKXfJfE,128
36
- smart_bot_factory/creation/bot_builder.py,sha256=xWgWRe4DV3PngiLoQlzm6AdhNvPqn3wOCwcgsIoh-QA,25220
36
+ smart_bot_factory/creation/bot_builder.py,sha256=RhnnZZhNvJC-nKTly5VvoxpXBucKFoXUl4e5gfBk7TI,27057
37
37
  smart_bot_factory/creation/bot_testing.py,sha256=JDWXyJfZmbgo-DLdAPk8Sd9FiehtHHa4sLD17lBrTOc,55669
38
38
  smart_bot_factory/database/database_structure.sql,sha256=26gFtMC2jdQGQF7Zb_F4Br56rMd4hUDTk9FkNZYneLo,2789
39
39
  smart_bot_factory/database/schema.sql,sha256=-6kOmA9QnSkUtmGI2iQRbTvbdiqOhEOQcuz1lJn79mU,28059
40
40
  smart_bot_factory/event/__init__.py,sha256=hPL449RULIOB-OXv1ZbGNiHctAYaOMUqhSWGPrDHYBM,212
41
- smart_bot_factory/handlers/handlers.py,sha256=YH8xG0tDcb7uxZXI4socXURzc-y57_FEQ6GqTgYcM5Q,37603
41
+ smart_bot_factory/handlers/handlers.py,sha256=1_0CAbedbmdSBeWPF9KR97RM6zNWPv56wR9EdrfPtdo,38630
42
42
  smart_bot_factory/integrations/openai_client.py,sha256=aMcDrKO0GEx3ZSVEOGDeDtFCDWSXs6biUfgrbRK8yTU,23180
43
43
  smart_bot_factory/integrations/supabase_client.py,sha256=AfALLZdDYeMWHLJw6POTGiBd-sH3i03oT6tT7m9C28I,44644
44
44
  smart_bot_factory/message/__init__.py,sha256=6QvjdfF99venyDB9udZv9WDNjIHJLNuaVhYdTK3a44A,282
@@ -48,8 +48,8 @@ smart_bot_factory/supabase/client.py,sha256=8_-I3kxZQlKQElI4cTUjNGYcqlyIyEkSrUZa
48
48
  smart_bot_factory/utils/__init__.py,sha256=5zNjw491bj5VkOhoEAwh2hjmv8nldyDOTrG7pbGpz6A,285
49
49
  smart_bot_factory/utils/debug_routing.py,sha256=BOoDhKBg7UXe5uHQxRk3TSfPfLPOFqt0N7lAo6kjCOo,4719
50
50
  smart_bot_factory/utils/prompt_loader.py,sha256=JSn7CsWnToSbHYtURdeuZn7ectyDqQGrPGHN2ixIGkw,19930
51
- smart_bot_factory-0.2.0.dist-info/METADATA,sha256=WEC38O2La8OlQpfCZWkXjhMU70VigduV0wIrferi2w0,28224
52
- smart_bot_factory-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
53
- smart_bot_factory-0.2.0.dist-info/entry_points.txt,sha256=ybKEAI0WSb7WoRiey7QE-HHfn88UGV7nxLDxXq7b7SU,50
54
- smart_bot_factory-0.2.0.dist-info/licenses/LICENSE,sha256=OrK3cwdUTzNzIhJvSPtJaVMoYIyC_sSx5EFE_FDMvGs,1092
55
- smart_bot_factory-0.2.0.dist-info/RECORD,,
51
+ smart_bot_factory-0.2.1.dist-info/METADATA,sha256=wj1v5p2joJlA_u9LcfBFPFjPqBfxvFu1BxUE389uwDA,28224
52
+ smart_bot_factory-0.2.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
53
+ smart_bot_factory-0.2.1.dist-info/entry_points.txt,sha256=ybKEAI0WSb7WoRiey7QE-HHfn88UGV7nxLDxXq7b7SU,50
54
+ smart_bot_factory-0.2.1.dist-info/licenses/LICENSE,sha256=OrK3cwdUTzNzIhJvSPtJaVMoYIyC_sSx5EFE_FDMvGs,1092
55
+ smart_bot_factory-0.2.1.dist-info/RECORD,,