chatgraph 0.3.15__tar.gz → 0.4.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 chatgraph might be problematic. Click here for more details.
- {chatgraph-0.3.15 → chatgraph-0.4.1}/PKG-INFO +3 -1
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/bot/chatbot_model.py +5 -18
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/bot/chatbot_router.py +16 -20
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/messages/message_consumer.py +1 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/types/request_types.py +23 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/types/route.py +14 -7
- {chatgraph-0.3.15 → chatgraph-0.4.1}/pyproject.toml +3 -1
- {chatgraph-0.3.15 → chatgraph-0.4.1}/LICENSE +0 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/README.md +0 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/__init__.py +0 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/auth/credentials.py +0 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/cli/__init__.py +0 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/error/chatbot_error.py +0 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/error/route_error.py +0 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/gRPC/gRPCCall.py +0 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/pb/userstate.proto +0 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/pb/userstate_pb2.py +0 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/pb/userstate_pb2_grpc.py +0 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/pb/voll.proto +0 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/pb/voll_pb2.py +0 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/pb/voll_pb2_grpc.py +0 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/types/end_types.py +0 -0
- {chatgraph-0.3.15 → chatgraph-0.4.1}/chatgraph/types/message_types.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: chatgraph
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: A user-friendly chatbot library
|
|
5
5
|
Home-page: https://github.com/irissonnlima/chatgraph
|
|
6
6
|
License: MIT
|
|
@@ -13,6 +13,8 @@ Classifier: Programming Language :: Python :: 3
|
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
14
|
Requires-Dist: grpcio (>=1.67.0,<2.0.0)
|
|
15
15
|
Requires-Dist: grpcio-tools (>=1.67.0,<2.0.0)
|
|
16
|
+
Requires-Dist: matplotlib (>=3.10.0,<4.0.0)
|
|
17
|
+
Requires-Dist: networkx (>=3.4.2,<4.0.0)
|
|
16
18
|
Requires-Dist: pika (>=1.3.2,<2.0.0)
|
|
17
19
|
Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
|
|
18
20
|
Requires-Dist: rich (>=13.8.1,<14.0.0)
|
|
@@ -31,7 +31,7 @@ class ChatbotApp:
|
|
|
31
31
|
self.__message_consumer = message_consumer
|
|
32
32
|
self.__routes = {}
|
|
33
33
|
|
|
34
|
-
def include_router(self, router: ChatbotRouter
|
|
34
|
+
def include_router(self, router: ChatbotRouter):
|
|
35
35
|
"""
|
|
36
36
|
Inclui um roteador de chatbot com um prefixo nas rotas da aplicação.
|
|
37
37
|
|
|
@@ -42,18 +42,7 @@ class ChatbotApp:
|
|
|
42
42
|
Raises:
|
|
43
43
|
ChatbotError: Se a rota 'start' não for encontrada no roteador.
|
|
44
44
|
"""
|
|
45
|
-
|
|
46
|
-
raise ChatbotError('Erro ao incluir rota, start não encontrado!')
|
|
47
|
-
|
|
48
|
-
prefixed_routes = {
|
|
49
|
-
(
|
|
50
|
-
f'start{prefix.lower()}'
|
|
51
|
-
if key.lower() == 'start'
|
|
52
|
-
else f'start{prefix.lower()}{key.lower().replace("start", "")}'
|
|
53
|
-
): value
|
|
54
|
-
for key, value in router.routes.items()
|
|
55
|
-
}
|
|
56
|
-
self.__routes.update(prefixed_routes)
|
|
45
|
+
self.__routes.update(router.routes)
|
|
57
46
|
|
|
58
47
|
def route(self, route_name: str):
|
|
59
48
|
"""
|
|
@@ -67,9 +56,6 @@ class ChatbotApp:
|
|
|
67
56
|
"""
|
|
68
57
|
route_name = route_name.strip().lower()
|
|
69
58
|
|
|
70
|
-
if 'start' not in route_name:
|
|
71
|
-
route_name = f'start{route_name}'
|
|
72
|
-
|
|
73
59
|
def decorator(func):
|
|
74
60
|
params = dict()
|
|
75
61
|
signature = inspect.signature(func)
|
|
@@ -121,9 +107,10 @@ class ChatbotApp:
|
|
|
121
107
|
"""
|
|
122
108
|
customer_id = userCall.customer_id
|
|
123
109
|
route = userCall.route.lower()
|
|
110
|
+
route_handler = route.split('.')[-1]
|
|
124
111
|
menu = userCall.menu.lower()
|
|
125
112
|
obs = userCall.obs
|
|
126
|
-
handler = self.__routes.get(
|
|
113
|
+
handler = self.__routes.get(route_handler, None)
|
|
127
114
|
|
|
128
115
|
if not handler:
|
|
129
116
|
raise ChatbotMessageError(
|
|
@@ -172,7 +159,7 @@ class ChatbotApp:
|
|
|
172
159
|
return
|
|
173
160
|
|
|
174
161
|
elif isinstance(userCall_response, RedirectResponse):
|
|
175
|
-
route =
|
|
162
|
+
route = route + '.' + userCall_response.route
|
|
176
163
|
userCall.route = route
|
|
177
164
|
return self.process_message(userCall)
|
|
178
165
|
|
|
@@ -18,7 +18,17 @@ class ChatbotRouter:
|
|
|
18
18
|
"""
|
|
19
19
|
Inicializa a classe ChatbotRouter com um dicionário vazio de rotas.
|
|
20
20
|
"""
|
|
21
|
-
self.
|
|
21
|
+
self.__routes = {}
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def routes(self):
|
|
25
|
+
"""
|
|
26
|
+
Retorna as rotas registradas no roteador.
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
dict: Um dicionário contendo as rotas e funções associadas.
|
|
30
|
+
"""
|
|
31
|
+
return self.__routes
|
|
22
32
|
|
|
23
33
|
def route(self, route_name: str):
|
|
24
34
|
"""
|
|
@@ -30,15 +40,14 @@ class ChatbotRouter:
|
|
|
30
40
|
Returns:
|
|
31
41
|
function: O decorador que adiciona a função à rota especificada.
|
|
32
42
|
"""
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
|
|
44
|
+
route_name = route_name.strip().lower()
|
|
35
45
|
|
|
36
46
|
def decorator(func):
|
|
37
47
|
params = dict()
|
|
38
48
|
signature = inspect.signature(func)
|
|
39
49
|
output_param = signature.return_annotation
|
|
40
50
|
|
|
41
|
-
# Itera sobre os parâmetros da função e extrai seus tipos
|
|
42
51
|
for name, param in signature.parameters.items():
|
|
43
52
|
param_type = (
|
|
44
53
|
param.annotation
|
|
@@ -48,8 +57,7 @@ class ChatbotRouter:
|
|
|
48
57
|
params[param_type] = name
|
|
49
58
|
debug(f'Parameter: {name}, Type: {param_type}')
|
|
50
59
|
|
|
51
|
-
|
|
52
|
-
self.routes[route_name.strip().lower()] = {
|
|
60
|
+
self.__routes[route_name] = {
|
|
53
61
|
'function': func,
|
|
54
62
|
'params': params,
|
|
55
63
|
'return': output_param,
|
|
@@ -63,7 +71,7 @@ class ChatbotRouter:
|
|
|
63
71
|
|
|
64
72
|
return decorator
|
|
65
73
|
|
|
66
|
-
def include_router(self, router: 'ChatbotRouter'
|
|
74
|
+
def include_router(self, router: 'ChatbotRouter'):
|
|
67
75
|
"""
|
|
68
76
|
Inclui outro roteador com um prefixo nas rotas do roteador atual.
|
|
69
77
|
|
|
@@ -74,16 +82,4 @@ class ChatbotRouter:
|
|
|
74
82
|
Raises:
|
|
75
83
|
ChatbotError: Se a rota 'start' não for encontrada no roteador fornecido.
|
|
76
84
|
"""
|
|
77
|
-
|
|
78
|
-
raise ChatbotError('Erro ao incluir rota, start não encontrado!')
|
|
79
|
-
|
|
80
|
-
# Adiciona prefixo às rotas do roteador incluído
|
|
81
|
-
prefixed_routes = {
|
|
82
|
-
(
|
|
83
|
-
f'{prefix.lower()}'
|
|
84
|
-
if key.lower() == 'start'
|
|
85
|
-
else f'start{prefix.lower()}{key.lower().replace("start", "")}'
|
|
86
|
-
): value
|
|
87
|
-
for key, value in router.routes.items()
|
|
88
|
-
}
|
|
89
|
-
self.routes.update(prefixed_routes)
|
|
85
|
+
self.__routes.update(router.__routes)
|
|
@@ -178,6 +178,7 @@ class MessageConsumer:
|
|
|
178
178
|
voll_id=user_state.get('voll_id', ''),
|
|
179
179
|
platform=user_state.get('platform', ''),
|
|
180
180
|
obs=obs,
|
|
181
|
+
protocol=user_state.get('protocol', ''),
|
|
181
182
|
),
|
|
182
183
|
channel=message.get('channel', ''),
|
|
183
184
|
customer_phone=message.get('customer_phone', ''),
|
|
@@ -26,6 +26,7 @@ class UserState:
|
|
|
26
26
|
voll_id: Optional[str]=None,
|
|
27
27
|
lst_update: Optional[str]=None,
|
|
28
28
|
obs: Optional[dict] = None,
|
|
29
|
+
protocol: Optional[str] = None,
|
|
29
30
|
) -> None:
|
|
30
31
|
|
|
31
32
|
self.customer_id = customer_id
|
|
@@ -36,6 +37,7 @@ class UserState:
|
|
|
36
37
|
self.direction_in = direction_in
|
|
37
38
|
self.voll_id = voll_id
|
|
38
39
|
self.platform = platform
|
|
40
|
+
self.protocol = protocol
|
|
39
41
|
|
|
40
42
|
def __str__(self):
|
|
41
43
|
return f"UserState:\n\tcustomer_id={self.customer_id},\n\tmenu={self.menu},\n\troute={self.route},\n\tlst_update={self.lst_update},\n\tobs={self.obs},\n\tdirection_in={self.direction_in}"
|
|
@@ -53,6 +55,7 @@ class UserState:
|
|
|
53
55
|
'direction': self.direction_in,
|
|
54
56
|
'voll_id': self.voll_id,
|
|
55
57
|
'platform': self.platform,
|
|
58
|
+
'protocol': self.protocol,
|
|
56
59
|
})
|
|
57
60
|
|
|
58
61
|
def update(self, grpc_uri: Optional[str] = None) -> None:
|
|
@@ -318,6 +321,26 @@ class UserCall:
|
|
|
318
321
|
def customer_id(self):
|
|
319
322
|
return self.__user_state.customer_id
|
|
320
323
|
|
|
324
|
+
@property
|
|
325
|
+
def voll_id(self):
|
|
326
|
+
return self.__user_state.voll_id
|
|
327
|
+
|
|
328
|
+
@property
|
|
329
|
+
def platform(self):
|
|
330
|
+
return self.__user_state.platform
|
|
331
|
+
|
|
332
|
+
@property
|
|
333
|
+
def direction_in(self):
|
|
334
|
+
return self.__user_state.direction_in
|
|
335
|
+
|
|
336
|
+
@property
|
|
337
|
+
def lst_update(self):
|
|
338
|
+
return self.__user_state.lst_update
|
|
339
|
+
|
|
340
|
+
@property
|
|
341
|
+
def protocol(self):
|
|
342
|
+
return self.__user_state.protocol
|
|
343
|
+
|
|
321
344
|
@menu.setter
|
|
322
345
|
def menu(self, menu):
|
|
323
346
|
|
|
@@ -24,13 +24,20 @@ class Route:
|
|
|
24
24
|
self.separator = separator
|
|
25
25
|
|
|
26
26
|
@property
|
|
27
|
-
def previous(self)->
|
|
27
|
+
def previous(self)->'Route':
|
|
28
28
|
"""
|
|
29
29
|
Retorna a rota anterior a atual do usuário
|
|
30
30
|
"""
|
|
31
31
|
return self.get_previous()
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
@property
|
|
34
|
+
def current_node(self)->str:
|
|
35
|
+
"""
|
|
36
|
+
Retorna o nó atual do usuário
|
|
37
|
+
"""
|
|
38
|
+
return self.current.split(self.separator)[-1]
|
|
39
|
+
|
|
40
|
+
def get_previous(self) -> 'Route':
|
|
34
41
|
"""
|
|
35
42
|
Retorna o caminho anterior ao caminho atual.
|
|
36
43
|
|
|
@@ -41,10 +48,10 @@ class Route:
|
|
|
41
48
|
str: O caminho anterior à rota atual.
|
|
42
49
|
"""
|
|
43
50
|
if self.current == 'start':
|
|
44
|
-
|
|
51
|
+
return Route(self.current, self.routes, self.separator)
|
|
45
52
|
|
|
46
53
|
previous_route = self.separator.join(self.current.split(self.separator)[:-1])
|
|
47
|
-
return previous_route
|
|
54
|
+
return Route(previous_route, self.routes, self.separator)
|
|
48
55
|
|
|
49
56
|
def get_next(self, next_part: str) -> 'Route':
|
|
50
57
|
"""
|
|
@@ -60,9 +67,9 @@ class Route:
|
|
|
60
67
|
Route: O próximo caminho montado.
|
|
61
68
|
"""
|
|
62
69
|
next_part = next_part.strip().lower()
|
|
63
|
-
next_route = f"{self.current.rstrip(self.separator)}{next_part}"
|
|
64
|
-
if
|
|
65
|
-
raise RouteError(f'Rota não encontrada: {
|
|
70
|
+
next_route = f"{self.current.rstrip(self.separator)}.{next_part}"
|
|
71
|
+
if next_part not in self.routes:
|
|
72
|
+
raise RouteError(f'Rota não encontrada: {next_part}')
|
|
66
73
|
|
|
67
74
|
return Route(next_route, self.routes, self.separator)
|
|
68
75
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "chatgraph"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.4.1"
|
|
4
4
|
description = "A user-friendly chatbot library"
|
|
5
5
|
authors = ["Irisson N. Lima <irisson.lima@verdecard.com.br>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -17,6 +17,8 @@ grpcio = "^1.67.0"
|
|
|
17
17
|
grpcio-tools = "^1.67.0"
|
|
18
18
|
python-dotenv = "^1.0.1"
|
|
19
19
|
typer = "^0.12.5"
|
|
20
|
+
matplotlib = "^3.10.0"
|
|
21
|
+
networkx = "^3.4.2"
|
|
20
22
|
|
|
21
23
|
[tool.poetry.group.dev.dependencies]
|
|
22
24
|
ruff = "^0.5.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|