smart-bot-factory 0.2.0__tar.gz → 0.2.1__tar.gz

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.

Files changed (102) hide show
  1. smart_bot_factory-0.2.1/.claude/settings.local.json +10 -0
  2. smart_bot_factory-0.2.1/.env.example +40 -0
  3. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/PKG-INFO +1 -1
  4. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/best-valera.py +49 -3
  5. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/pyproject.toml +1 -1
  6. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/creation/bot_builder.py +33 -0
  7. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/handlers/handlers.py +17 -0
  8. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/uv.lock +1 -1
  9. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/.github/ISSUE_TEMPLATE//342/234/250-/320/267/320/260/320/277/321/200/320/276/321/201-/321/204/321/203/320/275/320/272/321/206/320/270/320/270.md" +0 -0
  10. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/.github/ISSUE_TEMPLATE//360/237/220/233-/320/261/320/260/320/263-/321/200/320/265/320/277/320/276/321/200/321/202.md" +0 -0
  11. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/.github/workflows/ci.yml +0 -0
  12. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/.github/workflows/publish-private.yml +0 -0
  13. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/.github/workflows/publish.yml +0 -0
  14. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/.gitignore +0 -0
  15. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/.python-version +0 -0
  16. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/CLIENTS_USAGE.md +0 -0
  17. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/Dockerfile +0 -0
  18. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/LICENSE +0 -0
  19. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/README.md +0 -0
  20. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/best-valera/prompts/1sales_context.txt +0 -0
  21. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/best-valera/prompts/2product_info.txt +0 -0
  22. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/best-valera/prompts/3objection_handling.txt +0 -0
  23. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/best-valera/prompts/final_instructions.txt +0 -0
  24. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/best-valera/prompts/help_message.txt +0 -0
  25. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/best-valera/prompts/welcome_message.txt +0 -0
  26. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/best-valera/tests/quick_scenarios.yaml +0 -0
  27. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/best-valera/tests/realistic_scenarios.yaml +0 -0
  28. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/best-valera/tests/scenario_examples.yaml +0 -0
  29. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/best-valera/welcome_files/welcome_file_msg.txt +0 -0
  30. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/best-valera/welcome_files//320/247/320/265/320/272 /320/273/320/270/321/201/321/202 /320/277/320/276 152/320/244/320/227 /320/270 323/320/244/320/227 /320/264/320/273/321/217 /320/274/320/265/320/264/320/270/321/206/320/270/320/275/321/213.pdf" +0 -0
  31. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/valera/prompts/2product_info.txt +0 -0
  32. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/valera/prompts/3objection_handling.txt +0 -0
  33. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/valera/prompts/final_instructions.txt +0 -0
  34. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/valera/prompts/help_message.txt +0 -0
  35. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/valera/prompts/welcome_message.txt +0 -0
  36. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/valera/tests/quick_scenarios.yaml +0 -0
  37. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/valera/tests/realistic_scenarios.yaml +0 -0
  38. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/valera/tests/scenario_examples.yaml +0 -0
  39. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/valera/welcome_files/welcome_file_msg.txt +0 -0
  40. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/bots/valera/welcome_files//320/247/320/265/320/272 /320/273/320/270/321/201/321/202 /320/277/320/276 152/320/244/320/227 /320/270 323/320/244/320/227 /320/264/320/273/321/217 /320/274/320/265/320/264/320/270/321/206/320/270/320/275/321/213.pdf" +0 -0
  41. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/configs/valera/cats//320/224/320/276/320/263/320/276/320/262/320/276/321/200.pdf" +0 -0
  42. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/configs/valera/cats//320/272/320/276/320/275/320/270.jpg" +0 -0
  43. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/configs/valera/cats//320/272/320/276/321/202.jpg" +0 -0
  44. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/configs/valera/cats//320/273/320/265/321/201.jpg" +0 -0
  45. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/configs/valera/tests/fixes_elina.yaml +0 -0
  46. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/configs/valera/welcome_file//320/247/320/265/320/272 /320/273/320/270/321/201/321/202 /320/277/320/276 152/320/244/320/227 /320/270 323/320/244/320/227 /320/264/320/273/321/217 /320/274/320/265/320/264/320/270/321/206/320/270/320/275/321/213.pdf" +0 -0
  47. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/create_tag.sh +0 -0
  48. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/docker-compose.yml +0 -0
  49. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/env.example +0 -0
  50. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/requirements.txt +0 -0
  51. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/save_backup.sh +0 -0
  52. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/save_fixes.sh +0 -0
  53. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/__init__.py +0 -0
  54. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/admin/__init__.py +0 -0
  55. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/admin/admin_logic.py +0 -0
  56. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/admin/admin_manager.py +0 -0
  57. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/admin/admin_migration.sql +0 -0
  58. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/admin/admin_tester.py +0 -0
  59. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/admin/timeout_checker.py +0 -0
  60. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/analytics/analytics_manager.py +0 -0
  61. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/cli.py +0 -0
  62. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/config.py +0 -0
  63. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/configs/growthmed-october-24/prompts/1sales_context.txt +0 -0
  64. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/configs/growthmed-october-24/prompts/2product_info.txt +0 -0
  65. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/configs/growthmed-october-24/prompts/3objection_handling.txt +0 -0
  66. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/configs/growthmed-october-24/prompts/final_instructions.txt +0 -0
  67. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/configs/growthmed-october-24/prompts/help_message.txt +0 -0
  68. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/configs/growthmed-october-24/prompts/welcome_message.txt +0 -0
  69. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/configs/growthmed-october-24/reports/test_20250924_064229.txt +0 -0
  70. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/configs/growthmed-october-24/reports/test_20250924_064335.txt +0 -0
  71. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/configs/growthmed-october-24/reports/test_20250924_064638.txt +0 -0
  72. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/configs/growthmed-october-24/tests/quick_scenarios.yaml +0 -0
  73. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/configs/growthmed-october-24/tests/realistic_scenarios.yaml +0 -0
  74. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/configs/growthmed-october-24/tests/scenario_examples.yaml +0 -0
  75. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/configs/growthmed-october-24/welcome_file/welcome_file_msg.txt +0 -0
  76. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/configs/growthmed-october-24/welcome_file//320/247/320/265/320/272 /320/273/320/270/321/201/321/202 /320/277/320/276 152/320/244/320/227 /320/270 323/320/244/320/227 /320/264/320/273/321/217 /320/274/320/265/320/264/320/270/321/206/320/270/320/275/321/213.pdf" +0 -0
  77. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/core/bot_utils.py +0 -0
  78. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/core/conversation_manager.py +0 -0
  79. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/core/decorators.py +0 -0
  80. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/core/message_sender.py +0 -0
  81. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/core/router.py +0 -0
  82. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/core/router_manager.py +0 -0
  83. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/core/states.py +0 -0
  84. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/core/telegram_router.py +0 -0
  85. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/creation/__init__.py +0 -0
  86. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/creation/bot_testing.py +0 -0
  87. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/database/database_structure.sql +0 -0
  88. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/database/schema.sql +0 -0
  89. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/event/__init__.py +0 -0
  90. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/integrations/openai_client.py +0 -0
  91. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/integrations/supabase_client.py +0 -0
  92. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/message/__init__.py +0 -0
  93. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/router/__init__.py +0 -0
  94. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/setup_checker.py +0 -0
  95. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/supabase/__init__.py +0 -0
  96. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/supabase/client.py +0 -0
  97. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/utils/__init__.py +0 -0
  98. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/utils/debug_routing.py +0 -0
  99. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/utils/prompt_loader.py +0 -0
  100. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/smart_bot_factory/utm_link_generator.py +0 -0
  101. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/system_prompt_example.txt +0 -0
  102. {smart_bot_factory-0.2.0 → smart_bot_factory-0.2.1}/valera.py +0 -0
@@ -0,0 +1,10 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(awk:*)",
5
+ "Bash(python:*)"
6
+ ],
7
+ "deny": [],
8
+ "ask": []
9
+ }
10
+ }
@@ -0,0 +1,40 @@
1
+ # Telegram
2
+ TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
3
+
4
+ # Supabase
5
+ SUPABASE_URL=https://your-project.supabase.co
6
+ SUPABASE_KEY=your_supabase_anon_key
7
+
8
+ # OpenAI
9
+ OPENAI_API_KEY=sk-your-openai-api-key
10
+ OPENAI_MODEL=gpt-5-mini
11
+ OPENAI_MAX_TOKENS=1500
12
+ OPENAI_TEMPERATURE=0.7
13
+
14
+ # Промпты (каталог)
15
+ PROMT_FILES_DIR=prompts
16
+
17
+ # Файл после приветствия с подписью (если он есть - грузим его в папку welcome_file, если нет - ничего не делаем)
18
+ WELCOME_FILE_URL=welcome_file/
19
+ WELCOME_FILE_MSG=welcome_file_msg.txt
20
+
21
+ # 🆕 Администраторы (через запятую)
22
+ # Укажите Telegram ID админов
23
+ ADMIN_TELEGRAM_IDS=123456789,987654321
24
+ ADMIN_SESSION_TIMEOUT_MINUTES=30
25
+
26
+ # 🆕 Режим отладки (показывать JSON пользователям)
27
+ DEBUG_MODE=false
28
+
29
+ # Дополнительные настройки
30
+ MAX_CONTEXT_MESSAGES=50
31
+ LOG_LEVEL=INFO
32
+ MESSAGE_PARSE_MODE=Markdown
33
+
34
+ # Настройки продаж
35
+ LEAD_QUALIFICATION_THRESHOLD=7
36
+ SESSION_TIMEOUT_HOURS=24
37
+
38
+ # ⚠️ ВАЖНО: BOT_ID теперь НЕ нужен в .env!
39
+ # Bot ID автоматически определяется из имени файла запускалки
40
+ # Например: python growthmed-october-24.py → BOT_ID = growthmed-october-24
@@ -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
@@ -18,15 +18,43 @@ telegram_router_2 = TelegramRouter("best-valera_telegram_2")
18
18
 
19
19
  supabase_client = SupabaseClient("best-valera")
20
20
 
21
+ # =============================================================================
22
+ # ИНИЦИАЛИЗАЦИЯ BOT BUILDER (нужен для декоратора on_start)
23
+ # =============================================================================
24
+
25
+ bot_builder = BotBuilder("best-valera")
26
+
21
27
  # =============================================================================
22
28
  # TELEGRAM ОБРАБОТЧИКИ (используем прямой aiogram API)
23
29
  # =============================================================================
24
30
 
25
31
  from aiogram import F
26
32
  from aiogram.filters import Command
27
- from aiogram.types import Message, CallbackQuery
33
+ from aiogram.types import Message, CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton
28
34
  from aiogram.fsm.context import FSMContext
29
35
 
36
+ # =============================================================================
37
+ # ОБРАБОТЧИК on_start (вызывается после стандартного /start)
38
+ # =============================================================================
39
+
40
+ @bot_builder.on_start
41
+ async def custom_start_handler(user_id: int, session_id: str, message: Message, state: FSMContext):
42
+ """
43
+ Вызывается после стандартной логики /start
44
+ Здесь можно отправить дополнительные сообщения, кнопки и т.д.
45
+ """
46
+ # Пример: отправляем сообщение с кнопками
47
+ keyboard = InlineKeyboardMarkup(inline_keyboard=[
48
+ [InlineKeyboardButton(text="📖 Каталог", callback_data="catalog")],
49
+ [InlineKeyboardButton(text="💰 Цены", callback_data="prices")],
50
+ [InlineKeyboardButton(text="📞 Связаться", callback_data="contact")]
51
+ ])
52
+
53
+ await message.answer(
54
+ "🎯 Что вас интересует?",
55
+ reply_markup=keyboard
56
+ )
57
+
30
58
  @telegram_router_1.router.message(Command("price", "цена"))
31
59
  async def handle_price_command(message: Message, state: FSMContext):
32
60
  """Обработчик команды /price"""
@@ -42,6 +70,25 @@ async def handle_price_question(message: Message, state: FSMContext):
42
70
  """Обработчик вопросов о цене"""
43
71
  await message.answer("💡 Напишите /price чтобы увидеть актуальные цены")
44
72
 
73
+ # Обработчики callback'ов от кнопок в on_start
74
+ @telegram_router_1.router.callback_query(F.data == "catalog")
75
+ async def handle_catalog(callback: CallbackQuery, state: FSMContext):
76
+ """Обработка кнопки Каталог"""
77
+ await callback.answer()
78
+ await callback.message.answer("📖 Вот наш каталог товаров:\n\n1. Товар 1\n2. Товар 2\n3. Товар 3")
79
+
80
+ @telegram_router_1.router.callback_query(F.data == "prices")
81
+ async def handle_prices(callback: CallbackQuery, state: FSMContext):
82
+ """Обработка кнопки Цены"""
83
+ await callback.answer()
84
+ await callback.message.answer("💰 Наши цены:\n\n📦 Базовый - 1000₽\n📦 Премиум - 5000₽")
85
+
86
+ @telegram_router_1.router.callback_query(F.data == "contact")
87
+ async def handle_contact(callback: CallbackQuery, state: FSMContext):
88
+ """Обработка кнопки Связаться"""
89
+ await callback.answer()
90
+ await callback.message.answer("📞 Свяжитесь с нами:\n\nТелефон: +7 (999) 123-45-67\nEmail: info@example.com")
91
+
45
92
  # =============================================================================
46
93
  # ОБРАБОТЧИКИ СОБЫТИЙ (бизнес-логика)
47
94
  # =============================================================================
@@ -97,8 +144,7 @@ async def send_global_announcement(announcement_text: str):
97
144
  async def main():
98
145
  """Основная функция запуска бота"""
99
146
  try:
100
- # Создаем и собираем бота
101
- bot_builder = BotBuilder("best-valera")
147
+ # bot_builder уже создан выше (для декоратора @bot_builder.on_start)
102
148
 
103
149
  # Регистрируем роутеры ПЕРЕД сборкой (можно по одному или несколько сразу)
104
150
  bot_builder.register_routers(event_router) # Роутеры событий
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "smart-bot-factory"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  description = "Библиотека для создания умных чат-ботов"
5
5
  authors = [
6
6
  {name = "Kopatych", email = "kopatych@example.com"}
@@ -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, "Произошла ошибка при инициализации. Попробуйте позже.")
@@ -1259,7 +1259,7 @@ wheels = [
1259
1259
 
1260
1260
  [[package]]
1261
1261
  name = "smart-bot-factory"
1262
- version = "0.1.9"
1262
+ version = "0.2.0"
1263
1263
  source = { editable = "." }
1264
1264
  dependencies = [
1265
1265
  { name = "aiofiles" },