chatgraph 0.3.0__tar.gz → 0.3.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.0 → chatgraph-0.3.1}/PKG-INFO +1 -1
- chatgraph-0.3.1/chatgraph/bot/__pycache__/chatbot_model.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/bot/__pycache__/chatbot_router.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/bot/chatbot_model.py +46 -33
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/bot/chatbot_router.py +4 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/types/__pycache__/message_types.cpython-312.pyc +0 -0
- chatgraph-0.3.1/chatgraph/types/__pycache__/output_state.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/types/__pycache__/route.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/types/message_types.py +3 -1
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/types/output_state.py +12 -1
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/types/route.py +7 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/pyproject.toml +1 -1
- chatgraph-0.3.0/chatgraph/bot/__pycache__/chatbot_model.cpython-312.pyc +0 -0
- chatgraph-0.3.0/chatgraph/types/__pycache__/output_state.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/LICENSE +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/README.md +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/__init__.py +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/auth/__pycache__/credentials.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/auth/credentials.py +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/bot/__pycache__/chatbot_app.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/bot/__pycache__/user_state.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/error/__pycache__/chatbot_error.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/error/__pycache__/error_handler.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/error/__pycache__/route_error.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/error/chatbot_error.py +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/error/route_error.py +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/gRPC/__pycache__/gRPCCall.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/gRPC/gRPCCall.py +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/messages/__pycache__/__init__.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/messages/__pycache__/base_message_consumer.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/messages/__pycache__/message_consumer.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/messages/__pycache__/rabbitMQ_message_consumer.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/messages/__pycache__/test_message_consumer.cpython-312-pytest-8.3.2.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/messages/message_consumer.py +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/pb/__pycache__/userstate_pb2.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/pb/__pycache__/userstate_pb2_grpc.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/pb/__pycache__/voll_pb2.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/pb/__pycache__/voll_pb2_grpc.cpython-312.pyc +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/pb/userstate.proto +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/pb/userstate_pb2.py +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/pb/userstate_pb2_grpc.py +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/pb/voll.proto +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/pb/voll_pb2.py +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/pb/voll_pb2_grpc.py +0 -0
- {chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/types/__pycache__/user_state.cpython-312.pyc +0 -0
|
Binary file
|
{chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/bot/__pycache__/chatbot_router.cpython-312.pyc
RENAMED
|
Binary file
|
|
@@ -17,13 +17,16 @@ class ChatbotApp:
|
|
|
17
17
|
Classe principal para a aplicação do chatbot, gerencia as rotas e a lógica de processamento de mensagens.
|
|
18
18
|
"""
|
|
19
19
|
|
|
20
|
-
def __init__(self, message_consumer: MessageConsumer):
|
|
20
|
+
def __init__(self, message_consumer: MessageConsumer = None):
|
|
21
21
|
"""
|
|
22
22
|
Inicializa a classe ChatbotApp com um estado de usuário e um consumidor de mensagens.
|
|
23
23
|
|
|
24
24
|
Args:
|
|
25
25
|
message_consumer (MessageConsumer): O consumidor de mensagens que lida com a entrada de mensagens no sistema.
|
|
26
26
|
"""
|
|
27
|
+
if not message_consumer:
|
|
28
|
+
message_consumer = MessageConsumer.load_dotenv()
|
|
29
|
+
|
|
27
30
|
self.__message_consumer = message_consumer
|
|
28
31
|
self.__routes = {}
|
|
29
32
|
|
|
@@ -125,6 +128,7 @@ class ChatbotApp:
|
|
|
125
128
|
raise ChatbotMessageError(
|
|
126
129
|
customer_id, f'Rota não encontrada para {route}!'
|
|
127
130
|
)
|
|
131
|
+
|
|
128
132
|
func = handler['function']
|
|
129
133
|
userCall_name = handler['params'].get(UserCall, None)
|
|
130
134
|
route_state_name = handler['params'].get(Route, None)
|
|
@@ -137,41 +141,24 @@ class ChatbotApp:
|
|
|
137
141
|
|
|
138
142
|
userCall_response = func(**kwargs)
|
|
139
143
|
|
|
140
|
-
if
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
'customer_id': customer_id,
|
|
145
|
-
'route': route,
|
|
146
|
-
'menu': menu,
|
|
147
|
-
'obs': obs,
|
|
148
|
-
}
|
|
149
|
-
return json.dumps(response)
|
|
150
|
-
elif type(userCall_response) == ChatbotResponse:
|
|
144
|
+
if isinstance(userCall_response, (str, float, int)):
|
|
145
|
+
return self.__create_response(userCall_response, customer_id, route, menu, obs)
|
|
146
|
+
|
|
147
|
+
elif isinstance(userCall_response, ChatbotResponse):
|
|
151
148
|
adjusted_route = self.__adjust_route(userCall_response.route, route)
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
return json.dumps(response)
|
|
160
|
-
elif type(userCall_response) in (EndChatResponse, TransferToHuman):
|
|
161
|
-
response = userCall_response.json()
|
|
162
|
-
response['user_state'] = {
|
|
163
|
-
'customer_id': customer_id,
|
|
164
|
-
'menu': None,
|
|
165
|
-
'route': None,
|
|
166
|
-
'obs': None,
|
|
167
|
-
}
|
|
168
|
-
return json.dumps(response)
|
|
169
|
-
|
|
170
|
-
elif type(userCall_response) == RedirectResponse:
|
|
149
|
+
return self.__create_response(userCall_response.json(), customer_id, adjusted_route, menu, obs)
|
|
150
|
+
|
|
151
|
+
elif isinstance(userCall_response, (EndChatResponse, TransferToHuman)):
|
|
152
|
+
return self.__end_chat_response(userCall_response, customer_id)
|
|
153
|
+
|
|
154
|
+
elif isinstance(userCall_response, RedirectResponse):
|
|
171
155
|
route = self.__adjust_route(userCall_response.route, route)
|
|
172
156
|
userCall.route = route
|
|
173
157
|
return self.process_message(userCall)
|
|
174
|
-
|
|
158
|
+
|
|
159
|
+
elif not userCall_response:
|
|
160
|
+
return self.__create_response('', customer_id, None, None, None)
|
|
161
|
+
|
|
175
162
|
else:
|
|
176
163
|
error('Tipo de retorno inválido!')
|
|
177
164
|
return None
|
|
@@ -194,4 +181,30 @@ class ChatbotApp:
|
|
|
194
181
|
if 'start' not in route:
|
|
195
182
|
route = absolute_route + route
|
|
196
183
|
|
|
197
|
-
return route
|
|
184
|
+
return route
|
|
185
|
+
|
|
186
|
+
def __create_response(self, response, customer_id, route, menu, obs):
|
|
187
|
+
"""
|
|
188
|
+
Cria uma resposta padronizada em formato JSON com o estado do usuário.
|
|
189
|
+
"""
|
|
190
|
+
response = ChatbotResponse(response).json() if not isinstance(response, dict) else response
|
|
191
|
+
response['user_state'] = {
|
|
192
|
+
'customer_id': customer_id,
|
|
193
|
+
'route': route,
|
|
194
|
+
'menu': menu,
|
|
195
|
+
'obs': obs,
|
|
196
|
+
}
|
|
197
|
+
return json.dumps(response)
|
|
198
|
+
|
|
199
|
+
def __end_chat_response(self, response, customer_id):
|
|
200
|
+
"""
|
|
201
|
+
Gera a resposta de finalização ou transferência de chat.
|
|
202
|
+
"""
|
|
203
|
+
response = response.json()
|
|
204
|
+
response['user_state'] = {
|
|
205
|
+
'customer_id': customer_id,
|
|
206
|
+
'menu': None,
|
|
207
|
+
'route': None,
|
|
208
|
+
'obs': None,
|
|
209
|
+
}
|
|
210
|
+
return json.dumps(response)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
import inspect
|
|
2
3
|
from functools import wraps
|
|
3
4
|
from logging import debug
|
|
@@ -37,6 +38,7 @@ class ChatbotRouter:
|
|
|
37
38
|
signature = inspect.signature(func)
|
|
38
39
|
output_param = signature.return_annotation
|
|
39
40
|
|
|
41
|
+
# Itera sobre os parâmetros da função e extrai seus tipos
|
|
40
42
|
for name, param in signature.parameters.items():
|
|
41
43
|
param_type = (
|
|
42
44
|
param.annotation
|
|
@@ -46,6 +48,7 @@ class ChatbotRouter:
|
|
|
46
48
|
params[param_type] = name
|
|
47
49
|
debug(f'Parameter: {name}, Type: {param_type}')
|
|
48
50
|
|
|
51
|
+
# Adiciona a função e seus parâmetros à rota especificada
|
|
49
52
|
self.routes[route_name.strip().lower()] = {
|
|
50
53
|
'function': func,
|
|
51
54
|
'params': params,
|
|
@@ -74,6 +77,7 @@ class ChatbotRouter:
|
|
|
74
77
|
if 'start' not in router.routes.keys():
|
|
75
78
|
raise ChatbotError('Erro ao incluir rota, start não encontrado!')
|
|
76
79
|
|
|
80
|
+
# Adiciona prefixo às rotas do roteador incluído
|
|
77
81
|
prefixed_routes = {
|
|
78
82
|
(
|
|
79
83
|
f'{prefix.lower()}'
|
{chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/types/__pycache__/message_types.cpython-312.pyc
RENAMED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -72,7 +72,9 @@ class UserCall:
|
|
|
72
72
|
self.__wpp_server_client = WhatsappServiceClient(self.grpc_uri)
|
|
73
73
|
self.__user_state_client = UserStateServiceClient(self.grpc_uri)
|
|
74
74
|
|
|
75
|
-
def send_text(self, text:str) -> None:
|
|
75
|
+
def send_text(self, text:str, abs_text:bool=False) -> None:
|
|
76
|
+
if not abs_text:
|
|
77
|
+
text = text.replace('\t', '')
|
|
76
78
|
|
|
77
79
|
response = self.__wpp_server_client.send_text(
|
|
78
80
|
{
|
|
@@ -13,7 +13,12 @@ class ChatbotResponse:
|
|
|
13
13
|
route (str, opcional): A rota para a qual o chatbot deve direcionar após esta mensagem. Padrão é None.
|
|
14
14
|
"""
|
|
15
15
|
|
|
16
|
-
def __init__(
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
message: messageTypes = None,
|
|
19
|
+
route: str = None,
|
|
20
|
+
abs_text:bool=False
|
|
21
|
+
) -> None:
|
|
17
22
|
"""
|
|
18
23
|
Inicializa a resposta do chatbot com uma mensagem e uma rota opcional.
|
|
19
24
|
|
|
@@ -21,6 +26,12 @@ class ChatbotResponse:
|
|
|
21
26
|
message (messageTypes, opcional): A mensagem a ser enviada ao usuário. Pode ser uma string, um número, ou None.
|
|
22
27
|
route (str, opcional): A rota para a qual o chatbot deve direcionar após esta mensagem. Padrão é None.
|
|
23
28
|
"""
|
|
29
|
+
if not message:
|
|
30
|
+
message = ''
|
|
31
|
+
|
|
32
|
+
if not abs_text:
|
|
33
|
+
message = message.replace('\t', '')
|
|
34
|
+
|
|
24
35
|
self.message = message
|
|
25
36
|
self.route = route
|
|
26
37
|
|
|
@@ -23,6 +23,13 @@ class Route:
|
|
|
23
23
|
self.routes = routes
|
|
24
24
|
self.separator = separator
|
|
25
25
|
|
|
26
|
+
@property
|
|
27
|
+
def previous(self)->str:
|
|
28
|
+
"""
|
|
29
|
+
Retorna a rota anterior a atual do usuário
|
|
30
|
+
"""
|
|
31
|
+
return self.get_previous()
|
|
32
|
+
|
|
26
33
|
def get_previous(self) -> str:
|
|
27
34
|
"""
|
|
28
35
|
Retorna o caminho anterior ao caminho atual.
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/error/__pycache__/chatbot_error.cpython-312.pyc
RENAMED
|
File without changes
|
{chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/error/__pycache__/error_handler.cpython-312.pyc
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/messages/__pycache__/message_consumer.cpython-312.pyc
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{chatgraph-0.3.0 → chatgraph-0.3.1}/chatgraph/pb/__pycache__/userstate_pb2_grpc.cpython-312.pyc
RENAMED
|
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
|