chatgraph 0.3.16__tar.gz → 0.5.0__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.

Files changed (30) hide show
  1. {chatgraph-0.3.16 → chatgraph-0.5.0}/PKG-INFO +3 -1
  2. {chatgraph-0.3.16 → chatgraph-0.5.0}/chatgraph/__init__.py +4 -3
  3. {chatgraph-0.3.16 → chatgraph-0.5.0}/chatgraph/bot/chatbot_model.py +16 -26
  4. {chatgraph-0.3.16 → chatgraph-0.5.0}/chatgraph/bot/chatbot_router.py +16 -20
  5. chatgraph-0.5.0/chatgraph/gRPC/gRPCCall.py +126 -0
  6. chatgraph-0.5.0/chatgraph/messages/message_consumer.py +150 -0
  7. chatgraph-0.5.0/chatgraph/pb/router.proto +127 -0
  8. chatgraph-0.5.0/chatgraph/pb/router_pb2.py +77 -0
  9. chatgraph-0.5.0/chatgraph/pb/router_pb2_grpc.py +669 -0
  10. chatgraph-0.5.0/chatgraph/types/message_types.py +111 -0
  11. chatgraph-0.5.0/chatgraph/types/request_types.py +294 -0
  12. {chatgraph-0.3.16 → chatgraph-0.5.0}/chatgraph/types/route.py +11 -4
  13. {chatgraph-0.3.16 → chatgraph-0.5.0}/pyproject.toml +3 -1
  14. chatgraph-0.3.16/chatgraph/gRPC/gRPCCall.py +0 -210
  15. chatgraph-0.3.16/chatgraph/messages/message_consumer.py +0 -214
  16. chatgraph-0.3.16/chatgraph/pb/userstate.proto +0 -41
  17. chatgraph-0.3.16/chatgraph/pb/userstate_pb2.py +0 -47
  18. chatgraph-0.3.16/chatgraph/pb/userstate_pb2_grpc.py +0 -269
  19. chatgraph-0.3.16/chatgraph/pb/voll.proto +0 -90
  20. chatgraph-0.3.16/chatgraph/pb/voll_pb2.py +0 -63
  21. chatgraph-0.3.16/chatgraph/pb/voll_pb2_grpc.py +0 -470
  22. chatgraph-0.3.16/chatgraph/types/message_types.py +0 -108
  23. chatgraph-0.3.16/chatgraph/types/request_types.py +0 -347
  24. {chatgraph-0.3.16 → chatgraph-0.5.0}/LICENSE +0 -0
  25. {chatgraph-0.3.16 → chatgraph-0.5.0}/README.md +0 -0
  26. {chatgraph-0.3.16 → chatgraph-0.5.0}/chatgraph/auth/credentials.py +0 -0
  27. {chatgraph-0.3.16 → chatgraph-0.5.0}/chatgraph/cli/__init__.py +0 -0
  28. {chatgraph-0.3.16 → chatgraph-0.5.0}/chatgraph/error/chatbot_error.py +0 -0
  29. {chatgraph-0.3.16 → chatgraph-0.5.0}/chatgraph/error/route_error.py +0 -0
  30. {chatgraph-0.3.16 → chatgraph-0.5.0}/chatgraph/types/end_types.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chatgraph
3
- Version: 0.3.16
3
+ Version: 0.5.0
4
4
  Summary: A user-friendly chatbot library
5
5
  Home-page: https://github.com/irissonnlima/chatgraph
6
6
  License: MIT
@@ -13,6 +13,8 @@ Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Requires-Dist: grpcio (>=1.67.0,<2.0.0)
15
15
  Requires-Dist: grpcio-tools (>=1.67.0,<2.0.0)
16
+ Requires-Dist: matplotlib (>=3.10.0,<4.0.0)
17
+ Requires-Dist: networkx (>=3.4.2,<4.0.0)
16
18
  Requires-Dist: pika (>=1.3.2,<2.0.0)
17
19
  Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
18
20
  Requires-Dist: rich (>=13.8.1,<14.0.0)
@@ -2,9 +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.request_types import UserCall, UserState
5
+ from .types.request_types import UserCall, UserState, ChatID
6
6
  from .types.end_types import RedirectResponse, EndChatResponse, TransferToHuman
7
- from .types.message_types import Message, Button, ListElements
7
+ from .types.message_types import Message, Button
8
8
  from .types.route import Route
9
9
 
10
10
  __all__ = [
@@ -18,8 +18,9 @@ __all__ = [
18
18
  'Route',
19
19
  'EndChatResponse',
20
20
  'TransferToHuman',
21
+ 'ChatID',
21
22
  'UserState',
22
23
  'Message',
23
24
  'Button',
24
- 'ListElements'
25
+
25
26
  ]
@@ -2,12 +2,13 @@ import inspect
2
2
  from functools import wraps
3
3
  from logging import debug
4
4
  import json
5
+ import asyncio
5
6
  from logging import error
6
7
 
7
- from ..error.chatbot_error import ChatbotError, ChatbotMessageError
8
+ from ..error.chatbot_error import ChatbotMessageError
8
9
  from ..messages.message_consumer import MessageConsumer
9
10
  from ..types.request_types import UserCall
10
- from ..types.message_types import messageTypes, Message, Button, ListElements
11
+ from ..types.message_types import Message, Button
11
12
  from ..types.end_types import RedirectResponse, EndChatResponse, TransferToHuman
12
13
  from ..types.route import Route
13
14
  from .chatbot_router import ChatbotRouter
@@ -31,7 +32,7 @@ class ChatbotApp:
31
32
  self.__message_consumer = message_consumer
32
33
  self.__routes = {}
33
34
 
34
- def include_router(self, router: ChatbotRouter, prefix: str):
35
+ def include_router(self, router: ChatbotRouter):
35
36
  """
36
37
  Inclui um roteador de chatbot com um prefixo nas rotas da aplicação.
37
38
 
@@ -42,18 +43,7 @@ class ChatbotApp:
42
43
  Raises:
43
44
  ChatbotError: Se a rota 'start' não for encontrada no roteador.
44
45
  """
45
- if 'start' not in router.routes.keys():
46
- raise ChatbotError('Erro ao incluir rota, start não encontrado!')
47
-
48
- prefixed_routes = {
49
- (
50
- f'start{prefix.lower()}'
51
- if key.lower() == 'start'
52
- else f'start{prefix.lower()}{key.lower().replace("start", "")}'
53
- ): value
54
- for key, value in router.routes.items()
55
- }
56
- self.__routes.update(prefixed_routes)
46
+ self.__routes.update(router.routes)
57
47
 
58
48
  def route(self, route_name: str):
59
49
  """
@@ -67,9 +57,6 @@ class ChatbotApp:
67
57
  """
68
58
  route_name = route_name.strip().lower()
69
59
 
70
- if 'start' not in route_name:
71
- route_name = f'start{route_name}'
72
-
73
60
  def decorator(func):
74
61
  params = dict()
75
62
  signature = inspect.signature(func)
@@ -102,8 +89,10 @@ class ChatbotApp:
102
89
  """
103
90
  Inicia o consumo de mensagens pelo chatbot, processando cada mensagem recebida.
104
91
  """
92
+
93
+
105
94
  self.__message_consumer.reprer()
106
- self.__message_consumer.start_consume(self.process_message)
95
+ asyncio.run(self.__message_consumer.start_consume(self.process_message))
107
96
 
108
97
  def process_message(self, userCall: UserCall):
109
98
  """
@@ -119,15 +108,16 @@ class ChatbotApp:
119
108
  Returns:
120
109
  str: A resposta gerada pela função da rota, que pode ser uma mensagem ou o resultado de uma redireção.
121
110
  """
122
- customer_id = userCall.customer_id
111
+ user_id = userCall.user_id
123
112
  route = userCall.route.lower()
113
+ route_handler = route.split('.')[-1]
124
114
  menu = userCall.menu.lower()
125
- obs = userCall.obs
126
- handler = self.__routes.get(route, None)
115
+ observation = userCall.observation
116
+ handler = self.__routes.get(route_handler, None)
127
117
 
128
118
  if not handler:
129
119
  raise ChatbotMessageError(
130
- customer_id, f'Rota não encontrada para {route}!'
120
+ user_id, f'Rota não encontrada para {route}!'
131
121
  )
132
122
 
133
123
  func = handler['function']
@@ -151,14 +141,14 @@ class ChatbotApp:
151
141
  def __process_func_response(self, userCall_response, userCall: UserCall, route: str):
152
142
 
153
143
  if isinstance(userCall_response, (str, float, int)):
154
- userCall.send(Message(text=userCall_response))
144
+ userCall.send(Message(userCall_response))
155
145
  return
156
146
 
157
147
  elif isinstance(userCall_response, Route):
158
148
  userCall.route = userCall_response.current
159
149
  return
160
150
 
161
- elif isinstance(userCall_response, (Message, Button, ListElements)):
151
+ elif isinstance(userCall_response, (Message, Button)):
162
152
  userCall.send(userCall_response)
163
153
 
164
154
  return
@@ -172,7 +162,7 @@ class ChatbotApp:
172
162
  return
173
163
 
174
164
  elif isinstance(userCall_response, RedirectResponse):
175
- route = self.__adjust_route(userCall_response.route, route)
165
+ route = route + '.' + userCall_response.route
176
166
  userCall.route = route
177
167
  return self.process_message(userCall)
178
168
 
@@ -18,7 +18,17 @@ class ChatbotRouter:
18
18
  """
19
19
  Inicializa a classe ChatbotRouter com um dicionário vazio de rotas.
20
20
  """
21
- self.routes = {}
21
+ self.__routes = {}
22
+
23
+ @property
24
+ def routes(self):
25
+ """
26
+ Retorna as rotas registradas no roteador.
27
+
28
+ Returns:
29
+ dict: Um dicionário contendo as rotas e funções associadas.
30
+ """
31
+ return self.__routes
22
32
 
23
33
  def route(self, route_name: str):
24
34
  """
@@ -30,15 +40,14 @@ class ChatbotRouter:
30
40
  Returns:
31
41
  function: O decorador que adiciona a função à rota especificada.
32
42
  """
33
- if 'start' not in route_name:
34
- route_name = f'start{route_name}'
43
+
44
+ route_name = route_name.strip().lower()
35
45
 
36
46
  def decorator(func):
37
47
  params = dict()
38
48
  signature = inspect.signature(func)
39
49
  output_param = signature.return_annotation
40
50
 
41
- # Itera sobre os parâmetros da função e extrai seus tipos
42
51
  for name, param in signature.parameters.items():
43
52
  param_type = (
44
53
  param.annotation
@@ -48,8 +57,7 @@ class ChatbotRouter:
48
57
  params[param_type] = name
49
58
  debug(f'Parameter: {name}, Type: {param_type}')
50
59
 
51
- # Adiciona a função e seus parâmetros à rota especificada
52
- self.routes[route_name.strip().lower()] = {
60
+ self.__routes[route_name] = {
53
61
  'function': func,
54
62
  'params': params,
55
63
  'return': output_param,
@@ -63,7 +71,7 @@ class ChatbotRouter:
63
71
 
64
72
  return decorator
65
73
 
66
- def include_router(self, router: 'ChatbotRouter', prefix: str):
74
+ def include_router(self, router: 'ChatbotRouter'):
67
75
  """
68
76
  Inclui outro roteador com um prefixo nas rotas do roteador atual.
69
77
 
@@ -74,16 +82,4 @@ class ChatbotRouter:
74
82
  Raises:
75
83
  ChatbotError: Se a rota 'start' não for encontrada no roteador fornecido.
76
84
  """
77
- if 'start' not in router.routes.keys():
78
- raise ChatbotError('Erro ao incluir rota, start não encontrado!')
79
-
80
- # Adiciona prefixo às rotas do roteador incluído
81
- prefixed_routes = {
82
- (
83
- f'{prefix.lower()}'
84
- if key.lower() == 'start'
85
- else f'start{prefix.lower()}{key.lower().replace("start", "")}'
86
- ): value
87
- for key, value in router.routes.items()
88
- }
89
- self.routes.update(prefixed_routes)
85
+ self.__routes.update(router.__routes)
@@ -0,0 +1,126 @@
1
+ import os
2
+ import grpc
3
+ import json
4
+
5
+ import chatgraph.pb.router_pb2 as chatbot_pb2
6
+ import chatgraph.pb.router_pb2_grpc as chatbot_pb2_grpc
7
+
8
+
9
+ class RouterServiceClient:
10
+ def __init__(self, grpc_uri=None):
11
+ self.grpc_uri = grpc_uri or os.getenv("GRPC_URI")
12
+
13
+ if not self.grpc_uri:
14
+ raise ValueError("A variável de ambiente 'GRPC_URI' não está definida.")
15
+
16
+ # Cria o canal gRPC
17
+ self.channel = grpc.insecure_channel(self.grpc_uri)
18
+
19
+ # Cria os stubs para os serviços gRPC
20
+ self.user_state_stub = chatbot_pb2_grpc.UserStateServiceStub(self.channel)
21
+ self.send_message_stub = chatbot_pb2_grpc.SendMessageStub(self.channel)
22
+ self.transfer_stub = chatbot_pb2_grpc.TransferStub(self.channel)
23
+ self.end_chat_stub = chatbot_pb2_grpc.EndChatStub(self.channel)
24
+
25
+ def insert_update_user_state(self, user_state_data):
26
+ request = chatbot_pb2.UserState(**user_state_data)
27
+ try:
28
+ response = self.user_state_stub.InsertUpdateUserState(request)
29
+ return response
30
+ except grpc.RpcError as e:
31
+ print(f"Erro ao chamar InsertUpdateUserState: {e}")
32
+ return None
33
+
34
+ def delete_user_state(self, chat_id_data):
35
+ request = chatbot_pb2.ChatID(**chat_id_data)
36
+ try:
37
+ response = self.user_state_stub.DeleteUserState(request)
38
+ return response
39
+ except grpc.RpcError as e:
40
+ print(f"Erro ao chamar DeleteUserState: {e}")
41
+ return None
42
+
43
+ def get_user_state(self, chat_id_data):
44
+ request = chatbot_pb2.ChatID(**chat_id_data)
45
+ try:
46
+ response = self.user_state_stub.GetUserState(request)
47
+ return response
48
+ except grpc.RpcError as e:
49
+ print(f"Erro ao chamar GetUserState: {e}")
50
+ return None
51
+
52
+ def send_message(self, message_data):
53
+ print(json.dumps(message_data))
54
+
55
+ request = chatbot_pb2.Message(**message_data)
56
+
57
+ try:
58
+ response = self.send_message_stub.SendMessage(request)
59
+ return response
60
+ except grpc.RpcError as e:
61
+ print(f"Erro ao chamar SendMessage: {e}")
62
+ return None
63
+
64
+ def transfer_to_human(self, transfer_request_data):
65
+ request = chatbot_pb2.TransferToHumanRequest(**transfer_request_data)
66
+ try:
67
+ response = self.transfer_stub.TransferToHuman(request)
68
+ return response
69
+ except grpc.RpcError as e:
70
+ print(f"Erro ao chamar TransferToHuman: {e}")
71
+ return None
72
+
73
+ def transfer_to_menu(self, transfer_request_data):
74
+ request = chatbot_pb2.TransferToMenuRequest(**transfer_request_data)
75
+ try:
76
+ response = self.transfer_stub.TransferToMenu(request)
77
+ return response
78
+ except grpc.RpcError as e:
79
+ print(f"Erro ao chamar TransferToMenu: {e}")
80
+ return None
81
+
82
+ def end_chat(self, end_chat_request_data):
83
+ request = chatbot_pb2.EndChatRequest(**end_chat_request_data)
84
+ try:
85
+ response = self.end_chat_stub.EndChat(request)
86
+ return response
87
+ except grpc.RpcError as e:
88
+ print(f"Erro ao chamar EndChat: {e}")
89
+ return None
90
+
91
+ def get_campaign_id(self, campaign_name):
92
+ request = chatbot_pb2.CampaignName(**campaign_name)
93
+ try:
94
+ response = self.transfer_stub.GetCampaignID(request)
95
+ print(response)
96
+ return response
97
+ except grpc.RpcError as e:
98
+ print(f"Erro ao chamar GetCampaignID: {e}")
99
+ return None
100
+
101
+ def get_all_campaigns(self):
102
+ request = chatbot_pb2.Void()
103
+ try:
104
+ response = self.transfer_stub.GetAllCampaigns(request)
105
+ return response
106
+ except grpc.RpcError as e:
107
+ print(f"Erro ao chamar GetAllCampaigns: {e}")
108
+ return None
109
+
110
+ def get_tabulation_id(self, tabulation_name):
111
+ request = chatbot_pb2.TabulationName(**tabulation_name)
112
+ try:
113
+ response = self.end_chat_stub.GetTabulationID(request)
114
+ return response
115
+ except grpc.RpcError as e:
116
+ print(f"Erro ao chamar GetTabulationID: {e}")
117
+ return None
118
+
119
+ def get_all_tabulations(self):
120
+ request = chatbot_pb2.Void()
121
+ try:
122
+ response = self.end_chat_stub.GetAllTabulations(request)
123
+ return response
124
+ except grpc.RpcError as e:
125
+ print(f"Erro ao chamar GetAllTabulations: {e}")
126
+ return None
@@ -0,0 +1,150 @@
1
+ import json
2
+ import asyncio
3
+ from logging import debug, info
4
+ import os
5
+ import aio_pika
6
+ from typing import Callable
7
+ from ..auth.credentials import Credential
8
+ from ..types.request_types import UserCall, UserState, ChatID
9
+ from rich.console import Console
10
+ from rich.table import Table
11
+ from rich.text import Text
12
+ from rich.panel import Panel
13
+ from urllib.parse import quote
14
+
15
+ class MessageConsumer:
16
+ def __init__(
17
+ self,
18
+ credential: Credential,
19
+ amqp_url: str,
20
+ grpc_uri: str,
21
+ queue_consume: str,
22
+ prefetch_count: int = 1,
23
+ virtual_host: str = "/",
24
+ ) -> None:
25
+ self.__virtual_host = virtual_host
26
+ self.__prefetch_count = prefetch_count
27
+ self.__queue_consume = queue_consume
28
+ self.__amqp_url = amqp_url
29
+ self.__grpc_uri = grpc_uri
30
+ self.__credentials = credential
31
+
32
+ @classmethod
33
+ def load_dotenv(
34
+ cls,
35
+ user_env: str = "RABBIT_USER",
36
+ pass_env: str = "RABBIT_PASS",
37
+ uri_env: str = "RABBIT_URI",
38
+ queue_env: str = "RABBIT_QUEUE",
39
+ prefetch_env: str = "RABBIT_PREFETCH",
40
+ vhost_env: str = "RABBIT_VHOST",
41
+ grpc_uri: str = "GRPC_URI",
42
+ ) -> "MessageConsumer":
43
+ username = os.getenv(user_env)
44
+ password = os.getenv(pass_env)
45
+ url = os.getenv(uri_env)
46
+ queue = os.getenv(queue_env)
47
+ prefetch = os.getenv(prefetch_env, 1)
48
+ vhost = os.getenv(vhost_env, "/")
49
+ grpc = os.getenv(grpc_uri)
50
+
51
+ if not username or not password or not url or not queue or not grpc:
52
+ raise ValueError("Corrija as variáveis de ambiente!")
53
+
54
+ return cls(
55
+ credential=Credential(username=username, password=password),
56
+ amqp_url=url,
57
+ queue_consume=queue,
58
+ prefetch_count=int(prefetch),
59
+ virtual_host=vhost,
60
+ grpc_uri=grpc,
61
+ )
62
+
63
+ async def start_consume(self, process_message: Callable):
64
+ try:
65
+ user = quote(self.__credentials.username)
66
+ pwd = quote(self.__credentials.password)
67
+ vhost = quote(self.__virtual_host)
68
+ uri = self.__amqp_url
69
+ amqp_url = f"amqp://{user}:{pwd}@{uri}/{vhost}"
70
+ connection = await aio_pika.connect_robust(amqp_url)
71
+
72
+ async with connection:
73
+ channel = await connection.channel()
74
+ await channel.set_qos(prefetch_count=self.__prefetch_count)
75
+
76
+ try:
77
+ queue = await channel.get_queue(self.__queue_consume, ensure=True)
78
+ except aio_pika.exceptions.ChannelNotFoundEntity:
79
+ arguments = {
80
+ "x-dead-letter-exchange": "log_error", # Dead Letter Exchange
81
+ "x-expires": 86400000, # Expiração da fila (em milissegundos)
82
+ "x-message-ttl": 300000 # Tempo de vida das mensagens (em milissegundos)
83
+ }
84
+ queue = await channel.declare_queue(self.__queue_consume, durable=True, arguments=arguments)
85
+
86
+ info("[x] Server inicializado! Aguardando solicitações RPC")
87
+
88
+ async for message in queue:
89
+ async with message.process():
90
+ await self.on_request(message.body, process_message)
91
+ except Exception as e:
92
+ print(f"Erro durante o consumo de mensagens: {e}")
93
+ # Reiniciar a conexão em caso de falha
94
+ # await self.start_consume(process_message)
95
+
96
+ async def on_request(self, body: bytes, process_message: Callable):
97
+ try:
98
+ message = body.decode()
99
+ message_json = json.loads(message)
100
+ pure_message = self.__transform_message(message_json)
101
+ await process_message(pure_message)
102
+ except Exception as e:
103
+ print(f"Erro ao processar mensagem: {e}")
104
+
105
+ def __transform_message(self, message: dict) -> UserCall:
106
+ user_state = message.get("user_state", {})
107
+ observation = user_state.get("observation", {})
108
+ if isinstance(observation, str):
109
+ observation = json.loads(observation)
110
+
111
+ usercall = UserCall(
112
+ user_state=UserState(
113
+ chatID=ChatID(
114
+ user_id=user_state['chat_id'].get("user_id", ""),
115
+ company_id=user_state['chat_id'].get("company_id", ""),
116
+ ),
117
+ menu=user_state.get("menu", ""),
118
+ route=user_state.get("route", ""),
119
+ protocol=user_state.get("protocol", ""),
120
+ observation=observation,
121
+ ),
122
+ type_message=message.get("type_message", ""),
123
+ content_message=message.get("content_message", ""),
124
+ grpc_uri=self.__grpc_uri,
125
+ )
126
+
127
+ return usercall
128
+
129
+ def reprer(self):
130
+ console = Console()
131
+
132
+ title_text = Text("ChatGraph", style="bold red", justify="center")
133
+ title_panel = Panel.fit(title_text, title=" ", border_style="bold red", padding=(1, 4))
134
+
135
+ separator = Text("🐇🐇🐇 RabbitMessageConsumer 📨📨📨", style="cyan", justify="center")
136
+
137
+ table = Table(show_header=True, header_style="bold magenta", title="RabbitMQ Consumer")
138
+ table.add_column("Atributo", justify="center", style="cyan", no_wrap=True)
139
+ table.add_column("Valor", justify="center", style="magenta")
140
+
141
+ table.add_row("Virtual Host", self.__virtual_host)
142
+ table.add_row("Prefetch Count", str(self.__prefetch_count))
143
+ table.add_row("Queue Consume", self.__queue_consume)
144
+ table.add_row("AMQP URL", self.__amqp_url)
145
+ table.add_row("Username", self.__credentials.username)
146
+ table.add_row("Password", "******")
147
+
148
+ console.print(title_panel, justify="center")
149
+ console.print(separator, justify="center")
150
+ console.print(table, justify="center")
@@ -0,0 +1,127 @@
1
+ syntax = "proto3";
2
+
3
+ package chatbot;
4
+
5
+ option go_package = "./chatbot";
6
+
7
+ ///// Serviços de Estado do Usuário /////
8
+ service UserStateService {
9
+ rpc InsertUpdateUserState(UserState) returns (RequestStatus);
10
+ rpc DeleteUserState(ChatID) returns (RequestStatus);
11
+ rpc GetUserState(ChatID) returns (UserState);
12
+ rpc GetAllUserStates(Void) returns (UserStateList);
13
+ }
14
+
15
+ ///// Serviços de Mensagens /////
16
+ service SendMessage {
17
+ rpc SendMessage(Message) returns (RequestStatus);
18
+ }
19
+
20
+ ///// Serviços de Transfer /////
21
+ service Transfer {
22
+ rpc GetAllCampaigns(Void) returns (CampaignsList);
23
+ rpc GetCampaignID(CampaignName) returns (CampaignDetails);
24
+ rpc TransferToHuman(TransferToHumanRequest) returns (RequestStatus);
25
+ rpc TransferToMenu(TransferToMenuRequest) returns (RequestStatus);
26
+ }
27
+
28
+ ///// Serviços de EndChat /////
29
+ service EndChat {
30
+ rpc GetAllTabulations(Void) returns (TabulationsList);
31
+ rpc GetTabulationID(TabulationName) returns (TabulationDetails);
32
+ rpc EndChat(EndChatRequest) returns (RequestStatus);
33
+ }
34
+
35
+ ///// Mensagens Compartilhadas /////
36
+ message Void {}
37
+
38
+ message RequestStatus {
39
+ bool status = 1;
40
+ string message = 2;
41
+ }
42
+
43
+ message ChatID {
44
+ string user_id = 1;
45
+ string company_id = 2;
46
+ }
47
+ ///// Mensagens para Estado do Usuário /////
48
+ message UserState {
49
+ ChatID chat_id = 1;
50
+ string menu = 2;
51
+ string route = 3;
52
+ string protocol = 4;
53
+ string observation = 5;
54
+ }
55
+
56
+ message UserStateList {
57
+ repeated UserState user_states = 1;
58
+ }
59
+
60
+ ///// Mensagens para Serviços de Mensagens /////
61
+ message TextMessage {
62
+ string type = 1;
63
+ string url = 2;
64
+ string filename = 3;
65
+ string title = 4;
66
+ string detail = 5;
67
+ string caption = 6;
68
+ }
69
+
70
+ message Button{
71
+ string type = 1;
72
+ string title = 2;
73
+ string detail = 3;
74
+ }
75
+
76
+ message Message {
77
+ ChatID chat_id = 1;
78
+ TextMessage message = 2;
79
+ repeated Button buttons = 3;
80
+ Button display_button = 4;
81
+ }
82
+
83
+ ///// Mensagens para Serviços de Transfer /////
84
+ message TransferToHumanRequest{
85
+ ChatID chat_id = 1;
86
+ string campaign_id = 2;
87
+ }
88
+
89
+ message TransferToMenuRequest{
90
+ ChatID chat_id = 1;
91
+ string menu = 2;
92
+ string user_message = 3;
93
+ }
94
+
95
+ message TabulationName{
96
+ string name = 1;
97
+ }
98
+
99
+ message TabulationDetails{
100
+ string id = 1;
101
+ string name = 2;
102
+ string last_update = 3;
103
+ }
104
+
105
+ message TabulationsList{
106
+ repeated TabulationDetails tabulations = 1;
107
+ }
108
+
109
+ ///// Serviços de EndChat /////
110
+ message EndChatRequest {
111
+ ChatID chat_id = 1;
112
+ string tabulation_id = 2;
113
+ }
114
+
115
+ message CampaignName {
116
+ string name = 1;
117
+ }
118
+
119
+ message CampaignDetails {
120
+ string id = 1;
121
+ string name = 2;
122
+ string last_update = 3;
123
+ }
124
+
125
+ message CampaignsList {
126
+ repeated CampaignDetails campaigns = 1;
127
+ }