smart-bot-factory 0.2.8__py3-none-any.whl → 0.2.10__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.
- smart_bot_factory/core/bot_utils.py +11 -0
- smart_bot_factory/creation/bot_builder.py +43 -0
- smart_bot_factory/message/__init__.py +42 -0
- {smart_bot_factory-0.2.8.dist-info → smart_bot_factory-0.2.10.dist-info}/METADATA +1 -1
- {smart_bot_factory-0.2.8.dist-info → smart_bot_factory-0.2.10.dist-info}/RECORD +8 -8
- {smart_bot_factory-0.2.8.dist-info → smart_bot_factory-0.2.10.dist-info}/WHEEL +0 -0
- {smart_bot_factory-0.2.8.dist-info → smart_bot_factory-0.2.10.dist-info}/entry_points.txt +0 -0
- {smart_bot_factory-0.2.8.dist-info → smart_bot_factory-0.2.10.dist-info}/licenses/LICENSE +0 -0
|
@@ -177,6 +177,17 @@ def parse_ai_response_method2(ai_response: str) -> tuple[str, dict]:
|
|
|
177
177
|
|
|
178
178
|
async def process_events(session_id: str, events: list, user_id: int):
|
|
179
179
|
"""Обрабатывает события из ответа ИИ"""
|
|
180
|
+
|
|
181
|
+
# Проверяем кастомный процессор
|
|
182
|
+
custom_processor = get_global_var('custom_event_processor')
|
|
183
|
+
|
|
184
|
+
if custom_processor:
|
|
185
|
+
# Используем кастомную функцию обработки событий
|
|
186
|
+
logger.info(f"🔄 Используется кастомная обработка событий: {custom_processor.__name__}")
|
|
187
|
+
await custom_processor(session_id, events, user_id)
|
|
188
|
+
return
|
|
189
|
+
|
|
190
|
+
# Стандартная обработка
|
|
180
191
|
supabase_client = get_global_var('supabase_client')
|
|
181
192
|
|
|
182
193
|
for event in events:
|
|
@@ -58,6 +58,9 @@ class BotBuilder:
|
|
|
58
58
|
# Кастомный PromptLoader
|
|
59
59
|
self._custom_prompt_loader = None
|
|
60
60
|
|
|
61
|
+
# Кастомный процессор событий
|
|
62
|
+
self._custom_event_processor = None
|
|
63
|
+
|
|
61
64
|
# Флаги инициализации
|
|
62
65
|
self._initialized = False
|
|
63
66
|
|
|
@@ -402,6 +405,44 @@ class BotBuilder:
|
|
|
402
405
|
self._custom_prompt_loader = prompt_loader
|
|
403
406
|
logger.info(f"✅ Установлен кастомный PromptLoader: {type(prompt_loader).__name__}")
|
|
404
407
|
|
|
408
|
+
def set_event_processor(self, custom_processor):
|
|
409
|
+
"""
|
|
410
|
+
Устанавливает кастомную функцию для обработки событий
|
|
411
|
+
|
|
412
|
+
Полностью заменяет стандартную process_events из bot_utils
|
|
413
|
+
|
|
414
|
+
Args:
|
|
415
|
+
custom_processor: async def(session_id: str, events: list, user_id: int)
|
|
416
|
+
|
|
417
|
+
Example:
|
|
418
|
+
from smart_bot_factory.message import get_bot
|
|
419
|
+
from smart_bot_factory.core.decorators import execute_event_handler
|
|
420
|
+
|
|
421
|
+
async def my_process_events(session_id, events, user_id):
|
|
422
|
+
'''Моя кастомная обработка событий'''
|
|
423
|
+
bot = get_bot()
|
|
424
|
+
|
|
425
|
+
for event in events:
|
|
426
|
+
event_type = event.get('тип')
|
|
427
|
+
event_info = event.get('инфо')
|
|
428
|
+
|
|
429
|
+
if event_type == 'запись':
|
|
430
|
+
# Кастомная логика для бронирования
|
|
431
|
+
telegram_user = await bot.get_chat(user_id)
|
|
432
|
+
name = telegram_user.first_name or 'Клиент'
|
|
433
|
+
# ... ваша обработка
|
|
434
|
+
else:
|
|
435
|
+
# Для остальных - стандартная обработка
|
|
436
|
+
await execute_event_handler(event_type, user_id, event_info)
|
|
437
|
+
|
|
438
|
+
bot_builder.set_event_processor(my_process_events)
|
|
439
|
+
"""
|
|
440
|
+
if not callable(custom_processor):
|
|
441
|
+
raise TypeError(f"Процессор должен быть callable, получен {type(custom_processor)}")
|
|
442
|
+
|
|
443
|
+
self._custom_event_processor = custom_processor
|
|
444
|
+
logger.info(f"✅ Установлена кастомная функция обработки событий: {custom_processor.__name__}")
|
|
445
|
+
|
|
405
446
|
# ========== ХУКИ ДЛЯ КАСТОМИЗАЦИИ ОБРАБОТКИ СООБЩЕНИЙ ==========
|
|
406
447
|
|
|
407
448
|
def validate_message(self, handler):
|
|
@@ -580,6 +621,7 @@ class BotBuilder:
|
|
|
580
621
|
handlers_module.conversation_manager = self.conversation_manager
|
|
581
622
|
handlers_module.start_handlers = self._start_handlers # Передаем обработчики on_start
|
|
582
623
|
handlers_module.message_hooks = self.get_message_hooks() # Передаем хуки для обработки сообщений
|
|
624
|
+
handlers_module.custom_event_processor = self._custom_event_processor # Передаем кастомный процессор событий
|
|
583
625
|
logger.info("✅ Глобальные переменные установлены в handlers")
|
|
584
626
|
except Exception as e:
|
|
585
627
|
logger.warning(f"⚠️ Не удалось установить глобальные переменные в handlers: {e}")
|
|
@@ -611,6 +653,7 @@ class BotBuilder:
|
|
|
611
653
|
bot_utils_module.admin_manager = self.admin_manager
|
|
612
654
|
bot_utils_module.analytics_manager = self.analytics_manager
|
|
613
655
|
bot_utils_module.conversation_manager = self.conversation_manager
|
|
656
|
+
bot_utils_module.custom_event_processor = self._custom_event_processor # Передаем кастомный процессор событий
|
|
614
657
|
logger.info("✅ Глобальные переменные установлены в bot_utils")
|
|
615
658
|
except Exception as e:
|
|
616
659
|
logger.warning(f"⚠️ Не удалось установить глобальные переменные в bot_utils: {e}")
|
|
@@ -10,9 +10,51 @@ from ..core.message_sender import (
|
|
|
10
10
|
send_message,
|
|
11
11
|
)
|
|
12
12
|
|
|
13
|
+
|
|
14
|
+
def get_bot():
|
|
15
|
+
"""
|
|
16
|
+
Получает aiogram Bot из глобального контекста
|
|
17
|
+
|
|
18
|
+
Доступен после вызова bot_builder.start()
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
Bot: aiogram Bot объект
|
|
22
|
+
|
|
23
|
+
Raises:
|
|
24
|
+
RuntimeError: Если bot еще не инициализирован
|
|
25
|
+
|
|
26
|
+
Example:
|
|
27
|
+
from smart_bot_factory.message import get_bot
|
|
28
|
+
|
|
29
|
+
@event_router.event_handler("booking")
|
|
30
|
+
async def handle_booking(user_id: int, event_data: str):
|
|
31
|
+
bot = get_bot()
|
|
32
|
+
|
|
33
|
+
# Получаем информацию о пользователе из Telegram
|
|
34
|
+
telegram_user = await bot.get_chat(user_id)
|
|
35
|
+
name = telegram_user.first_name or 'Клиент'
|
|
36
|
+
|
|
37
|
+
# Используем любые методы aiogram Bot
|
|
38
|
+
await bot.send_message(user_id, f"Привет, {name}!")
|
|
39
|
+
await bot.send_photo(user_id, photo=...)
|
|
40
|
+
"""
|
|
41
|
+
from ..handlers.handlers import get_global_var
|
|
42
|
+
|
|
43
|
+
bot = get_global_var('bot')
|
|
44
|
+
if not bot:
|
|
45
|
+
raise RuntimeError(
|
|
46
|
+
"Bot еще не инициализирован. "
|
|
47
|
+
"Убедитесь что bot_builder.start() уже вызван. "
|
|
48
|
+
"Функция get_bot() доступна только внутри обработчиков событий, "
|
|
49
|
+
"которые выполняются во время работы бота."
|
|
50
|
+
)
|
|
51
|
+
return bot
|
|
52
|
+
|
|
53
|
+
|
|
13
54
|
__all__ = [
|
|
14
55
|
'send_message_by_human',
|
|
15
56
|
'send_message_by_ai',
|
|
16
57
|
'send_message_to_users_by_stage',
|
|
17
58
|
'send_message', # Чистая отправка с файлами и кнопками
|
|
59
|
+
'get_bot', # Доступ к aiogram Bot
|
|
18
60
|
]
|
|
@@ -24,7 +24,7 @@ smart_bot_factory/configs/growthmed-october-24/tests/realistic_scenarios.yaml,sh
|
|
|
24
24
|
smart_bot_factory/configs/growthmed-october-24/tests/scenario_examples.yaml,sha256=bzDulOU4a2LyWlcHzlQU8GYhOky2WTfyizGfjX4ioMY,2436
|
|
25
25
|
smart_bot_factory/configs/growthmed-october-24/welcome_file/welcome_file_msg.txt,sha256=Db21Mm0r8SBWFdX9EeIF2FZtLQ2cvuwVlSRJd2KEYCg,922
|
|
26
26
|
smart_bot_factory/configs/growthmed-october-24/welcome_file/Чек лист по 152ФЗ и 323ФЗ для медицины.pdf,sha256=BiAiQHNnQXJPMsks9AeL6s0beEjRFkRMJLMlAn4WorA,5284954
|
|
27
|
-
smart_bot_factory/core/bot_utils.py,sha256=
|
|
27
|
+
smart_bot_factory/core/bot_utils.py,sha256=CIIEAsHFjOhdrXX6AG27F7xhQVd1xbeAHlYYaYbSN1Y,41610
|
|
28
28
|
smart_bot_factory/core/conversation_manager.py,sha256=eoHL7MCEz68DRvTVwRwZgf2PWwGv4T6J9D-I-thETi8,28289
|
|
29
29
|
smart_bot_factory/core/decorators.py,sha256=xQCtr5SOLqqmEzaxrDf_sfxWQouIG7riI6Sa_jqGlcg,68647
|
|
30
30
|
smart_bot_factory/core/message_sender.py,sha256=J4b6n8nXVjqf-qzL6URRSvc-FVnQfShwujVSM6qv26w,32232
|
|
@@ -33,13 +33,13 @@ 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=
|
|
36
|
+
smart_bot_factory/creation/bot_builder.py,sha256=CA91xUCPLAQ7k-ClyejfWI3PRXVJ8o9rHrhMrUF_W3w,37979
|
|
37
37
|
smart_bot_factory/creation/bot_testing.py,sha256=JDWXyJfZmbgo-DLdAPk8Sd9FiehtHHa4sLD17lBrTOc,55669
|
|
38
38
|
smart_bot_factory/event/__init__.py,sha256=hPL449RULIOB-OXv1ZbGNiHctAYaOMUqhSWGPrDHYBM,212
|
|
39
39
|
smart_bot_factory/handlers/handlers.py,sha256=tNtOjtdLUIXVh8mqjTD2kc2N_GiU69BYzxhcOJ2ozBI,41542
|
|
40
40
|
smart_bot_factory/integrations/openai_client.py,sha256=aMcDrKO0GEx3ZSVEOGDeDtFCDWSXs6biUfgrbRK8yTU,23180
|
|
41
41
|
smart_bot_factory/integrations/supabase_client.py,sha256=AfALLZdDYeMWHLJw6POTGiBd-sH3i03oT6tT7m9C28I,44644
|
|
42
|
-
smart_bot_factory/message/__init__.py,sha256
|
|
42
|
+
smart_bot_factory/message/__init__.py,sha256=-ehDZweUc3uKgmLLxFVsD-KWrDtnHpHms7pCrDelWo0,1950
|
|
43
43
|
smart_bot_factory/router/__init__.py,sha256=QrfO5u8H2uVzWGMtBvNKunsJAv7UrKtvt2f_D5xSFWE,270
|
|
44
44
|
smart_bot_factory/supabase/__init__.py,sha256=XmZP6yM9ffERM5ddAWyJnrNzEhCYtMu3AcjVCi1rOf8,179
|
|
45
45
|
smart_bot_factory/supabase/client.py,sha256=lWIzfOgoSvU7xPhYLoJtM5GnbWdoWsvHcRFC22sFBMU,25637
|
|
@@ -49,8 +49,8 @@ smart_bot_factory/utils/__init__.py,sha256=UhsJXEHfrIK8h1AHsroHSwAriijk-LvnqLyvg
|
|
|
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
51
|
smart_bot_factory/utils/user_prompt_loader.py,sha256=dk6P0X_3UcNqxjRtuIvb0LcPrp03zIIsstZwdmeCPaE,2519
|
|
52
|
-
smart_bot_factory-0.2.
|
|
53
|
-
smart_bot_factory-0.2.
|
|
54
|
-
smart_bot_factory-0.2.
|
|
55
|
-
smart_bot_factory-0.2.
|
|
56
|
-
smart_bot_factory-0.2.
|
|
52
|
+
smart_bot_factory-0.2.10.dist-info/METADATA,sha256=1VZJbgUK4dHMJuwA1gM4ktD4HmVC_raTVI7DfScODX0,28225
|
|
53
|
+
smart_bot_factory-0.2.10.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
54
|
+
smart_bot_factory-0.2.10.dist-info/entry_points.txt,sha256=ybKEAI0WSb7WoRiey7QE-HHfn88UGV7nxLDxXq7b7SU,50
|
|
55
|
+
smart_bot_factory-0.2.10.dist-info/licenses/LICENSE,sha256=OrK3cwdUTzNzIhJvSPtJaVMoYIyC_sSx5EFE_FDMvGs,1092
|
|
56
|
+
smart_bot_factory-0.2.10.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|