chatgraph 0.2.4__py3-none-any.whl → 0.2.5__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 +7 -1
- chatgraph/messages/base_message_sender.py +23 -0
- chatgraph/messages/rabbitMQ_message_consumer.py +6 -8
- chatgraph/messages/rabbitMQ_message_sender.py +79 -0
- chatgraph/types/output_state.py +1 -1
- {chatgraph-0.2.4.dist-info → chatgraph-0.2.5.dist-info}/METADATA +1 -1
- {chatgraph-0.2.4.dist-info → chatgraph-0.2.5.dist-info}/RECORD +9 -7
- {chatgraph-0.2.4.dist-info → chatgraph-0.2.5.dist-info}/LICENSE +0 -0
- {chatgraph-0.2.4.dist-info → chatgraph-0.2.5.dist-info}/WHEEL +0 -0
chatgraph/bot/chatbot_model.py
CHANGED
|
@@ -139,7 +139,13 @@ class ChatbotApp(ABC):
|
|
|
139
139
|
|
|
140
140
|
if type(message_response) in (str, float, int):
|
|
141
141
|
response = ChatbotResponse(message_response)
|
|
142
|
-
|
|
142
|
+
response = message_response.json()
|
|
143
|
+
response['user_state'] = {
|
|
144
|
+
'customer_id': customer_id,
|
|
145
|
+
'menu': menu,
|
|
146
|
+
'obs': user_state.obs,
|
|
147
|
+
}
|
|
148
|
+
return json.dumps(response)
|
|
143
149
|
elif type(message_response) == ChatbotResponse:
|
|
144
150
|
route = self.__adjust_route(message_response.route, menu)
|
|
145
151
|
response = message_response.json()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
|
|
3
|
+
class MessageSender(ABC):
|
|
4
|
+
|
|
5
|
+
@abstractmethod
|
|
6
|
+
def load_dotenv(self) -> 'MessageSender':
|
|
7
|
+
"""
|
|
8
|
+
Carrega variáveis de ambiente para configurar o disparador de mensagens.
|
|
9
|
+
|
|
10
|
+
Returns:
|
|
11
|
+
MessageSender: A instância do disparador de mensagens configurado.
|
|
12
|
+
"""
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
@abstractmethod
|
|
16
|
+
def send_message(self) -> None:
|
|
17
|
+
"""
|
|
18
|
+
Envia uma mensagem para o destino especificado.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
message (str): A mensagem a ser enviada.
|
|
22
|
+
"""
|
|
23
|
+
pass
|
|
@@ -164,14 +164,16 @@ class RabbitMessageConsumer(MessageConsumer):
|
|
|
164
164
|
Returns:
|
|
165
165
|
Message: Uma instância da classe Message com os dados extraídos do dicionário.
|
|
166
166
|
"""
|
|
167
|
+
|
|
168
|
+
user_state = message.get('user_state', {})
|
|
167
169
|
return Message(
|
|
168
170
|
type=message.get('type', ''),
|
|
169
171
|
text=message.get('text', ''),
|
|
170
172
|
user_state=UserState(
|
|
171
|
-
customer_id=
|
|
172
|
-
menu=
|
|
173
|
-
lst_update=
|
|
174
|
-
obs=
|
|
173
|
+
customer_id=user_state.get('customer_id', ''),
|
|
174
|
+
menu=user_state.get('menu', ''),
|
|
175
|
+
lst_update=user_state.get('lst_update', ''),
|
|
176
|
+
obs=user_state.get('obs', {}),
|
|
175
177
|
),
|
|
176
178
|
channel=message.get('channel', ''),
|
|
177
179
|
customer_phone=message.get('customer_phone', ''),
|
|
@@ -205,7 +207,3 @@ class RabbitMessageConsumer(MessageConsumer):
|
|
|
205
207
|
console.print(title_panel, justify="center")
|
|
206
208
|
console.print(separator, justify="center")
|
|
207
209
|
console.print(table, justify="center")
|
|
208
|
-
|
|
209
|
-
c = Credential('user', 'pass')
|
|
210
|
-
consumer = RabbitMessageConsumer(c, "amqp://example.com", "queue_name", 10, "/virtual_host")
|
|
211
|
-
consumer.reprer()
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from .base_message_sender import MessageSender
|
|
2
|
+
from ..auth.credentials import Credential
|
|
3
|
+
import pika
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
class RabbitMessageSender(MessageSender):
|
|
7
|
+
def __init__(
|
|
8
|
+
self,
|
|
9
|
+
credential: Credential,
|
|
10
|
+
amqp_url: str,
|
|
11
|
+
send_queue: str,
|
|
12
|
+
virtual_host: str = '/',
|
|
13
|
+
) -> None:
|
|
14
|
+
"""
|
|
15
|
+
Inicializa o consumidor de mensagens RabbitMQ com as configurações fornecidas.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
credential (Credential): Credenciais de autenticação para o RabbitMQ.
|
|
19
|
+
amqp_url (str): A URL de conexão AMQP do RabbitMQ.
|
|
20
|
+
queue_consume (str): O nome da fila de consumo.
|
|
21
|
+
prefetch_count (int, opcional): O número de mensagens pré-carregadas. Padrão é 1.
|
|
22
|
+
virtual_host (str, opcional): O host virtual do RabbitMQ. Padrão é '/'.
|
|
23
|
+
"""
|
|
24
|
+
self.__virtual_host = virtual_host
|
|
25
|
+
self.__send_queue = send_queue
|
|
26
|
+
self.__amqp_url = amqp_url
|
|
27
|
+
self.__credentials = pika.PlainCredentials(
|
|
28
|
+
credential.username, credential.password
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
@classmethod
|
|
32
|
+
def load_dotenv(
|
|
33
|
+
cls,
|
|
34
|
+
user_env: str = 'RABBIT_USER',
|
|
35
|
+
pass_env: str = 'RABBIT_PASS',
|
|
36
|
+
uri_env: str = 'RABBIT_URI',
|
|
37
|
+
queue_env: str = 'RABBIT_QUEUE',
|
|
38
|
+
prefetch_env: str = 'RABBIT_PREFETCH',
|
|
39
|
+
vhost_env: str = 'RABBIT_VHOST',
|
|
40
|
+
) -> 'RabbitMessageSender':
|
|
41
|
+
"""
|
|
42
|
+
Carrega variáveis de ambiente para configurar o disparador de mensagens.
|
|
43
|
+
Args:
|
|
44
|
+
user_env (str): Nome da variável de ambiente para o usuário do RabbitMQ. Padrão é 'RABBIT_USER'.
|
|
45
|
+
pass_env (str): Nome da variável de ambiente para a senha do RabbitMQ. Padrão é 'RABBIT_PASS'.
|
|
46
|
+
uri_env (str): Nome da variável de ambiente para a URL do RabbitMQ. Padrão é 'RABBIT_URI'.
|
|
47
|
+
queue_env (str): Nome da variável de ambiente para a fila de consumo do RabbitMQ. Padrão é 'RABBIT_QUEUE'.
|
|
48
|
+
prefetch_env (str): Nome da variável de ambiente para o prefetch count. Padrão é 'RABBIT_PREFETCH'.
|
|
49
|
+
vhost_env (str): Nome da variável de ambiente para o host virtual do RabbitMQ. Padrão é 'RABBIT_VHOST'.
|
|
50
|
+
Raises:
|
|
51
|
+
ValueError: Se as variáveis de ambiente não forem configuradas corret
|
|
52
|
+
Returns:
|
|
53
|
+
RabbitMessageSender: A instância do disparador de mensagens configurado.
|
|
54
|
+
"""
|
|
55
|
+
username = os.getenv(user_env)
|
|
56
|
+
password = os.getenv(pass_env)
|
|
57
|
+
url = os.getenv(uri_env)
|
|
58
|
+
queue = os.getenv(queue_env)
|
|
59
|
+
vhost = os.getenv(vhost_env, '/')
|
|
60
|
+
|
|
61
|
+
if not username or not password or not url or not queue:
|
|
62
|
+
raise ValueError('Corrija as variáveis de ambiente!')
|
|
63
|
+
|
|
64
|
+
return cls(
|
|
65
|
+
credential=Credential(username=username, password=password),
|
|
66
|
+
amqp_url=url,
|
|
67
|
+
send_queue=queue,
|
|
68
|
+
virtual_host=vhost,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def send_message(self) -> None:
|
|
73
|
+
"""
|
|
74
|
+
Envia uma mensagem para o destino especificado.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
message (str): A mensagem a ser enviada.
|
|
78
|
+
"""
|
|
79
|
+
pass
|
chatgraph/types/output_state.py
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
chatgraph/__init__.py,sha256=6pDNMUOLR8iFK_3mWula1IJQcIoE8io-65mS_QheXXE,642
|
|
2
2
|
chatgraph/auth/credentials.py,sha256=xsMEpLQnc66novPjL6upocMcnUnvFJ7yxINzUenkxmc,2388
|
|
3
|
-
chatgraph/bot/chatbot_model.py,sha256=
|
|
3
|
+
chatgraph/bot/chatbot_model.py,sha256=NNsUM6GUvmf-d2DbGxsUCL26JtNscBdrQJcbXdv20_0,6850
|
|
4
4
|
chatgraph/bot/chatbot_router.py,sha256=kZ_4X5AhhE2mntx4tcHiapaSKC1T4K1jqIVjLp1Pjg0,2817
|
|
5
5
|
chatgraph/error/chatbot_error.py,sha256=4sEcW8vz0eQk2QDmDygucVM4caHliZW5iH7XJvmLBuk,1897
|
|
6
6
|
chatgraph/error/route_error.py,sha256=CY8m82ap7-Sr-DXPsolltRW50TqD__5RyXBmNNJCWr8,793
|
|
7
7
|
chatgraph/messages/base_message_consumer.py,sha256=4qZj69eDtqeqmSDSfGsCRt6hyypSPTSry3pmRh8r8nM,1269
|
|
8
|
-
chatgraph/messages/
|
|
8
|
+
chatgraph/messages/base_message_sender.py,sha256=0IgNW0WMwRXnXiKokqhMtX5imK3L6ZDKEYjFdSbQIq4,610
|
|
9
|
+
chatgraph/messages/rabbitMQ_message_consumer.py,sha256=Y9Y0BuHHPBj3qJZNVBQ0QA9XI-T_AqUR-ULd5WSeY1A,8771
|
|
10
|
+
chatgraph/messages/rabbitMQ_message_sender.py,sha256=TWegMfDasjUjKF5u8LVfr8ai32E3oBa_EELtGrTS7xk,3213
|
|
9
11
|
chatgraph/messages/test_message_consumer.py,sha256=9XIkbCHd1S6S8pINRT-SLEvUT0TQWBCsdPhYN6PpZ2s,518
|
|
10
12
|
chatgraph/types/message_types.py,sha256=7eB45hrlbYKV1Lp9vysR6V7OXNsySpeKYbGBc2Ux6xE,1363
|
|
11
|
-
chatgraph/types/output_state.py,sha256=
|
|
13
|
+
chatgraph/types/output_state.py,sha256=_pbCssNM4ls7tFG1Wbdg8BJN6ih0q3x2onXZdvZcGDo,3025
|
|
12
14
|
chatgraph/types/route.py,sha256=nKTqzwGl7d_Bu8G6Sr0EmmhuuiZWKEoSozITRrdyi1g,2587
|
|
13
15
|
chatgraph/types/user_state.py,sha256=nliV-kC_yOmYoFh8CQSfT92DbOv4BLF0vvn8kotnDog,2884
|
|
14
|
-
chatgraph-0.2.
|
|
15
|
-
chatgraph-0.2.
|
|
16
|
-
chatgraph-0.2.
|
|
17
|
-
chatgraph-0.2.
|
|
16
|
+
chatgraph-0.2.5.dist-info/LICENSE,sha256=rVJozpRzDlplOpvI8A1GvmfVS0ReYdZvMWc1j2jV0v8,1090
|
|
17
|
+
chatgraph-0.2.5.dist-info/METADATA,sha256=PLM-QZCefEPaSuAKJq9qz7NYcBbCxw12gMlqt-aFHqQ,5868
|
|
18
|
+
chatgraph-0.2.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
19
|
+
chatgraph-0.2.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|