multibotkit 0.1.34__tar.gz → 0.2.0__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.
- {multibotkit-0.1.34 → multibotkit-0.2.0}/PKG-INFO +21 -4
- multibotkit-0.2.0/multibotkit/dispatchers/yandexmessenger.py +87 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/helpers/fb.py +4 -4
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/helpers/telegram.py +84 -83
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/helpers/viber.py +4 -4
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/helpers/vk.py +2 -2
- multibotkit-0.2.0/multibotkit/helpers/yandexmessenger.py +408 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/schemas/telegram/incoming.py +13 -17
- multibotkit-0.2.0/multibotkit/schemas/yandexmessenger/incoming.py +77 -0
- multibotkit-0.2.0/multibotkit/schemas/yandexmessenger/outgoing.py +126 -0
- multibotkit-0.2.0/multibotkit/states/managers/__init__.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit.egg-info/PKG-INFO +21 -4
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit.egg-info/SOURCES.txt +5 -0
- multibotkit-0.2.0/multibotkit.egg-info/requires.txt +10 -0
- multibotkit-0.2.0/pyproject.toml +5 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/setup.py +9 -7
- multibotkit-0.1.34/multibotkit.egg-info/requires.txt +0 -10
- multibotkit-0.1.34/pyproject.toml +0 -3
- {multibotkit-0.1.34 → multibotkit-0.2.0}/LICENSE +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/README.md +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/__init__.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/dispatchers/__init__.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/dispatchers/base_dispatcher.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/dispatchers/fb.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/dispatchers/telegram.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/dispatchers/viber.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/dispatchers/vk.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/helpers/__init__.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/helpers/base_helper.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/schemas/__init__.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/schemas/fb/__init__.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/schemas/fb/incoming.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/schemas/fb/outgoing.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/schemas/telegram/__init__.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/schemas/telegram/outgoing.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/schemas/viber/__init__.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/schemas/viber/incoming.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/schemas/viber/outgoing.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/schemas/vk/__init__.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/schemas/vk/incoming.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/schemas/vk/outgoing.py +0 -0
- {multibotkit-0.1.34/multibotkit/states → multibotkit-0.2.0/multibotkit/schemas/yandexmessenger}/__init__.py +0 -0
- {multibotkit-0.1.34/multibotkit/states/managers → multibotkit-0.2.0/multibotkit/states}/__init__.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/states/managers/base.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/states/managers/memory.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/states/managers/mongo.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/states/managers/redis.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit/states/state.py +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit.egg-info/dependency_links.txt +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/multibotkit.egg-info/top_level.txt +0 -0
- {multibotkit-0.1.34 → multibotkit-0.2.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: multibotkit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Functional library for developing multiplatform chatbots
|
|
5
5
|
Home-page: https://github.com/Appvelox/multibotkit
|
|
6
6
|
Author: Appvelox LLC
|
|
@@ -9,11 +9,28 @@ Classifier: Intended Audience :: Developers
|
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
10
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
11
|
Classifier: Operating System :: OS Independent
|
|
12
|
-
Requires-Python: >=3.
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: httpx>=0.28.1
|
|
16
|
+
Requires-Dist: pydantic<3
|
|
17
|
+
Requires-Dist: tenacity>=9.1.2
|
|
18
|
+
Requires-Dist: aiofiles>=22.1.0
|
|
14
19
|
Provides-Extra: mongo
|
|
20
|
+
Requires-Dist: motor>=3.7.0; extra == "mongo"
|
|
15
21
|
Provides-Extra: redis
|
|
16
|
-
|
|
22
|
+
Requires-Dist: redis>=7.1.0; extra == "redis"
|
|
23
|
+
Dynamic: author
|
|
24
|
+
Dynamic: author-email
|
|
25
|
+
Dynamic: classifier
|
|
26
|
+
Dynamic: description
|
|
27
|
+
Dynamic: description-content-type
|
|
28
|
+
Dynamic: home-page
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
Dynamic: provides-extra
|
|
31
|
+
Dynamic: requires-dist
|
|
32
|
+
Dynamic: requires-python
|
|
33
|
+
Dynamic: summary
|
|
17
34
|
|
|
18
35
|
# multibotkit
|
|
19
36
|
Functional library for developing multiplatform chatbots
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
|
|
4
|
+
from multibotkit.dispatchers.base_dispatcher import BaseDispatcher
|
|
5
|
+
from multibotkit.schemas.yandexmessenger.incoming import Update
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class YandexMessengerDispatcher(BaseDispatcher):
|
|
9
|
+
"""
|
|
10
|
+
Dispatcher для обработки событий Yandex Messenger.
|
|
11
|
+
|
|
12
|
+
Логика работы:
|
|
13
|
+
1. Получает Update событие
|
|
14
|
+
2. Определяет sender_id (из login или id)
|
|
15
|
+
3. Загружает/создает state объект для пользователя
|
|
16
|
+
4. Проходит по зарегистрированным handlers
|
|
17
|
+
5. Выполняет handler если условия (func + state_object_func) выполнены
|
|
18
|
+
6. Логирует событие если logger настроен
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
async def process_event(self, event: Update):
|
|
22
|
+
"""
|
|
23
|
+
Обработка входящего события Update.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
event: Update объект с входящим сообщением
|
|
27
|
+
"""
|
|
28
|
+
# 1. Определение sender_id
|
|
29
|
+
sender = event.from_
|
|
30
|
+
if sender.login:
|
|
31
|
+
sender_id = sender.login
|
|
32
|
+
elif sender.id:
|
|
33
|
+
sender_id = sender.id
|
|
34
|
+
else:
|
|
35
|
+
sender_id = "unknown" # fallback
|
|
36
|
+
|
|
37
|
+
# 2. Формирование state_id
|
|
38
|
+
# ВАЖНО: использовать "yandexmessenger" (одно слово)
|
|
39
|
+
# чтобы state.id = state_id.split("_")[1] работало корректно
|
|
40
|
+
state_id = f"yandexmessenger_{sender_id}"
|
|
41
|
+
state_object = await self.state_manager.get_state(state_id)
|
|
42
|
+
|
|
43
|
+
# 3. Обработка handlers
|
|
44
|
+
for (func, state_func, handler) in self._handlers:
|
|
45
|
+
state_func_result = True
|
|
46
|
+
if state_func is not None:
|
|
47
|
+
try:
|
|
48
|
+
if inspect.iscoroutinefunction(state_func):
|
|
49
|
+
state_func_result = await state_func(state_object)
|
|
50
|
+
else:
|
|
51
|
+
state_func_result = state_func(state_object)
|
|
52
|
+
except Exception:
|
|
53
|
+
continue
|
|
54
|
+
|
|
55
|
+
func_result = True
|
|
56
|
+
if func is not None:
|
|
57
|
+
try:
|
|
58
|
+
if inspect.iscoroutinefunction(func):
|
|
59
|
+
func_result = await func(event)
|
|
60
|
+
else:
|
|
61
|
+
func_result = func(event)
|
|
62
|
+
except Exception:
|
|
63
|
+
continue
|
|
64
|
+
|
|
65
|
+
summary_result = state_func_result * func_result
|
|
66
|
+
|
|
67
|
+
if summary_result:
|
|
68
|
+
await handler(event, state_object)
|
|
69
|
+
|
|
70
|
+
# 4. Логирование
|
|
71
|
+
if self.logger:
|
|
72
|
+
new_state_object = await self.state_manager.get_state(state_id)
|
|
73
|
+
event_log = {
|
|
74
|
+
"created_at": datetime.now(),
|
|
75
|
+
"user_id": state_object.id,
|
|
76
|
+
"platform": "YandexMessenger",
|
|
77
|
+
"old_state": state_object.state,
|
|
78
|
+
"old_state_data": state_object.data,
|
|
79
|
+
"new_state": new_state_object.state,
|
|
80
|
+
"new_state_data": new_state_object.data,
|
|
81
|
+
"event": event.dict(),
|
|
82
|
+
}
|
|
83
|
+
if callable(self.logger):
|
|
84
|
+
await self.logger(event_log)
|
|
85
|
+
return
|
|
86
|
+
self.logger.info(f"Incoming YandexMessenger event: {event_log}")
|
|
87
|
+
return
|
|
@@ -62,7 +62,7 @@ a list of quick replies"
|
|
|
62
62
|
quick_replies=quick_replies,
|
|
63
63
|
)
|
|
64
64
|
|
|
65
|
-
data = message.
|
|
65
|
+
data = message.model_dump_json(exclude_none=True)
|
|
66
66
|
r = self._perform_sync_request(url=self.MESSAGES_URL, data=data)
|
|
67
67
|
return r
|
|
68
68
|
|
|
@@ -88,7 +88,7 @@ a list of quick replies"
|
|
|
88
88
|
quick_replies=quick_replies,
|
|
89
89
|
)
|
|
90
90
|
|
|
91
|
-
data = message.
|
|
91
|
+
data = message.model_dump_json(exclude_none=True)
|
|
92
92
|
r = await self._perform_async_request(url=self.MESSAGES_URL, data=data)
|
|
93
93
|
return r
|
|
94
94
|
|
|
@@ -113,11 +113,11 @@ a list of quick replies"
|
|
|
113
113
|
return r
|
|
114
114
|
|
|
115
115
|
def sync_send_persistent_menu(self, persistent_menu: PersistentMenu):
|
|
116
|
-
data = persistent_menu.
|
|
116
|
+
data = persistent_menu.model_dump(exclude_none=True)
|
|
117
117
|
r = self._perform_sync_request(self.PROFILE_URL, data=data)
|
|
118
118
|
return r
|
|
119
119
|
|
|
120
120
|
async def async_send_persistent_menu(self, persistent_menu: PersistentMenu):
|
|
121
|
-
data = persistent_menu.
|
|
121
|
+
data = persistent_menu.model_dump(exclude_none=True)
|
|
122
122
|
r = await self._perform_async_request(self.PROFILE_URL, data=data)
|
|
123
123
|
return r
|