chatgraph 0.3.0__py3-none-any.whl → 0.3.4__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/__init__.py +6 -3
- chatgraph/bot/chatbot_model.py +39 -34
- chatgraph/bot/chatbot_router.py +4 -0
- chatgraph/cli/__init__.py +187 -0
- chatgraph/gRPC/gRPCCall.py +85 -0
- chatgraph/messages/message_consumer.py +7 -11
- chatgraph/pb/userstate.proto +10 -0
- chatgraph/pb/userstate_pb2.py +13 -9
- chatgraph/pb/userstate_pb2_grpc.py +44 -1
- chatgraph/pb/voll.proto +60 -3
- chatgraph/pb/voll_pb2.py +29 -9
- chatgraph/pb/voll_pb2_grpc.py +288 -1
- chatgraph/types/end_types.py +45 -0
- chatgraph/types/message_types.py +82 -186
- chatgraph/types/request_types.py +265 -0
- chatgraph/types/route.py +11 -3
- chatgraph-0.3.4.dist-info/METADATA +326 -0
- chatgraph-0.3.4.dist-info/RECORD +24 -0
- chatgraph-0.3.4.dist-info/entry_points.txt +3 -0
- chatgraph/types/output_state.py +0 -127
- chatgraph-0.3.0.dist-info/METADATA +0 -146
- chatgraph-0.3.0.dist-info/RECORD +0 -21
- {chatgraph-0.3.0.dist-info → chatgraph-0.3.4.dist-info}/LICENSE +0 -0
- {chatgraph-0.3.0.dist-info → chatgraph-0.3.4.dist-info}/WHEEL +0 -0
chatgraph/__init__.py
CHANGED
|
@@ -2,8 +2,9 @@ from .auth.credentials import Credential
|
|
|
2
2
|
from .bot.chatbot_model import ChatbotApp
|
|
3
3
|
from .bot.chatbot_router import ChatbotRouter
|
|
4
4
|
from .messages.message_consumer import MessageConsumer
|
|
5
|
-
from .types.
|
|
6
|
-
from .types.
|
|
5
|
+
from .types.request_types import UserCall, UserState
|
|
6
|
+
from .types.end_types import RedirectResponse, EndChatResponse, TransferToHuman
|
|
7
|
+
from .types.message_types import Message, Button, ListElements
|
|
7
8
|
from .types.route import Route
|
|
8
9
|
|
|
9
10
|
__all__ = [
|
|
@@ -18,5 +19,7 @@ __all__ = [
|
|
|
18
19
|
'EndChatResponse',
|
|
19
20
|
'TransferToHuman',
|
|
20
21
|
'UserState',
|
|
21
|
-
'
|
|
22
|
+
'Message',
|
|
23
|
+
'Button',
|
|
24
|
+
'ListElements'
|
|
22
25
|
]
|
chatgraph/bot/chatbot_model.py
CHANGED
|
@@ -6,8 +6,9 @@ from logging import error
|
|
|
6
6
|
|
|
7
7
|
from ..error.chatbot_error import ChatbotError, ChatbotMessageError
|
|
8
8
|
from ..messages.message_consumer import MessageConsumer
|
|
9
|
-
from ..types.
|
|
10
|
-
from ..types.
|
|
9
|
+
from ..types.request_types import UserCall
|
|
10
|
+
from ..types.message_types import messageTypes, Message, Button, ListElements
|
|
11
|
+
from ..types.end_types import RedirectResponse, EndChatResponse, TransferToHuman
|
|
11
12
|
from ..types.route import Route
|
|
12
13
|
from .chatbot_router import ChatbotRouter
|
|
13
14
|
|
|
@@ -17,13 +18,16 @@ class ChatbotApp:
|
|
|
17
18
|
Classe principal para a aplicação do chatbot, gerencia as rotas e a lógica de processamento de mensagens.
|
|
18
19
|
"""
|
|
19
20
|
|
|
20
|
-
def __init__(self, message_consumer: MessageConsumer):
|
|
21
|
+
def __init__(self, message_consumer: MessageConsumer = None):
|
|
21
22
|
"""
|
|
22
23
|
Inicializa a classe ChatbotApp com um estado de usuário e um consumidor de mensagens.
|
|
23
24
|
|
|
24
25
|
Args:
|
|
25
26
|
message_consumer (MessageConsumer): O consumidor de mensagens que lida com a entrada de mensagens no sistema.
|
|
26
27
|
"""
|
|
28
|
+
if not message_consumer:
|
|
29
|
+
message_consumer = MessageConsumer.load_dotenv()
|
|
30
|
+
|
|
27
31
|
self.__message_consumer = message_consumer
|
|
28
32
|
self.__routes = {}
|
|
29
33
|
|
|
@@ -125,6 +129,7 @@ class ChatbotApp:
|
|
|
125
129
|
raise ChatbotMessageError(
|
|
126
130
|
customer_id, f'Rota não encontrada para {route}!'
|
|
127
131
|
)
|
|
132
|
+
|
|
128
133
|
func = handler['function']
|
|
129
134
|
userCall_name = handler['params'].get(UserCall, None)
|
|
130
135
|
route_state_name = handler['params'].get(Route, None)
|
|
@@ -136,42 +141,42 @@ class ChatbotApp:
|
|
|
136
141
|
kwargs[route_state_name] = Route(route, list(self.__routes.keys()))
|
|
137
142
|
|
|
138
143
|
userCall_response = func(**kwargs)
|
|
144
|
+
|
|
145
|
+
if isinstance(userCall_response, (list, tuple)):
|
|
146
|
+
for response in userCall_response:
|
|
147
|
+
self.__process_func_response(response, userCall)
|
|
139
148
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
elif
|
|
151
|
-
|
|
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)
|
|
149
|
+
def __process_func_response(self, userCall_response, userCall: UserCall):
|
|
150
|
+
|
|
151
|
+
if isinstance(userCall_response, (str, float, int)):
|
|
152
|
+
userCall.send(Message(text=userCall_response))
|
|
153
|
+
return
|
|
154
|
+
|
|
155
|
+
elif isinstance(userCall_response, Route):
|
|
156
|
+
userCall.route = userCall_response.current
|
|
157
|
+
return
|
|
158
|
+
|
|
159
|
+
elif isinstance(userCall_response, (Message, Button, ListElements)):
|
|
160
|
+
userCall.send(userCall_response)
|
|
161
|
+
|
|
162
|
+
return
|
|
163
|
+
|
|
164
|
+
elif isinstance(userCall_response, EndChatResponse):
|
|
165
|
+
userCall.end_chat(userCall_response.obersevations, userCall_response.tabulation_id)
|
|
166
|
+
return
|
|
169
167
|
|
|
170
|
-
elif
|
|
168
|
+
elif isinstance(userCall_response, TransferToHuman):
|
|
169
|
+
userCall.transfer_to_human(userCall_response.observations, userCall_response.campaign_id)
|
|
170
|
+
return
|
|
171
|
+
|
|
172
|
+
elif isinstance(userCall_response, RedirectResponse):
|
|
171
173
|
route = self.__adjust_route(userCall_response.route, route)
|
|
172
174
|
userCall.route = route
|
|
173
175
|
return self.process_message(userCall)
|
|
174
|
-
|
|
176
|
+
|
|
177
|
+
elif not userCall_response:
|
|
178
|
+
return
|
|
179
|
+
|
|
175
180
|
else:
|
|
176
181
|
error('Tipo de retorno inválido!')
|
|
177
182
|
return None
|
chatgraph/bot/chatbot_router.py
CHANGED
|
@@ -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()}'
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
from rich.console import Console
|
|
3
|
+
from rich.table import Table
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
from ..gRPC.gRPCCall import WhatsappServiceClient, UserStateServiceClient
|
|
6
|
+
import os, re
|
|
7
|
+
|
|
8
|
+
load_dotenv()
|
|
9
|
+
app = typer.Typer()
|
|
10
|
+
|
|
11
|
+
@app.command()
|
|
12
|
+
def configs():
|
|
13
|
+
"""Recupera os IDs necessários."""
|
|
14
|
+
console = Console()
|
|
15
|
+
|
|
16
|
+
username = os.getenv('RABBIT_USER')
|
|
17
|
+
password = os.getenv('RABBIT_PASS')
|
|
18
|
+
url = os.getenv('RABBIT_URI')
|
|
19
|
+
queue = os.getenv('RABBIT_QUEUE')
|
|
20
|
+
prefetch = os.getenv('RABBIT_PREFETCH', 1)
|
|
21
|
+
vhost = os.getenv('RABBIT_VHOST', '/')
|
|
22
|
+
grpc = os.getenv('GRPC_URI')
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
tableRabbit = Table(show_header=True, header_style="bold magenta", title="RabbitMQ Consumer")
|
|
26
|
+
tableRabbit.add_column("Atributo", justify="center", style="cyan", no_wrap=True)
|
|
27
|
+
tableRabbit.add_column("Valor", justify="center", style="magenta")
|
|
28
|
+
|
|
29
|
+
tableRabbit.add_row("Virtual Host", vhost)
|
|
30
|
+
tableRabbit.add_row("Prefetch Count", str(prefetch))
|
|
31
|
+
tableRabbit.add_row("Queue Consume", queue)
|
|
32
|
+
tableRabbit.add_row("AMQP URL", url)
|
|
33
|
+
tableRabbit.add_row("Username", username)
|
|
34
|
+
tableRabbit.add_row("Password", "******")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
tableGRPC = Table(show_header=True, header_style="bold magenta", title="gRPC Consumer")
|
|
38
|
+
tableGRPC.add_column("Atributo", justify="center", style="cyan", no_wrap=True)
|
|
39
|
+
tableGRPC.add_column("Valor", justify="center", style="magenta")
|
|
40
|
+
|
|
41
|
+
tableGRPC.add_row("URI", grpc)
|
|
42
|
+
|
|
43
|
+
console.print(tableGRPC, justify="center")
|
|
44
|
+
console.print(tableRabbit, justify="center")
|
|
45
|
+
|
|
46
|
+
@app.command()
|
|
47
|
+
def campaigns(regex: str = typer.Option(None, "--regex", "-r", help="Filtro regex para campanhas.")):
|
|
48
|
+
"""Recupera as campanhas cadastradas."""
|
|
49
|
+
grpc = os.getenv('GRPC_URI')
|
|
50
|
+
|
|
51
|
+
wwp = WhatsappServiceClient(grpc)
|
|
52
|
+
campaigns = wwp.get_all_campaigns()
|
|
53
|
+
|
|
54
|
+
console = Console()
|
|
55
|
+
tableGRPC = Table(show_header=True, header_style="bold magenta", title="Campaigns")
|
|
56
|
+
tableGRPC.add_column("campaign_id", justify="center", style="cyan", no_wrap=True)
|
|
57
|
+
tableGRPC.add_column("campaign_name", justify="center", style="magenta")
|
|
58
|
+
tableGRPC.add_column("last_update", justify="center", style="magenta")
|
|
59
|
+
|
|
60
|
+
# Aplicar filtro de regex, se fornecido
|
|
61
|
+
filtered_campaigns = campaigns.campaigns
|
|
62
|
+
if regex:
|
|
63
|
+
pattern = re.compile(regex, re.IGNORECASE)
|
|
64
|
+
filtered_campaigns = [
|
|
65
|
+
campaign for campaign in campaigns.campaigns
|
|
66
|
+
if pattern.search(campaign.campaign_name)
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
for campaign in filtered_campaigns:
|
|
70
|
+
tableGRPC.add_row(campaign.campaign_id, campaign.campaign_name, campaign.last_update)
|
|
71
|
+
|
|
72
|
+
console.print(tableGRPC, justify="center")
|
|
73
|
+
|
|
74
|
+
@app.command()
|
|
75
|
+
def tabulations(
|
|
76
|
+
regex: str = typer.Option(None, "--regex", "-r", help="Filtro regex para as tabulações.")
|
|
77
|
+
):
|
|
78
|
+
"""Recupera as tabulações cadastradas."""
|
|
79
|
+
grpc = os.getenv('GRPC_URI')
|
|
80
|
+
|
|
81
|
+
wwp = WhatsappServiceClient(grpc)
|
|
82
|
+
tabulations = wwp.get_all_tabulations()
|
|
83
|
+
|
|
84
|
+
console = Console()
|
|
85
|
+
tableGRPC = Table(show_header=True, header_style="bold magenta", title="Tabulations")
|
|
86
|
+
tableGRPC.add_column("tabulation_id", justify="center", style="cyan", no_wrap=True)
|
|
87
|
+
tableGRPC.add_column("tabulation_name", justify="center", style="magenta")
|
|
88
|
+
tableGRPC.add_column("tabulation_type", justify="center", style="magenta")
|
|
89
|
+
tableGRPC.add_column("group_name", justify="center", style="magenta")
|
|
90
|
+
tableGRPC.add_column("customer_service_survey_id", justify="center", style="magenta")
|
|
91
|
+
tableGRPC.add_column("last_update", justify="center", style="magenta")
|
|
92
|
+
|
|
93
|
+
# Aplicar filtro de regex, se fornecido
|
|
94
|
+
filtered_tabulations = tabulations.tabulations
|
|
95
|
+
if regex:
|
|
96
|
+
pattern = re.compile(regex, re.IGNORECASE)
|
|
97
|
+
filtered_tabulations = [
|
|
98
|
+
tabulation for tabulation in tabulations.tabulations
|
|
99
|
+
if (
|
|
100
|
+
pattern.search(tabulation.tabulation_id) or
|
|
101
|
+
pattern.search(tabulation.tabulation_name) or
|
|
102
|
+
pattern.search(tabulation.tabulation_type) or
|
|
103
|
+
pattern.search(tabulation.group_name) or
|
|
104
|
+
(tabulation.customer_service_survey_id and pattern.search(tabulation.customer_service_survey_id)) or
|
|
105
|
+
pattern.search(tabulation.last_update)
|
|
106
|
+
)
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
for tabulation in filtered_tabulations:
|
|
110
|
+
tableGRPC.add_row(
|
|
111
|
+
tabulation.tabulation_id,
|
|
112
|
+
tabulation.tabulation_name,
|
|
113
|
+
tabulation.tabulation_type,
|
|
114
|
+
tabulation.group_name,
|
|
115
|
+
tabulation.customer_service_survey_id or "N/A",
|
|
116
|
+
tabulation.last_update,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
console.print(tableGRPC, justify="center")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
@app.command("ustate")
|
|
123
|
+
def user_state(
|
|
124
|
+
regex: str = typer.Option(None, "--regex", "-r", help="Filtro regex para os estados do usuário.")
|
|
125
|
+
):
|
|
126
|
+
"""Recupera os UserState em operação no momento."""
|
|
127
|
+
grpc = os.getenv('GRPC_URI')
|
|
128
|
+
|
|
129
|
+
ustate = UserStateServiceClient(grpc)
|
|
130
|
+
userstates = ustate.get_all_user_states()
|
|
131
|
+
|
|
132
|
+
console = Console()
|
|
133
|
+
tableGRPC = Table(show_header=True, header_style="bold magenta", title="User States")
|
|
134
|
+
tableGRPC.add_column("user_id", justify="center", style="cyan", no_wrap=True)
|
|
135
|
+
tableGRPC.add_column("menu_id", justify="center", style="magenta")
|
|
136
|
+
tableGRPC.add_column("route", justify="center", style="magenta")
|
|
137
|
+
tableGRPC.add_column("obs", justify="center", style="magenta")
|
|
138
|
+
tableGRPC.add_column("date", justify="center", style="magenta")
|
|
139
|
+
tableGRPC.add_column("direction", justify="center", style="magenta")
|
|
140
|
+
|
|
141
|
+
# Aplicar filtro de regex, se fornecido
|
|
142
|
+
filtered_user_states = userstates.user_states
|
|
143
|
+
if regex:
|
|
144
|
+
pattern = re.compile(regex, re.IGNORECASE)
|
|
145
|
+
filtered_user_states = [
|
|
146
|
+
userstate for userstate in userstates.user_states
|
|
147
|
+
if (
|
|
148
|
+
pattern.search(userstate.user_id) or
|
|
149
|
+
pattern.search(userstate.menu_id) or
|
|
150
|
+
pattern.search(userstate.route) or
|
|
151
|
+
pattern.search(userstate.obs) or
|
|
152
|
+
pattern.search(userstate.date) or
|
|
153
|
+
pattern.search(str(userstate.direction))
|
|
154
|
+
)
|
|
155
|
+
]
|
|
156
|
+
|
|
157
|
+
for userstate in filtered_user_states:
|
|
158
|
+
tableGRPC.add_row(
|
|
159
|
+
userstate.user_id,
|
|
160
|
+
userstate.menu_id,
|
|
161
|
+
userstate.route,
|
|
162
|
+
userstate.obs,
|
|
163
|
+
userstate.date,
|
|
164
|
+
str(userstate.direction),
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
console.print(tableGRPC, justify="center")
|
|
168
|
+
|
|
169
|
+
@app.command("del-ustate")
|
|
170
|
+
def delete_user_state(user_id: str = typer.Argument(..., help="ID do UserState a ser deletado.")):
|
|
171
|
+
"""Deleta um UserState em operação no momento."""
|
|
172
|
+
grpc = os.getenv('GRPC_URI')
|
|
173
|
+
|
|
174
|
+
ustate = UserStateServiceClient(grpc)
|
|
175
|
+
|
|
176
|
+
# Chama o método para deletar o UserState usando o ID fornecido
|
|
177
|
+
try:
|
|
178
|
+
success = ustate.delete_user_state(user_id)
|
|
179
|
+
if success:
|
|
180
|
+
typer.echo(f"UserState com ID '{user_id}' deletado com sucesso.")
|
|
181
|
+
else:
|
|
182
|
+
typer.echo(f"Falha ao deletar UserState com ID '{user_id}'.", err=True)
|
|
183
|
+
except Exception as e:
|
|
184
|
+
typer.echo(f"Erro ao tentar deletar UserState: {e}", err=True)
|
|
185
|
+
|
|
186
|
+
def main():
|
|
187
|
+
app()
|
chatgraph/gRPC/gRPCCall.py
CHANGED
|
@@ -22,6 +22,7 @@ class WhatsappServiceClient:
|
|
|
22
22
|
|
|
23
23
|
# Cria o stub (client) para o serviço gRPC
|
|
24
24
|
self.stub = whatsapp_pb2_grpc.MessageServiceStub(self.channel)
|
|
25
|
+
self.actions_stub = whatsapp_pb2_grpc.ActionsServiceStub(self.channel)
|
|
25
26
|
|
|
26
27
|
def send_button(self, message_data):
|
|
27
28
|
# Cria o request para o método SendButton
|
|
@@ -58,6 +59,78 @@ class WhatsappServiceClient:
|
|
|
58
59
|
except grpc.RpcError as e:
|
|
59
60
|
print(f"Erro ao fazer a requisição gRPC SendText: {e}")
|
|
60
61
|
return None
|
|
62
|
+
|
|
63
|
+
def transfer_to_human(self, message_data):
|
|
64
|
+
# Cria o request para o método TransferToHuman
|
|
65
|
+
request = whatsapp_pb2.MessageRequest(**message_data)
|
|
66
|
+
|
|
67
|
+
# Faz a chamada ao serviço gRPC
|
|
68
|
+
try:
|
|
69
|
+
response = self.stub.TransferToHuman(request)
|
|
70
|
+
return response
|
|
71
|
+
except grpc.RpcError as e:
|
|
72
|
+
print(f"Erro ao fazer a requisição gRPC TransferToHuman: {e}")
|
|
73
|
+
return None
|
|
74
|
+
|
|
75
|
+
def end_chat(self, message_data):
|
|
76
|
+
# Cria o request para o método EndChat
|
|
77
|
+
request = whatsapp_pb2.MessageRequest(**message_data)
|
|
78
|
+
|
|
79
|
+
# Faz a chamada ao serviço gRPC
|
|
80
|
+
try:
|
|
81
|
+
response = self.stub.EndChat(request)
|
|
82
|
+
return response
|
|
83
|
+
except grpc.RpcError as e:
|
|
84
|
+
print(f"Erro ao fazer a requisição gRPC EndChat: {e}")
|
|
85
|
+
return None
|
|
86
|
+
|
|
87
|
+
def get_campaign_id(self, campaign_name):
|
|
88
|
+
# Cria o request para o método GetCampaignID
|
|
89
|
+
request = whatsapp_pb2.CampaignName(campaign_name=campaign_name)
|
|
90
|
+
|
|
91
|
+
# Faz a chamada ao serviço gRPC
|
|
92
|
+
try:
|
|
93
|
+
response = self.actions_stub.GetCampaignID(request)
|
|
94
|
+
return response
|
|
95
|
+
except grpc.RpcError as e:
|
|
96
|
+
print(f"Erro ao fazer a requisição gRPC GetCampaignID: {e}")
|
|
97
|
+
return None
|
|
98
|
+
|
|
99
|
+
def get_tabulation_id(self, tabulation_name):
|
|
100
|
+
# Cria o request para o método GetTabulationID
|
|
101
|
+
request = whatsapp_pb2.TabulationName(tabulation_name=tabulation_name)
|
|
102
|
+
|
|
103
|
+
# Faz a chamada ao serviço gRPC
|
|
104
|
+
try:
|
|
105
|
+
response = self.actions_stub.GetTabulationID(request)
|
|
106
|
+
return response
|
|
107
|
+
except grpc.RpcError as e:
|
|
108
|
+
print(f"Erro ao fazer a requisição gRPC GetTabulationID: {e}")
|
|
109
|
+
return None
|
|
110
|
+
|
|
111
|
+
def get_all_campaigns(self):
|
|
112
|
+
# Cria o request para o método GetAllCampaigns
|
|
113
|
+
request = whatsapp_pb2.Void()
|
|
114
|
+
|
|
115
|
+
# Faz a chamada ao serviço gRPC
|
|
116
|
+
try:
|
|
117
|
+
response = self.actions_stub.GetCampaignsList(request)
|
|
118
|
+
return response
|
|
119
|
+
except grpc.RpcError as e:
|
|
120
|
+
print(f"Erro ao fazer a requisição gRPC GetAllCampaigns: {e}")
|
|
121
|
+
return None
|
|
122
|
+
|
|
123
|
+
def get_all_tabulations(self):
|
|
124
|
+
# Cria o request para o método GetAllTabulations
|
|
125
|
+
request = whatsapp_pb2.Void()
|
|
126
|
+
|
|
127
|
+
# Faz a chamada ao serviço gRPC
|
|
128
|
+
try:
|
|
129
|
+
response = self.actions_stub.GetTabulationsList(request)
|
|
130
|
+
return response
|
|
131
|
+
except grpc.RpcError as e:
|
|
132
|
+
print(f"Erro ao fazer a requisição gRPC GetAllTabulations: {e}")
|
|
133
|
+
return None
|
|
61
134
|
|
|
62
135
|
class UserStateServiceClient:
|
|
63
136
|
def __init__(self, grpc_uri=None):
|
|
@@ -122,4 +195,16 @@ class UserStateServiceClient:
|
|
|
122
195
|
return response
|
|
123
196
|
except grpc.RpcError as e:
|
|
124
197
|
print(f"Erro ao fazer a requisição gRPC DeleteUserState: {e}")
|
|
198
|
+
return None
|
|
199
|
+
|
|
200
|
+
def get_all_user_states(self):
|
|
201
|
+
# Cria o request para o método GetAllUserStates
|
|
202
|
+
request = userstate_pb2.Void()
|
|
203
|
+
|
|
204
|
+
# Faz a chamada ao serviço gRPC
|
|
205
|
+
try:
|
|
206
|
+
response = self.stub.GetAllUserStates(request)
|
|
207
|
+
return response
|
|
208
|
+
except grpc.RpcError as e:
|
|
209
|
+
print(f"Erro ao fazer a requisição gRPC GetAllUserStates: {e}")
|
|
125
210
|
return None
|
|
@@ -4,7 +4,7 @@ import os
|
|
|
4
4
|
import pika
|
|
5
5
|
from typing import Callable
|
|
6
6
|
from ..auth.credentials import Credential
|
|
7
|
-
from ..types.
|
|
7
|
+
from ..types.request_types import UserCall, UserState
|
|
8
8
|
from rich.console import Console
|
|
9
9
|
from rich.table import Table
|
|
10
10
|
from rich.text import Text
|
|
@@ -146,16 +146,8 @@ class MessageConsumer:
|
|
|
146
146
|
message = body.decode()
|
|
147
147
|
message_json = json.loads(message)
|
|
148
148
|
pure_message = self.__transform_message(message_json)
|
|
149
|
-
|
|
149
|
+
process_message(pure_message)
|
|
150
150
|
|
|
151
|
-
ch.basic_publish(
|
|
152
|
-
exchange='',
|
|
153
|
-
routing_key=props.reply_to,
|
|
154
|
-
properties=pika.BasicProperties(
|
|
155
|
-
correlation_id=props.correlation_id
|
|
156
|
-
),
|
|
157
|
-
body=str(response),
|
|
158
|
-
)
|
|
159
151
|
ch.basic_ack(delivery_tag=method.delivery_tag)
|
|
160
152
|
|
|
161
153
|
def __transform_message(self, message: dict) -> UserCall:
|
|
@@ -170,6 +162,10 @@ class MessageConsumer:
|
|
|
170
162
|
"""
|
|
171
163
|
|
|
172
164
|
user_state = message.get('user_state', {})
|
|
165
|
+
obs = user_state.get('obs', {})
|
|
166
|
+
if isinstance(obs, str):
|
|
167
|
+
obs = json.loads(obs)
|
|
168
|
+
|
|
173
169
|
return UserCall(
|
|
174
170
|
type=message.get('type', ''),
|
|
175
171
|
text=message.get('text', ''),
|
|
@@ -178,7 +174,7 @@ class MessageConsumer:
|
|
|
178
174
|
menu=user_state.get('menu', ''),
|
|
179
175
|
route=user_state.get('route', ''),
|
|
180
176
|
lst_update=user_state.get('lst_update', ''),
|
|
181
|
-
obs=
|
|
177
|
+
obs=obs,
|
|
182
178
|
),
|
|
183
179
|
channel=message.get('channel', ''),
|
|
184
180
|
customer_phone=message.get('customer_phone', ''),
|
chatgraph/pb/userstate.proto
CHANGED
|
@@ -9,6 +9,11 @@ service UserStateService {
|
|
|
9
9
|
rpc InsertUserState(UserState) returns (RequestStatus);
|
|
10
10
|
rpc UpdateUserState(UserState) returns (RequestStatus);
|
|
11
11
|
rpc DeleteUserState(UserStateId) returns (RequestStatus);
|
|
12
|
+
|
|
13
|
+
rpc GetAllUserStates(Void) returns (UserStatesList);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
message Void {
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
message UserState {
|
|
@@ -17,6 +22,7 @@ message UserState {
|
|
|
17
22
|
string route = 3;
|
|
18
23
|
string obs = 4;
|
|
19
24
|
string date = 5;
|
|
25
|
+
string direction = 6;
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
message UserStateId {
|
|
@@ -26,4 +32,8 @@ message UserStateId {
|
|
|
26
32
|
message RequestStatus {
|
|
27
33
|
bool status = 1;
|
|
28
34
|
string message = 2;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
message UserStatesList {
|
|
38
|
+
repeated UserState user_states = 1;
|
|
29
39
|
}
|
chatgraph/pb/userstate_pb2.py
CHANGED
|
@@ -24,7 +24,7 @@ _sym_db = _symbol_database.Default()
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0fuserstate.proto\x12\tuserstate\"
|
|
27
|
+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0fuserstate.proto\x12\tuserstate\"\x06\n\x04Void\"j\n\tUserState\x12\x0f\n\x07user_id\x18\x01 \x01(\t\x12\x0f\n\x07menu_id\x18\x02 \x01(\t\x12\r\n\x05route\x18\x03 \x01(\t\x12\x0b\n\x03obs\x18\x04 \x01(\t\x12\x0c\n\x04\x64\x61te\x18\x05 \x01(\t\x12\x11\n\tdirection\x18\x06 \x01(\t\"\x1e\n\x0bUserStateId\x12\x0f\n\x07user_id\x18\x01 \x01(\t\"0\n\rRequestStatus\x12\x0e\n\x06status\x18\x01 \x01(\x08\x12\x0f\n\x07message\x18\x02 \x01(\t\";\n\x0eUserStatesList\x12)\n\x0buser_states\x18\x01 \x03(\x0b\x32\x14.userstate.UserState2\xde\x02\n\x10UserStateService\x12?\n\x0fSelectUserState\x12\x16.userstate.UserStateId\x1a\x14.userstate.UserState\x12\x41\n\x0fInsertUserState\x12\x14.userstate.UserState\x1a\x18.userstate.RequestStatus\x12\x41\n\x0fUpdateUserState\x12\x14.userstate.UserState\x1a\x18.userstate.RequestStatus\x12\x43\n\x0f\x44\x65leteUserState\x12\x16.userstate.UserStateId\x1a\x18.userstate.RequestStatus\x12>\n\x10GetAllUserStates\x12\x0f.userstate.Void\x1a\x19.userstate.UserStatesListB\x10Z\x0e./pb/userstateb\x06proto3')
|
|
28
28
|
|
|
29
29
|
_globals = globals()
|
|
30
30
|
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
|
|
@@ -32,12 +32,16 @@ _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'userstate_pb2', _globals)
|
|
|
32
32
|
if not _descriptor._USE_C_DESCRIPTORS:
|
|
33
33
|
_globals['DESCRIPTOR']._loaded_options = None
|
|
34
34
|
_globals['DESCRIPTOR']._serialized_options = b'Z\016./pb/userstate'
|
|
35
|
-
_globals['
|
|
36
|
-
_globals['
|
|
37
|
-
_globals['
|
|
38
|
-
_globals['
|
|
39
|
-
_globals['
|
|
40
|
-
_globals['
|
|
41
|
-
_globals['
|
|
42
|
-
_globals['
|
|
35
|
+
_globals['_VOID']._serialized_start=30
|
|
36
|
+
_globals['_VOID']._serialized_end=36
|
|
37
|
+
_globals['_USERSTATE']._serialized_start=38
|
|
38
|
+
_globals['_USERSTATE']._serialized_end=144
|
|
39
|
+
_globals['_USERSTATEID']._serialized_start=146
|
|
40
|
+
_globals['_USERSTATEID']._serialized_end=176
|
|
41
|
+
_globals['_REQUESTSTATUS']._serialized_start=178
|
|
42
|
+
_globals['_REQUESTSTATUS']._serialized_end=226
|
|
43
|
+
_globals['_USERSTATESLIST']._serialized_start=228
|
|
44
|
+
_globals['_USERSTATESLIST']._serialized_end=287
|
|
45
|
+
_globals['_USERSTATESERVICE']._serialized_start=290
|
|
46
|
+
_globals['_USERSTATESERVICE']._serialized_end=640
|
|
43
47
|
# @@protoc_insertion_point(module_scope)
|
|
@@ -5,7 +5,7 @@ import warnings
|
|
|
5
5
|
|
|
6
6
|
import chatgraph.pb.userstate_pb2 as userstate__pb2
|
|
7
7
|
|
|
8
|
-
GRPC_GENERATED_VERSION = '1.
|
|
8
|
+
GRPC_GENERATED_VERSION = '1.67.0'
|
|
9
9
|
GRPC_VERSION = grpc.__version__
|
|
10
10
|
_version_not_supported = False
|
|
11
11
|
|
|
@@ -54,6 +54,11 @@ class UserStateServiceStub(object):
|
|
|
54
54
|
request_serializer=userstate__pb2.UserStateId.SerializeToString,
|
|
55
55
|
response_deserializer=userstate__pb2.RequestStatus.FromString,
|
|
56
56
|
_registered_method=True)
|
|
57
|
+
self.GetAllUserStates = channel.unary_unary(
|
|
58
|
+
'/userstate.UserStateService/GetAllUserStates',
|
|
59
|
+
request_serializer=userstate__pb2.Void.SerializeToString,
|
|
60
|
+
response_deserializer=userstate__pb2.UserStatesList.FromString,
|
|
61
|
+
_registered_method=True)
|
|
57
62
|
|
|
58
63
|
|
|
59
64
|
class UserStateServiceServicer(object):
|
|
@@ -83,6 +88,12 @@ class UserStateServiceServicer(object):
|
|
|
83
88
|
context.set_details('Method not implemented!')
|
|
84
89
|
raise NotImplementedError('Method not implemented!')
|
|
85
90
|
|
|
91
|
+
def GetAllUserStates(self, request, context):
|
|
92
|
+
"""Missing associated documentation comment in .proto file."""
|
|
93
|
+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
|
94
|
+
context.set_details('Method not implemented!')
|
|
95
|
+
raise NotImplementedError('Method not implemented!')
|
|
96
|
+
|
|
86
97
|
|
|
87
98
|
def add_UserStateServiceServicer_to_server(servicer, server):
|
|
88
99
|
rpc_method_handlers = {
|
|
@@ -106,6 +117,11 @@ def add_UserStateServiceServicer_to_server(servicer, server):
|
|
|
106
117
|
request_deserializer=userstate__pb2.UserStateId.FromString,
|
|
107
118
|
response_serializer=userstate__pb2.RequestStatus.SerializeToString,
|
|
108
119
|
),
|
|
120
|
+
'GetAllUserStates': grpc.unary_unary_rpc_method_handler(
|
|
121
|
+
servicer.GetAllUserStates,
|
|
122
|
+
request_deserializer=userstate__pb2.Void.FromString,
|
|
123
|
+
response_serializer=userstate__pb2.UserStatesList.SerializeToString,
|
|
124
|
+
),
|
|
109
125
|
}
|
|
110
126
|
generic_handler = grpc.method_handlers_generic_handler(
|
|
111
127
|
'userstate.UserStateService', rpc_method_handlers)
|
|
@@ -224,3 +240,30 @@ class UserStateService(object):
|
|
|
224
240
|
timeout,
|
|
225
241
|
metadata,
|
|
226
242
|
_registered_method=True)
|
|
243
|
+
|
|
244
|
+
@staticmethod
|
|
245
|
+
def GetAllUserStates(request,
|
|
246
|
+
target,
|
|
247
|
+
options=(),
|
|
248
|
+
channel_credentials=None,
|
|
249
|
+
call_credentials=None,
|
|
250
|
+
insecure=False,
|
|
251
|
+
compression=None,
|
|
252
|
+
wait_for_ready=None,
|
|
253
|
+
timeout=None,
|
|
254
|
+
metadata=None):
|
|
255
|
+
return grpc.experimental.unary_unary(
|
|
256
|
+
request,
|
|
257
|
+
target,
|
|
258
|
+
'/userstate.UserStateService/GetAllUserStates',
|
|
259
|
+
userstate__pb2.Void.SerializeToString,
|
|
260
|
+
userstate__pb2.UserStatesList.FromString,
|
|
261
|
+
options,
|
|
262
|
+
channel_credentials,
|
|
263
|
+
insecure,
|
|
264
|
+
call_credentials,
|
|
265
|
+
compression,
|
|
266
|
+
wait_for_ready,
|
|
267
|
+
timeout,
|
|
268
|
+
metadata,
|
|
269
|
+
_registered_method=True)
|