chatgraph 0.6.1__py3-none-any.whl → 0.6.2__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 chatgraph might be problematic. Click here for more details.
- chatgraph/bot/chatbot_model.py +32 -2
- chatgraph/bot/default_functions.py +24 -0
- chatgraph/gRPC/gRPCCall.py +46 -21
- chatgraph/types/end_types.py +17 -2
- chatgraph/types/request_types.py +24 -6
- chatgraph/types/route.py +17 -12
- {chatgraph-0.6.1.dist-info → chatgraph-0.6.2.dist-info}/METADATA +1 -1
- {chatgraph-0.6.1.dist-info → chatgraph-0.6.2.dist-info}/RECORD +11 -10
- {chatgraph-0.6.1.dist-info → chatgraph-0.6.2.dist-info}/LICENSE +0 -0
- {chatgraph-0.6.1.dist-info → chatgraph-0.6.2.dist-info}/WHEEL +0 -0
- {chatgraph-0.6.1.dist-info → chatgraph-0.6.2.dist-info}/entry_points.txt +0 -0
chatgraph/bot/chatbot_model.py
CHANGED
|
@@ -2,6 +2,7 @@ import inspect
|
|
|
2
2
|
from functools import wraps
|
|
3
3
|
from logging import debug, error
|
|
4
4
|
import asyncio
|
|
5
|
+
import re
|
|
5
6
|
|
|
6
7
|
from ..error.chatbot_error import ChatbotMessageError
|
|
7
8
|
from ..messages.message_consumer import MessageConsumer
|
|
@@ -16,6 +17,11 @@ from ..types.end_types import (
|
|
|
16
17
|
from ..types.route import Route
|
|
17
18
|
from .chatbot_router import ChatbotRouter
|
|
18
19
|
from ..types.background_task import BackgroundTask
|
|
20
|
+
from .default_functions import voltar
|
|
21
|
+
|
|
22
|
+
DEFAULT_FUNCTION: dict[str, callable] = {
|
|
23
|
+
r"^\s*(voltar)\s*$": voltar,
|
|
24
|
+
}
|
|
19
25
|
|
|
20
26
|
|
|
21
27
|
class ChatbotApp:
|
|
@@ -23,16 +29,22 @@ class ChatbotApp:
|
|
|
23
29
|
Classe principal para a aplicação do chatbot, gerencia as rotas e a lógica de processamento de mensagens.
|
|
24
30
|
"""
|
|
25
31
|
|
|
26
|
-
def __init__(
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
message_consumer: MessageConsumer = None,
|
|
35
|
+
default_functions: dict[str, callable] = DEFAULT_FUNCTION,
|
|
36
|
+
):
|
|
27
37
|
"""
|
|
28
38
|
Inicializa a classe ChatbotApp com um estado de usuário e um consumidor de mensagens.
|
|
29
39
|
|
|
30
40
|
Args:
|
|
31
41
|
message_consumer (MessageConsumer): O consumidor de mensagens que lida com a entrada de mensagens no sistema.
|
|
42
|
+
default_functions (dict[str, callable]): Dicionário de funções padrão que podem ser usadas antes das rotas.
|
|
32
43
|
"""
|
|
33
44
|
if not message_consumer:
|
|
34
45
|
message_consumer = MessageConsumer.load_dotenv()
|
|
35
46
|
|
|
47
|
+
self.default_functions = default_functions
|
|
36
48
|
self.__message_consumer = message_consumer
|
|
37
49
|
self.__routes = {}
|
|
38
50
|
|
|
@@ -106,7 +118,20 @@ class ChatbotApp:
|
|
|
106
118
|
route = userCall.route.lower()
|
|
107
119
|
route_handler = route.split(".")[-1]
|
|
108
120
|
|
|
109
|
-
|
|
121
|
+
matchDefault = False
|
|
122
|
+
|
|
123
|
+
for regex, func in self.default_functions.items():
|
|
124
|
+
if re.match(regex, userCall.content_message):
|
|
125
|
+
matchDefault = True
|
|
126
|
+
debug(f"Função padrão encontrada: {func.__name__} para a rota {route}")
|
|
127
|
+
handler = {
|
|
128
|
+
"function": func,
|
|
129
|
+
"params": {UserCall: "userCall", Route: "route"},
|
|
130
|
+
}
|
|
131
|
+
break
|
|
132
|
+
|
|
133
|
+
if not matchDefault:
|
|
134
|
+
handler = self.__routes.get(route_handler, None)
|
|
110
135
|
|
|
111
136
|
if not handler:
|
|
112
137
|
raise ChatbotMessageError(user_id, f"Rota não encontrada para {route}!")
|
|
@@ -127,6 +152,9 @@ class ChatbotApp:
|
|
|
127
152
|
loop = asyncio.get_running_loop()
|
|
128
153
|
userCall_response = await loop.run_in_executor(None, lambda: func(**kwargs))
|
|
129
154
|
|
|
155
|
+
if matchDefault:
|
|
156
|
+
userCall.content_message = ""
|
|
157
|
+
|
|
130
158
|
if isinstance(userCall_response, (list, tuple)):
|
|
131
159
|
for response in userCall_response:
|
|
132
160
|
await self.__process_func_response(response, userCall, route=route)
|
|
@@ -166,6 +194,7 @@ class ChatbotApp:
|
|
|
166
194
|
userCall.end_chat,
|
|
167
195
|
userCall_response.observations,
|
|
168
196
|
userCall_response.tabulation_id,
|
|
197
|
+
userCall_response.tabulation_name,
|
|
169
198
|
)
|
|
170
199
|
return
|
|
171
200
|
|
|
@@ -175,6 +204,7 @@ class ChatbotApp:
|
|
|
175
204
|
userCall.transfer_to_human,
|
|
176
205
|
userCall_response.observations,
|
|
177
206
|
userCall_response.campaign_id,
|
|
207
|
+
userCall_response.campaign_name,
|
|
178
208
|
)
|
|
179
209
|
return
|
|
180
210
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from ..types.request_types import UserCall
|
|
2
|
+
from ..types.message_types import Message, Button
|
|
3
|
+
from ..types.end_types import (
|
|
4
|
+
RedirectResponse,
|
|
5
|
+
EndChatResponse,
|
|
6
|
+
TransferToHuman,
|
|
7
|
+
TransferToMenu,
|
|
8
|
+
)
|
|
9
|
+
from ..types.route import Route
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
async def voltar(route: Route, userCall: UserCall) -> tuple:
|
|
13
|
+
"""
|
|
14
|
+
Função para voltar à rota anterior.
|
|
15
|
+
Args:
|
|
16
|
+
route (Route): A rota atual do chatbot.
|
|
17
|
+
usercall (UserCall): O objeto UserCall associado à chamada do usuário.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
previous = route.get_previous()
|
|
21
|
+
userCall.console.print(
|
|
22
|
+
f"Voltando rota. ({route.current}) -> ({previous.current})", style="bold yellow"
|
|
23
|
+
)
|
|
24
|
+
return RedirectResponse(previous.current_node)
|
chatgraph/gRPC/gRPCCall.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import grpc
|
|
3
3
|
import json
|
|
4
|
+
from rich.console import Console
|
|
4
5
|
|
|
5
6
|
import chatgraph.pb.router_pb2 as chatbot_pb2
|
|
6
7
|
import chatgraph.pb.router_pb2_grpc as chatbot_pb2_grpc
|
|
@@ -22,15 +23,22 @@ class RouterServiceClient:
|
|
|
22
23
|
self.transfer_stub = chatbot_pb2_grpc.TransferStub(self.channel)
|
|
23
24
|
self.end_chat_stub = chatbot_pb2_grpc.EndChatStub(self.channel)
|
|
24
25
|
|
|
26
|
+
self.console = Console()
|
|
27
|
+
|
|
25
28
|
def insert_update_user_state(self, user_state_data):
|
|
26
29
|
request = chatbot_pb2.UserState(**user_state_data)
|
|
27
30
|
try:
|
|
28
31
|
response = self.user_state_stub.InsertUpdateUserState(request)
|
|
29
32
|
if not response.status:
|
|
30
|
-
print(
|
|
33
|
+
self.console.print(
|
|
34
|
+
f"Erro ao chamar InsertUpdateUserState: {response.message}",
|
|
35
|
+
style="bold red",
|
|
36
|
+
)
|
|
31
37
|
return response
|
|
32
38
|
except grpc.RpcError as e:
|
|
33
|
-
print(
|
|
39
|
+
self.console.print(
|
|
40
|
+
f"Erro ao chamar InsertUpdateUserState: {e}", style="bold red"
|
|
41
|
+
)
|
|
34
42
|
return None
|
|
35
43
|
|
|
36
44
|
def delete_user_state(self, chat_id_data):
|
|
@@ -38,10 +46,12 @@ class RouterServiceClient:
|
|
|
38
46
|
try:
|
|
39
47
|
response = self.user_state_stub.DeleteUserState(request)
|
|
40
48
|
if not response.status:
|
|
41
|
-
print(
|
|
49
|
+
self.console.print(
|
|
50
|
+
f"Erro ao chamar SendMessage: {response.message}", style="bold red"
|
|
51
|
+
)
|
|
42
52
|
return response
|
|
43
53
|
except grpc.RpcError as e:
|
|
44
|
-
print(f"Erro ao chamar DeleteUserState: {e}")
|
|
54
|
+
self.console.print(f"Erro ao chamar DeleteUserState: {e}", style="bold red")
|
|
45
55
|
return None
|
|
46
56
|
|
|
47
57
|
def get_user_state(self, chat_id_data):
|
|
@@ -50,7 +60,7 @@ class RouterServiceClient:
|
|
|
50
60
|
response = self.user_state_stub.GetUserState(request)
|
|
51
61
|
return response
|
|
52
62
|
except grpc.RpcError as e:
|
|
53
|
-
print(f"Erro ao chamar GetUserState: {e}")
|
|
63
|
+
self.console.print(f"Erro ao chamar GetUserState: {e}", style="bold red")
|
|
54
64
|
return None
|
|
55
65
|
|
|
56
66
|
def send_message(self, message_data):
|
|
@@ -61,10 +71,12 @@ class RouterServiceClient:
|
|
|
61
71
|
try:
|
|
62
72
|
response = self.send_message_stub.SendMessage(request)
|
|
63
73
|
if not response.status:
|
|
64
|
-
print(
|
|
74
|
+
self.console.print(
|
|
75
|
+
f"Erro ao chamar SendMessage: {response.message}", style="bold red"
|
|
76
|
+
)
|
|
65
77
|
return response
|
|
66
78
|
except grpc.RpcError as e:
|
|
67
|
-
print(f"Erro ao chamar SendMessage: {e}")
|
|
79
|
+
self.console.print(f"Erro ao chamar SendMessage: {e}", style="bold red")
|
|
68
80
|
return None
|
|
69
81
|
|
|
70
82
|
def send_image(self, message_data):
|
|
@@ -75,12 +87,14 @@ class RouterServiceClient:
|
|
|
75
87
|
try:
|
|
76
88
|
response = self.send_message_stub.SendImage(request)
|
|
77
89
|
if not response.status and response.message != "arquivo não encontrado":
|
|
78
|
-
print(
|
|
90
|
+
self.console.print(
|
|
91
|
+
f"Erro ao chamar SendImage: {response.message}", style="bold red"
|
|
92
|
+
)
|
|
79
93
|
elif response.message == "arquivo não encontrado":
|
|
80
94
|
print("Arquivo não encontrado, Carregando arquivo...")
|
|
81
95
|
return response
|
|
82
96
|
except grpc.RpcError as e:
|
|
83
|
-
print(f"Erro ao chamar SendImage: {e}")
|
|
97
|
+
self.console.print(f"Erro ao chamar SendImage: {e}", style="bold red")
|
|
84
98
|
return None
|
|
85
99
|
|
|
86
100
|
def upload_file(self, file_data):
|
|
@@ -88,10 +102,12 @@ class RouterServiceClient:
|
|
|
88
102
|
try:
|
|
89
103
|
response = self.send_message_stub.UploadFile(request)
|
|
90
104
|
if not response.status:
|
|
91
|
-
print(
|
|
105
|
+
self.console.print(
|
|
106
|
+
f"Erro ao chamar UploadFile: {response.message}", style="bold red"
|
|
107
|
+
)
|
|
92
108
|
return response
|
|
93
109
|
except grpc.RpcError as e:
|
|
94
|
-
print(f"Erro ao chamar UploadFile: {e}")
|
|
110
|
+
self.console.print(f"Erro ao chamar UploadFile: {e}", style="bold red")
|
|
95
111
|
return None
|
|
96
112
|
|
|
97
113
|
def transfer_to_human(self, transfer_request_data):
|
|
@@ -99,10 +115,12 @@ class RouterServiceClient:
|
|
|
99
115
|
try:
|
|
100
116
|
response = self.transfer_stub.TransferToHuman(request)
|
|
101
117
|
if not response.status:
|
|
102
|
-
print(
|
|
118
|
+
self.console.print(
|
|
119
|
+
f"Erro ao chamar SendMessage: {response.message}", style="bold red"
|
|
120
|
+
)
|
|
103
121
|
return response
|
|
104
122
|
except grpc.RpcError as e:
|
|
105
|
-
print(f"Erro ao chamar TransferToHuman: {e}")
|
|
123
|
+
self.console.print(f"Erro ao chamar TransferToHuman: {e}", style="bold red")
|
|
106
124
|
return None
|
|
107
125
|
|
|
108
126
|
def transfer_to_menu(self, transfer_request_data):
|
|
@@ -110,10 +128,13 @@ class RouterServiceClient:
|
|
|
110
128
|
try:
|
|
111
129
|
response = self.transfer_stub.TransferToMenu(request)
|
|
112
130
|
if not response.status:
|
|
113
|
-
print(
|
|
131
|
+
self.console.print(
|
|
132
|
+
f"Erro ao chamar TransferToMenu: {response.message}",
|
|
133
|
+
style="bold red",
|
|
134
|
+
)
|
|
114
135
|
return response
|
|
115
136
|
except grpc.RpcError as e:
|
|
116
|
-
print(f"Erro ao chamar TransferToMenu: {e}")
|
|
137
|
+
self.console.print(f"Erro ao chamar TransferToMenu: {e}", style="bold red")
|
|
117
138
|
return None
|
|
118
139
|
|
|
119
140
|
def end_chat(self, end_chat_request_data):
|
|
@@ -121,10 +142,12 @@ class RouterServiceClient:
|
|
|
121
142
|
try:
|
|
122
143
|
response = self.end_chat_stub.EndChat(request)
|
|
123
144
|
if not response.status:
|
|
124
|
-
print(
|
|
145
|
+
self.console.print(
|
|
146
|
+
f"Erro ao chamar SendMessage: {response.message}", style="bold red"
|
|
147
|
+
)
|
|
125
148
|
return response
|
|
126
149
|
except grpc.RpcError as e:
|
|
127
|
-
print(f"Erro ao chamar EndChat: {e}")
|
|
150
|
+
self.console.print(f"Erro ao chamar EndChat: {e}", style="bold red")
|
|
128
151
|
return None
|
|
129
152
|
|
|
130
153
|
def get_campaign_id(self, campaign_name):
|
|
@@ -133,7 +156,7 @@ class RouterServiceClient:
|
|
|
133
156
|
response = self.transfer_stub.GetCampaignID(request)
|
|
134
157
|
return response
|
|
135
158
|
except grpc.RpcError as e:
|
|
136
|
-
print(f"Erro ao chamar GetCampaignID: {e}")
|
|
159
|
+
self.console.print(f"Erro ao chamar GetCampaignID: {e}", style="bold red")
|
|
137
160
|
return None
|
|
138
161
|
|
|
139
162
|
def get_all_campaigns(self):
|
|
@@ -142,7 +165,7 @@ class RouterServiceClient:
|
|
|
142
165
|
response = self.transfer_stub.GetAllCampaigns(request)
|
|
143
166
|
return response
|
|
144
167
|
except grpc.RpcError as e:
|
|
145
|
-
print(f"Erro ao chamar GetAllCampaigns: {e}")
|
|
168
|
+
self.console.print(f"Erro ao chamar GetAllCampaigns: {e}", style="bold red")
|
|
146
169
|
return None
|
|
147
170
|
|
|
148
171
|
def get_tabulation_id(self, tabulation_name):
|
|
@@ -151,7 +174,7 @@ class RouterServiceClient:
|
|
|
151
174
|
response = self.end_chat_stub.GetTabulationID(request)
|
|
152
175
|
return response
|
|
153
176
|
except grpc.RpcError as e:
|
|
154
|
-
print(f"Erro ao chamar GetTabulationID: {e}")
|
|
177
|
+
self.console.print(f"Erro ao chamar GetTabulationID: {e}", style="bold red")
|
|
155
178
|
return None
|
|
156
179
|
|
|
157
180
|
def get_all_tabulations(self):
|
|
@@ -160,5 +183,7 @@ class RouterServiceClient:
|
|
|
160
183
|
response = self.end_chat_stub.GetAllTabulations(request)
|
|
161
184
|
return response
|
|
162
185
|
except grpc.RpcError as e:
|
|
163
|
-
print(
|
|
186
|
+
self.console.print(
|
|
187
|
+
f"Erro ao chamar GetAllTabulations: {e}", style="bold red"
|
|
188
|
+
)
|
|
164
189
|
return None
|
chatgraph/types/end_types.py
CHANGED
|
@@ -25,11 +25,20 @@ class EndChatResponse:
|
|
|
25
25
|
observations (str): As observações finais do chatbot.
|
|
26
26
|
"""
|
|
27
27
|
|
|
28
|
-
def __init__(
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
tabulation_id: str,
|
|
31
|
+
tabulation_name: str | None = None,
|
|
32
|
+
observations: str | None = None,
|
|
33
|
+
) -> None:
|
|
29
34
|
"""
|
|
30
35
|
Finzaliza e tabula as informações do chatbot.
|
|
31
36
|
"""
|
|
37
|
+
if not tabulation_id and not tabulation_name:
|
|
38
|
+
raise ValueError("tabulation_id or tabulation_name must be provided.")
|
|
39
|
+
|
|
32
40
|
self.tabulation_id = tabulation_id
|
|
41
|
+
self.tabulation_name = tabulation_name
|
|
33
42
|
self.observations = observations
|
|
34
43
|
|
|
35
44
|
|
|
@@ -38,11 +47,17 @@ class TransferToHuman:
|
|
|
38
47
|
Representa uma transferencia para um atendente humano.
|
|
39
48
|
"""
|
|
40
49
|
|
|
41
|
-
def __init__(
|
|
50
|
+
def __init__(
|
|
51
|
+
self,
|
|
52
|
+
campaign_id: str,
|
|
53
|
+
campaign_name: str | None = None,
|
|
54
|
+
observations: str | None = None,
|
|
55
|
+
) -> None:
|
|
42
56
|
"""
|
|
43
57
|
Finzaliza e tabula as informações do chatbot.
|
|
44
58
|
"""
|
|
45
59
|
self.campaign_id = campaign_id
|
|
60
|
+
self.campaign_name = campaign_name
|
|
46
61
|
self.observations = observations
|
|
47
62
|
|
|
48
63
|
|
chatgraph/types/request_types.py
CHANGED
|
@@ -4,6 +4,7 @@ from chatgraph.types.message_types import Message, Button, MessageTypes, message
|
|
|
4
4
|
from typing import Optional
|
|
5
5
|
from datetime import datetime
|
|
6
6
|
import json, os
|
|
7
|
+
from rich.console import Console
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
class ChatID:
|
|
@@ -155,6 +156,7 @@ class UserCall:
|
|
|
155
156
|
self.__grpc_uri = grpc_uri
|
|
156
157
|
|
|
157
158
|
self.__router_client = RouterServiceClient(self.__grpc_uri)
|
|
159
|
+
self.console = Console()
|
|
158
160
|
|
|
159
161
|
def __str__(self):
|
|
160
162
|
return f"UserCall({self.type}, {self.__type_message}, {self.__content_message}, {self.__user_state})"
|
|
@@ -220,14 +222,20 @@ class UserCall:
|
|
|
220
222
|
if not response.status:
|
|
221
223
|
raise ValueError("Erro ao enviar mensagem de botões.")
|
|
222
224
|
|
|
223
|
-
def transfer_to_human(
|
|
225
|
+
def transfer_to_human(
|
|
226
|
+
self, message: str, campaign_id: str = None, campaign_name: str = None
|
|
227
|
+
) -> None:
|
|
224
228
|
|
|
225
|
-
|
|
229
|
+
if campaign_id is None and campaign_name is None:
|
|
230
|
+
raise ValueError("Você deve informar o ID ou o nome da campanha.")
|
|
231
|
+
if not campaign_id:
|
|
232
|
+
campaign = self.__router_client.get_campaign_id({"name": campaign_name})
|
|
233
|
+
campaign_id = campaign.id
|
|
226
234
|
|
|
227
235
|
response = self.__router_client.transfer_to_human(
|
|
228
236
|
{
|
|
229
237
|
"chat_id": self.__user_state.chatID.to_dict(),
|
|
230
|
-
"campaign_id":
|
|
238
|
+
"campaign_id": campaign_id,
|
|
231
239
|
"observation": message,
|
|
232
240
|
}
|
|
233
241
|
)
|
|
@@ -248,13 +256,19 @@ class UserCall:
|
|
|
248
256
|
if not response.status:
|
|
249
257
|
raise ValueError("Erro ao transferir chat para menu.")
|
|
250
258
|
|
|
251
|
-
def end_chat(self, message: str, tabulation_name: str) -> None:
|
|
252
|
-
|
|
259
|
+
def end_chat(self, message: str, tabulation_id: str, tabulation_name: str) -> None:
|
|
260
|
+
if tabulation_id is None and tabulation_name is None:
|
|
261
|
+
raise ValueError("Você deve informar o ID ou o nome da tabulação.")
|
|
262
|
+
if not tabulation_id:
|
|
263
|
+
tabulation = self.__router_client.get_tabulation_id(
|
|
264
|
+
{"name": tabulation_name}
|
|
265
|
+
)
|
|
266
|
+
tabulation_id = tabulation.id
|
|
253
267
|
|
|
254
268
|
response = self.__router_client.end_chat(
|
|
255
269
|
{
|
|
256
270
|
"chat_id": self.__user_state.chatID.to_dict(),
|
|
257
|
-
"tabulation_id":
|
|
271
|
+
"tabulation_id": tabulation_id,
|
|
258
272
|
"observation": message,
|
|
259
273
|
}
|
|
260
274
|
)
|
|
@@ -340,3 +354,7 @@ class UserCall:
|
|
|
340
354
|
self.update_user_state(
|
|
341
355
|
self.__user_state.menu, self.__user_state.route, observation
|
|
342
356
|
)
|
|
357
|
+
|
|
358
|
+
@content_message.setter
|
|
359
|
+
def content_message(self, content_message: str):
|
|
360
|
+
self.__content_message = content_message
|
chatgraph/types/route.py
CHANGED
|
@@ -10,7 +10,7 @@ class Route:
|
|
|
10
10
|
routes (list[str]): A lista de todas as rotas disponíveis no fluxo.
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
|
-
def __init__(self, current: str, routes: list[str], separator:str=
|
|
13
|
+
def __init__(self, current: str, routes: list[str], separator: str = "."):
|
|
14
14
|
"""
|
|
15
15
|
Inicializa a rota com a rota atual e a lista de rotas disponíveis.
|
|
16
16
|
|
|
@@ -24,20 +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:
|
|
34
|
+
def current_node(self) -> str:
|
|
35
35
|
"""
|
|
36
36
|
Retorna o nó atual do usuário
|
|
37
37
|
"""
|
|
38
38
|
return self.current.split(self.separator)[-1]
|
|
39
|
-
|
|
40
|
-
def get_previous(self) ->
|
|
39
|
+
|
|
40
|
+
def get_previous(self) -> "Route":
|
|
41
41
|
"""
|
|
42
42
|
Retorna o caminho anterior ao caminho atual.
|
|
43
43
|
|
|
@@ -47,13 +47,18 @@ class Route:
|
|
|
47
47
|
Returns:
|
|
48
48
|
str: O caminho anterior à rota atual.
|
|
49
49
|
"""
|
|
50
|
-
if self.current ==
|
|
50
|
+
if self.current == "start":
|
|
51
51
|
return Route(self.current, self.routes, self.separator)
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
rotas_dedup = self.separator.join(
|
|
54
|
+
dict.fromkeys(self.current.split(self.separator))
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
previous_route = self.separator.join(rotas_dedup.split(self.separator)[:-1])
|
|
58
|
+
|
|
54
59
|
return Route(previous_route, self.routes, self.separator)
|
|
55
60
|
|
|
56
|
-
def get_next(self, next_part: str) ->
|
|
61
|
+
def get_next(self, next_part: str) -> "Route":
|
|
57
62
|
"""
|
|
58
63
|
Monta e retorna o próximo caminho com base na parte fornecida.
|
|
59
64
|
|
|
@@ -69,8 +74,8 @@ class Route:
|
|
|
69
74
|
next_part = next_part.strip().lower()
|
|
70
75
|
next_route = f"{self.current.rstrip(self.separator)}.{next_part}"
|
|
71
76
|
if next_part not in self.routes:
|
|
72
|
-
raise RouteError(f
|
|
73
|
-
|
|
77
|
+
raise RouteError(f"Rota não encontrada: {next_part}")
|
|
78
|
+
|
|
74
79
|
return Route(next_route, self.routes, self.separator)
|
|
75
80
|
|
|
76
81
|
def __str__(self):
|
|
@@ -80,7 +85,7 @@ class Route:
|
|
|
80
85
|
Returns:
|
|
81
86
|
str: A representação em string da rota atual.
|
|
82
87
|
"""
|
|
83
|
-
return f
|
|
88
|
+
return f"Route(current={self.current})"
|
|
84
89
|
|
|
85
90
|
def __repr__(self):
|
|
86
91
|
"""
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
chatgraph/__init__.py,sha256=cQk87BOUYKvOjgCkS5Vexy9EYeLOeuQn6vR1vXx1Akc,935
|
|
2
2
|
chatgraph/auth/credentials.py,sha256=xsMEpLQnc66novPjL6upocMcnUnvFJ7yxINzUenkxmc,2388
|
|
3
|
-
chatgraph/bot/chatbot_model.py,sha256=
|
|
3
|
+
chatgraph/bot/chatbot_model.py,sha256=kI990THIgwcwRm69XcfSqJkUAH1Khbm5OrfDnKxMZ8o,8446
|
|
4
4
|
chatgraph/bot/chatbot_router.py,sha256=bVbm9dBoC2OesetXlQJpCrkaiLM3GUro0GrOyCSgreI,2586
|
|
5
|
+
chatgraph/bot/default_functions.py,sha256=OSgo3NGxT4RwGe5ohpGksaARSDSkNInLmJsBuZAuv1Y,739
|
|
5
6
|
chatgraph/cli/__init__.py,sha256=tfgYhGoKy1nD4STN4xDh6J4VV55RICk7v1GZmzAg-bM,7413
|
|
6
7
|
chatgraph/error/chatbot_error.py,sha256=4sEcW8vz0eQk2QDmDygucVM4caHliZW5iH7XJvmLBuk,1897
|
|
7
8
|
chatgraph/error/route_error.py,sha256=CY8m82ap7-Sr-DXPsolltRW50TqD__5RyXBmNNJCWr8,793
|
|
8
|
-
chatgraph/gRPC/gRPCCall.py,sha256=
|
|
9
|
+
chatgraph/gRPC/gRPCCall.py,sha256=jMWPbHobyR6n942BARsQSlVmbh6dk0qUpfVgSNlGOvg,7561
|
|
9
10
|
chatgraph/messages/message_consumer.py,sha256=yHhfLYjtmXQYG44o7SNO6XUaeM4-jH8BpIpPHI-mt8Y,6116
|
|
10
11
|
chatgraph/pb/router.proto,sha256=0FDhMe7GrabeQz7QRJN8PN2mcuRjA5YrGt6TC9GWBak,3488
|
|
11
12
|
chatgraph/pb/router_pb2.py,sha256=eSo0ncYDSG3ryIfWNFzqmG3anx-VmQ2nGXBy1gPnXmQ,7962
|
|
12
13
|
chatgraph/pb/router_pb2_grpc.py,sha256=iaQQsYPc8Tihuf4sWEI48DhvhtCYtDqFBHhwRtE57ps,29886
|
|
13
14
|
chatgraph/types/background_task.py,sha256=j-Bpd1l_LCDiWukhfG8wNr1F0_GUaOL_J2_BCUnTof4,928
|
|
14
|
-
chatgraph/types/end_types.py,sha256=
|
|
15
|
+
chatgraph/types/end_types.py,sha256=QMNju3wpdbCpdUTSZ0oGQx9x0wgckxmw1wfGgowqCTk,2057
|
|
15
16
|
chatgraph/types/image.py,sha256=-Lf9ns8_M4jmROoFnHlZiYeScYD_GhF1pgIGLVjsRtI,3216
|
|
16
17
|
chatgraph/types/message_types.py,sha256=__LOk09Xfvojum0xiq9n157_3QSSLNaDMc02iq8dGpk,3434
|
|
17
|
-
chatgraph/types/request_types.py,sha256=
|
|
18
|
-
chatgraph/types/route.py,sha256=
|
|
19
|
-
chatgraph-0.6.
|
|
20
|
-
chatgraph-0.6.
|
|
21
|
-
chatgraph-0.6.
|
|
22
|
-
chatgraph-0.6.
|
|
23
|
-
chatgraph-0.6.
|
|
18
|
+
chatgraph/types/request_types.py,sha256=DC-x4tR5WLxcI9wzaZ0bk82eeLaTOClQbal3F1KWG2w,11240
|
|
19
|
+
chatgraph/types/route.py,sha256=UUlMWje8yZ4scHp3LKXrtRXycDtudIwUpwQvi3zQ2_w,3090
|
|
20
|
+
chatgraph-0.6.2.dist-info/entry_points.txt,sha256=bO9_Q-PqE5vCNNo6ke_-3j2gHfKQMDGnKDTkNuCdBuA,48
|
|
21
|
+
chatgraph-0.6.2.dist-info/LICENSE,sha256=rVJozpRzDlplOpvI8A1GvmfVS0ReYdZvMWc1j2jV0v8,1090
|
|
22
|
+
chatgraph-0.6.2.dist-info/METADATA,sha256=-n5XOgBx9bxthqGX6W7TncIQKqXkncARgWvKcZH28FA,12908
|
|
23
|
+
chatgraph-0.6.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
24
|
+
chatgraph-0.6.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|