chatgraph 0.3.1__py3-none-any.whl → 0.3.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/__init__.py +6 -3
- chatgraph/bot/chatbot_model.py +28 -36
- chatgraph/cli/__init__.py +189 -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 -188
- chatgraph/types/request_types.py +265 -0
- chatgraph/types/route.py +4 -3
- chatgraph-0.3.2.dist-info/METADATA +326 -0
- chatgraph-0.3.2.dist-info/RECORD +24 -0
- chatgraph-0.3.2.dist-info/entry_points.txt +3 -0
- chatgraph/types/output_state.py +0 -138
- chatgraph-0.3.1.dist-info/METADATA +0 -146
- chatgraph-0.3.1.dist-info/RECORD +0 -21
- {chatgraph-0.3.1.dist-info → chatgraph-0.3.2.dist-info}/LICENSE +0 -0
- {chatgraph-0.3.1.dist-info → chatgraph-0.3.2.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
|
|
|
@@ -140,16 +141,33 @@ class ChatbotApp:
|
|
|
140
141
|
kwargs[route_state_name] = Route(route, list(self.__routes.keys()))
|
|
141
142
|
|
|
142
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)
|
|
143
148
|
|
|
149
|
+
def __process_func_response(self, userCall_response, userCall: UserCall):
|
|
150
|
+
|
|
144
151
|
if isinstance(userCall_response, (str, float, int)):
|
|
145
|
-
|
|
152
|
+
userCall.send(Message(text=userCall_response))
|
|
153
|
+
return
|
|
146
154
|
|
|
147
|
-
elif isinstance(userCall_response,
|
|
148
|
-
|
|
149
|
-
return
|
|
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
|
|
150
163
|
|
|
151
|
-
elif isinstance(userCall_response,
|
|
152
|
-
|
|
164
|
+
elif isinstance(userCall_response, EndChatResponse):
|
|
165
|
+
userCall.end_chat(userCall_response.obersevations, userCall_response.tabulation_id)
|
|
166
|
+
return
|
|
167
|
+
|
|
168
|
+
elif isinstance(userCall_response, TransferToHuman):
|
|
169
|
+
userCall.transfer_to_human(userCall_response.observations, userCall_response.campaign_id)
|
|
170
|
+
return
|
|
153
171
|
|
|
154
172
|
elif isinstance(userCall_response, RedirectResponse):
|
|
155
173
|
route = self.__adjust_route(userCall_response.route, route)
|
|
@@ -157,7 +175,7 @@ class ChatbotApp:
|
|
|
157
175
|
return self.process_message(userCall)
|
|
158
176
|
|
|
159
177
|
elif not userCall_response:
|
|
160
|
-
return
|
|
178
|
+
return
|
|
161
179
|
|
|
162
180
|
else:
|
|
163
181
|
error('Tipo de retorno inválido!')
|
|
@@ -181,30 +199,4 @@ class ChatbotApp:
|
|
|
181
199
|
if 'start' not in route:
|
|
182
200
|
route = absolute_route + route
|
|
183
201
|
|
|
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)
|
|
202
|
+
return route
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
from rich.console import Console
|
|
3
|
+
from rich.table import Table
|
|
4
|
+
from rich.text import Text
|
|
5
|
+
from rich.panel import Panel
|
|
6
|
+
from dotenv import load_dotenv
|
|
7
|
+
from ..gRPC.gRPCCall import WhatsappServiceClient, UserStateServiceClient
|
|
8
|
+
import os, re
|
|
9
|
+
|
|
10
|
+
load_dotenv()
|
|
11
|
+
app = typer.Typer()
|
|
12
|
+
|
|
13
|
+
@app.command()
|
|
14
|
+
def configs():
|
|
15
|
+
"""Recupera os IDs necessários."""
|
|
16
|
+
console = Console()
|
|
17
|
+
|
|
18
|
+
username = os.getenv('RABBIT_USER')
|
|
19
|
+
password = os.getenv('RABBIT_PASS')
|
|
20
|
+
url = os.getenv('RABBIT_URI')
|
|
21
|
+
queue = os.getenv('RABBIT_QUEUE')
|
|
22
|
+
prefetch = os.getenv('RABBIT_PREFETCH', 1)
|
|
23
|
+
vhost = os.getenv('RABBIT_VHOST', '/')
|
|
24
|
+
grpc = os.getenv('GRPC_URI')
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
tableRabbit = Table(show_header=True, header_style="bold magenta", title="RabbitMQ Consumer")
|
|
28
|
+
tableRabbit.add_column("Atributo", justify="center", style="cyan", no_wrap=True)
|
|
29
|
+
tableRabbit.add_column("Valor", justify="center", style="magenta")
|
|
30
|
+
|
|
31
|
+
tableRabbit.add_row("Virtual Host", vhost)
|
|
32
|
+
tableRabbit.add_row("Prefetch Count", str(prefetch))
|
|
33
|
+
tableRabbit.add_row("Queue Consume", queue)
|
|
34
|
+
tableRabbit.add_row("AMQP URL", url)
|
|
35
|
+
tableRabbit.add_row("Username", username)
|
|
36
|
+
tableRabbit.add_row("Password", "******")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
tableGRPC = Table(show_header=True, header_style="bold magenta", title="gRPC Consumer")
|
|
40
|
+
tableGRPC.add_column("Atributo", justify="center", style="cyan", no_wrap=True)
|
|
41
|
+
tableGRPC.add_column("Valor", justify="center", style="magenta")
|
|
42
|
+
|
|
43
|
+
tableGRPC.add_row("URI", grpc)
|
|
44
|
+
|
|
45
|
+
console.print(tableGRPC, justify="center")
|
|
46
|
+
console.print(tableRabbit, justify="center")
|
|
47
|
+
|
|
48
|
+
@app.command()
|
|
49
|
+
def campaigns(regex: str = typer.Option(None, "--regex", "-r", help="Filtro regex para campanhas.")):
|
|
50
|
+
"""Recupera as campanhas cadastradas."""
|
|
51
|
+
grpc = os.getenv('GRPC_URI')
|
|
52
|
+
|
|
53
|
+
wwp = WhatsappServiceClient(grpc)
|
|
54
|
+
campaigns = wwp.get_all_campaigns()
|
|
55
|
+
|
|
56
|
+
console = Console()
|
|
57
|
+
tableGRPC = Table(show_header=True, header_style="bold magenta", title="Campaigns")
|
|
58
|
+
tableGRPC.add_column("campaign_id", justify="center", style="cyan", no_wrap=True)
|
|
59
|
+
tableGRPC.add_column("campaign_name", justify="center", style="magenta")
|
|
60
|
+
tableGRPC.add_column("last_update", justify="center", style="magenta")
|
|
61
|
+
|
|
62
|
+
# Aplicar filtro de regex, se fornecido
|
|
63
|
+
filtered_campaigns = campaigns.campaigns
|
|
64
|
+
if regex:
|
|
65
|
+
pattern = re.compile(regex)
|
|
66
|
+
filtered_campaigns = [
|
|
67
|
+
campaign for campaign in campaigns.campaigns
|
|
68
|
+
if pattern.search(campaign.campaign_name)
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
for campaign in filtered_campaigns:
|
|
72
|
+
tableGRPC.add_row(campaign.campaign_id, campaign.campaign_name, campaign.last_update)
|
|
73
|
+
|
|
74
|
+
console.print(tableGRPC, justify="center")
|
|
75
|
+
|
|
76
|
+
@app.command()
|
|
77
|
+
def tabulations(
|
|
78
|
+
regex: str = typer.Option(None, "--regex", "-r", help="Filtro regex para as tabulações.")
|
|
79
|
+
):
|
|
80
|
+
"""Recupera as tabulações cadastradas."""
|
|
81
|
+
grpc = os.getenv('GRPC_URI')
|
|
82
|
+
|
|
83
|
+
wwp = WhatsappServiceClient(grpc)
|
|
84
|
+
tabulations = wwp.get_all_tabulations()
|
|
85
|
+
|
|
86
|
+
console = Console()
|
|
87
|
+
tableGRPC = Table(show_header=True, header_style="bold magenta", title="Tabulations")
|
|
88
|
+
tableGRPC.add_column("tabulation_id", justify="center", style="cyan", no_wrap=True)
|
|
89
|
+
tableGRPC.add_column("tabulation_name", justify="center", style="magenta")
|
|
90
|
+
tableGRPC.add_column("tabulation_type", justify="center", style="magenta")
|
|
91
|
+
tableGRPC.add_column("group_name", justify="center", style="magenta")
|
|
92
|
+
tableGRPC.add_column("customer_service_survey_id", justify="center", style="magenta")
|
|
93
|
+
tableGRPC.add_column("last_update", justify="center", style="magenta")
|
|
94
|
+
|
|
95
|
+
# Aplicar filtro de regex, se fornecido
|
|
96
|
+
filtered_tabulations = tabulations.tabulations
|
|
97
|
+
if regex:
|
|
98
|
+
pattern = re.compile(regex, re.IGNORECASE)
|
|
99
|
+
filtered_tabulations = [
|
|
100
|
+
tabulation for tabulation in tabulations.tabulations
|
|
101
|
+
if (
|
|
102
|
+
pattern.search(tabulation.tabulation_id) or
|
|
103
|
+
pattern.search(tabulation.tabulation_name) or
|
|
104
|
+
pattern.search(tabulation.tabulation_type) or
|
|
105
|
+
pattern.search(tabulation.group_name) or
|
|
106
|
+
(tabulation.customer_service_survey_id and pattern.search(tabulation.customer_service_survey_id)) or
|
|
107
|
+
pattern.search(tabulation.last_update)
|
|
108
|
+
)
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
for tabulation in filtered_tabulations:
|
|
112
|
+
tableGRPC.add_row(
|
|
113
|
+
tabulation.tabulation_id,
|
|
114
|
+
tabulation.tabulation_name,
|
|
115
|
+
tabulation.tabulation_type,
|
|
116
|
+
tabulation.group_name,
|
|
117
|
+
tabulation.customer_service_survey_id or "N/A",
|
|
118
|
+
tabulation.last_update,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
console.print(tableGRPC, justify="center")
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@app.command("ustate")
|
|
125
|
+
def user_state(
|
|
126
|
+
regex: str = typer.Option(None, "--regex", "-r", help="Filtro regex para os estados do usuário.")
|
|
127
|
+
):
|
|
128
|
+
"""Recupera os UserState em operação no momento."""
|
|
129
|
+
grpc = os.getenv('GRPC_URI')
|
|
130
|
+
|
|
131
|
+
ustate = UserStateServiceClient(grpc)
|
|
132
|
+
userstates = ustate.get_all_user_states()
|
|
133
|
+
|
|
134
|
+
console = Console()
|
|
135
|
+
tableGRPC = Table(show_header=True, header_style="bold magenta", title="User States")
|
|
136
|
+
tableGRPC.add_column("user_id", justify="center", style="cyan", no_wrap=True)
|
|
137
|
+
tableGRPC.add_column("menu_id", justify="center", style="magenta")
|
|
138
|
+
tableGRPC.add_column("route", justify="center", style="magenta")
|
|
139
|
+
tableGRPC.add_column("obs", justify="center", style="magenta")
|
|
140
|
+
tableGRPC.add_column("date", justify="center", style="magenta")
|
|
141
|
+
tableGRPC.add_column("direction", justify="center", style="magenta")
|
|
142
|
+
|
|
143
|
+
# Aplicar filtro de regex, se fornecido
|
|
144
|
+
filtered_user_states = userstates.user_states
|
|
145
|
+
if regex:
|
|
146
|
+
pattern = re.compile(regex, re.IGNORECASE)
|
|
147
|
+
filtered_user_states = [
|
|
148
|
+
userstate for userstate in userstates.user_states
|
|
149
|
+
if (
|
|
150
|
+
pattern.search(userstate.user_id) or
|
|
151
|
+
pattern.search(userstate.menu_id) or
|
|
152
|
+
pattern.search(userstate.route) or
|
|
153
|
+
pattern.search(userstate.obs) or
|
|
154
|
+
pattern.search(userstate.date) or
|
|
155
|
+
pattern.search(str(userstate.direction))
|
|
156
|
+
)
|
|
157
|
+
]
|
|
158
|
+
|
|
159
|
+
for userstate in filtered_user_states:
|
|
160
|
+
tableGRPC.add_row(
|
|
161
|
+
userstate.user_id,
|
|
162
|
+
userstate.menu_id,
|
|
163
|
+
userstate.route,
|
|
164
|
+
userstate.obs,
|
|
165
|
+
userstate.date,
|
|
166
|
+
str(userstate.direction),
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
console.print(tableGRPC, justify="center")
|
|
170
|
+
|
|
171
|
+
@app.command("del-ustate")
|
|
172
|
+
def delete_user_state(user_id: str = typer.Argument(..., help="ID do UserState a ser deletado.")):
|
|
173
|
+
"""Deleta um UserState em operação no momento."""
|
|
174
|
+
grpc = os.getenv('GRPC_URI')
|
|
175
|
+
|
|
176
|
+
ustate = UserStateServiceClient(grpc)
|
|
177
|
+
|
|
178
|
+
# Chama o método para deletar o UserState usando o ID fornecido
|
|
179
|
+
try:
|
|
180
|
+
success = ustate.delete_user_state(user_id)
|
|
181
|
+
if success:
|
|
182
|
+
typer.echo(f"UserState com ID '{user_id}' deletado com sucesso.")
|
|
183
|
+
else:
|
|
184
|
+
typer.echo(f"Falha ao deletar UserState com ID '{user_id}'.", err=True)
|
|
185
|
+
except Exception as e:
|
|
186
|
+
typer.echo(f"Erro ao tentar deletar UserState: {e}", err=True)
|
|
187
|
+
|
|
188
|
+
def main():
|
|
189
|
+
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)
|
chatgraph/pb/voll.proto
CHANGED
|
@@ -8,6 +8,19 @@ service MessageService {
|
|
|
8
8
|
rpc SendButton(MessageRequest) returns (MessageResponse);
|
|
9
9
|
rpc SendList(MessageRequest) returns (MessageResponse);
|
|
10
10
|
rpc SendText(MessageRequest) returns (MessageResponse);
|
|
11
|
+
rpc TransferToHuman(MessageRequest) returns (MessageResponse);
|
|
12
|
+
rpc EndChat(MessageRequest) returns (MessageResponse);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
service ActionsService {
|
|
16
|
+
rpc GetCampaignID(CampaignName) returns (CampaignDetails);
|
|
17
|
+
rpc GetCampaignsList(Void) returns (CampaignsList);
|
|
18
|
+
|
|
19
|
+
rpc GetTabulationID(TabulationName) returns (TabulationDetails);
|
|
20
|
+
rpc GetTabulationsList(Void) returns (TabulationsList);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
message Void {
|
|
11
24
|
}
|
|
12
25
|
|
|
13
26
|
message MessageRequest {
|
|
@@ -16,9 +29,12 @@ message MessageRequest {
|
|
|
16
29
|
string unique_customer_id = 3;
|
|
17
30
|
string message_title = 4;
|
|
18
31
|
string message_text = 5;
|
|
19
|
-
string
|
|
20
|
-
string
|
|
21
|
-
|
|
32
|
+
string platform = 6;
|
|
33
|
+
string message_caption = 7;
|
|
34
|
+
string button_title = 8;
|
|
35
|
+
string campaign_name = 9;
|
|
36
|
+
string tabulation_name = 10;
|
|
37
|
+
repeated QuickOption options = 11;
|
|
22
38
|
}
|
|
23
39
|
|
|
24
40
|
message MessageResponse {
|
|
@@ -29,4 +45,45 @@ message MessageResponse {
|
|
|
29
45
|
message QuickOption {
|
|
30
46
|
string title = 1;
|
|
31
47
|
string description = 2;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
message CampaignName {
|
|
51
|
+
string campaign_name = 1;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
message TabulationName {
|
|
55
|
+
string tabulation_name = 1;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
message CampaignDetails{
|
|
59
|
+
string campaign_name = 1;
|
|
60
|
+
string campaign_id = 2;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
message CampaignElement{
|
|
64
|
+
string campaign_id = 1;
|
|
65
|
+
string campaign_name = 2;
|
|
66
|
+
string last_update = 3;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
message CampaignsList{
|
|
70
|
+
repeated CampaignElement campaigns = 1;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
message TabulationDetails{
|
|
74
|
+
string tabulation_name = 1;
|
|
75
|
+
string tabulation_id = 2;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
message TabulationElement{
|
|
79
|
+
string tabulation_id = 1;
|
|
80
|
+
string tabulation_name = 2;
|
|
81
|
+
string tabulation_type = 3;
|
|
82
|
+
string group_name = 4;
|
|
83
|
+
string customer_service_survey_id = 5;
|
|
84
|
+
string last_update = 6;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
message TabulationsList{
|
|
88
|
+
repeated TabulationElement tabulations = 1;
|
|
32
89
|
}
|