chatgraph 0.2.0__py3-none-any.whl → 0.2.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/bot/chatbot_model.py +18 -6
- chatgraph/messages/base_message_consumer.py +7 -0
- chatgraph/messages/rabbitMQ_message_consumer.py +35 -1
- chatgraph/types/output_state.py +6 -6
- {chatgraph-0.2.0.dist-info → chatgraph-0.2.4.dist-info}/METADATA +2 -1
- {chatgraph-0.2.0.dist-info → chatgraph-0.2.4.dist-info}/RECORD +8 -8
- {chatgraph-0.2.0.dist-info → chatgraph-0.2.4.dist-info}/LICENSE +0 -0
- {chatgraph-0.2.0.dist-info → chatgraph-0.2.4.dist-info}/WHEEL +0 -0
chatgraph/bot/chatbot_model.py
CHANGED
|
@@ -2,6 +2,7 @@ import inspect
|
|
|
2
2
|
from abc import ABC
|
|
3
3
|
from functools import wraps
|
|
4
4
|
from logging import debug
|
|
5
|
+
import json
|
|
5
6
|
|
|
6
7
|
from ..error.chatbot_error import ChatbotError, ChatbotMessageError
|
|
7
8
|
from ..messages.base_message_consumer import MessageConsumer
|
|
@@ -97,8 +98,9 @@ class ChatbotApp(ABC):
|
|
|
97
98
|
"""
|
|
98
99
|
Inicia o consumo de mensagens pelo chatbot, processando cada mensagem recebida.
|
|
99
100
|
"""
|
|
101
|
+
self.__message_consumer.reprer()
|
|
100
102
|
self.__message_consumer.start_consume(self.process_message)
|
|
101
|
-
|
|
103
|
+
|
|
102
104
|
def process_message(self, message: Message):
|
|
103
105
|
"""
|
|
104
106
|
Processa uma mensagem recebida, identificando a rota correspondente e executando a função associada.
|
|
@@ -113,8 +115,8 @@ class ChatbotApp(ABC):
|
|
|
113
115
|
Returns:
|
|
114
116
|
str: A resposta gerada pela função da rota, que pode ser uma mensagem ou o resultado de uma redireção.
|
|
115
117
|
"""
|
|
116
|
-
customer_id = message.customer_id
|
|
117
|
-
|
|
118
|
+
customer_id = message.user_state.customer_id
|
|
119
|
+
user_state = message.user_state
|
|
118
120
|
menu = message.user_state.menu
|
|
119
121
|
menu = menu.lower()
|
|
120
122
|
handler = self.__routes.get(menu, None)
|
|
@@ -138,9 +140,19 @@ class ChatbotApp(ABC):
|
|
|
138
140
|
if type(message_response) in (str, float, int):
|
|
139
141
|
response = ChatbotResponse(message_response)
|
|
140
142
|
return response.json()
|
|
143
|
+
elif type(message_response) == ChatbotResponse:
|
|
144
|
+
route = self.__adjust_route(message_response.route, menu)
|
|
145
|
+
response = message_response.json()
|
|
146
|
+
response['user_state'] = {
|
|
147
|
+
'customer_id': customer_id,
|
|
148
|
+
'menu': route,
|
|
149
|
+
'obs': user_state.obs,
|
|
150
|
+
}
|
|
151
|
+
return json.dumps(response)
|
|
141
152
|
elif type(message_response) in (ChatbotResponse, EndChatResponse, TransferToHuman):
|
|
142
|
-
|
|
143
|
-
|
|
153
|
+
response = message_response.json()
|
|
154
|
+
response['customer_id'] = customer_id
|
|
155
|
+
return json.dumps(response)
|
|
144
156
|
elif type(message_response) == RedirectResponse:
|
|
145
157
|
route = self.__adjust_route(message_response.route, menu)
|
|
146
158
|
message.user_state.menu = route
|
|
@@ -165,4 +177,4 @@ class ChatbotApp(ABC):
|
|
|
165
177
|
if 'start' not in route:
|
|
166
178
|
route = absolute_route + route
|
|
167
179
|
|
|
168
|
-
return route
|
|
180
|
+
return route
|
|
@@ -6,7 +6,10 @@ from typing import Callable
|
|
|
6
6
|
from ..auth.credentials import Credential
|
|
7
7
|
from ..types.message_types import Message, UserState
|
|
8
8
|
from .base_message_consumer import MessageConsumer
|
|
9
|
-
|
|
9
|
+
from rich.console import Console
|
|
10
|
+
from rich.table import Table
|
|
11
|
+
from rich.text import Text
|
|
12
|
+
from rich.panel import Panel
|
|
10
13
|
|
|
11
14
|
class RabbitMessageConsumer(MessageConsumer):
|
|
12
15
|
"""
|
|
@@ -175,3 +178,34 @@ class RabbitMessageConsumer(MessageConsumer):
|
|
|
175
178
|
company_phone=message.get('company_phone', ''),
|
|
176
179
|
status=message.get('status'),
|
|
177
180
|
)
|
|
181
|
+
|
|
182
|
+
def reprer(self):
|
|
183
|
+
console = Console()
|
|
184
|
+
|
|
185
|
+
# Título "ChatGraph" destacado em vermelho e negrito dentro de um painel
|
|
186
|
+
title_text = Text("ChatGraph", style="bold red", justify="center")
|
|
187
|
+
title_panel = Panel.fit(title_text, title=" ", border_style="bold red", padding=(1, 4))
|
|
188
|
+
|
|
189
|
+
# Linha separadora com emojis
|
|
190
|
+
separator = Text("🐇🐇🐇 RabbitMessageConsumer 📨📨📨", style="cyan", justify="center")
|
|
191
|
+
|
|
192
|
+
# Criação da tabela com os atributos
|
|
193
|
+
table = Table(show_header=True, header_style="bold magenta", title="RabbitMQ Consumer")
|
|
194
|
+
table.add_column("Atributo", justify="center", style="cyan", no_wrap=True)
|
|
195
|
+
table.add_column("Valor", justify="center", style="magenta")
|
|
196
|
+
|
|
197
|
+
table.add_row("Virtual Host", self.__virtual_host)
|
|
198
|
+
table.add_row("Prefetch Count", str(self.__prefetch_count))
|
|
199
|
+
table.add_row("Queue Consume", self.__queue_consume)
|
|
200
|
+
table.add_row("AMQP URL", self.__amqp_url)
|
|
201
|
+
table.add_row("Username", self.__credentials.username)
|
|
202
|
+
table.add_row("Password", "******") # Oculta a senha
|
|
203
|
+
|
|
204
|
+
# Imprime o título, separador e a tabela centralizada
|
|
205
|
+
console.print(title_panel, justify="center")
|
|
206
|
+
console.print(separator, justify="center")
|
|
207
|
+
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()
|
chatgraph/types/output_state.py
CHANGED
|
@@ -28,10 +28,10 @@ class ChatbotResponse:
|
|
|
28
28
|
'''
|
|
29
29
|
Retorna o objeto em formato json.
|
|
30
30
|
'''
|
|
31
|
-
return
|
|
31
|
+
return {
|
|
32
32
|
'type': 'message',
|
|
33
33
|
'message': self.message,
|
|
34
|
-
}
|
|
34
|
+
}
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
class RedirectResponse:
|
|
@@ -71,11 +71,11 @@ class EndChatResponse:
|
|
|
71
71
|
'''
|
|
72
72
|
Retorna o objeto em formato json.
|
|
73
73
|
'''
|
|
74
|
-
return
|
|
74
|
+
return {
|
|
75
75
|
'type': 'tabulate',
|
|
76
76
|
'tabulation_id': self.tabulation_id,
|
|
77
77
|
'observations': self.observations,
|
|
78
|
-
}
|
|
78
|
+
}
|
|
79
79
|
|
|
80
80
|
class TransferToHuman:
|
|
81
81
|
"""
|
|
@@ -92,8 +92,8 @@ class TransferToHuman:
|
|
|
92
92
|
'''
|
|
93
93
|
Retorna o objeto em formato json.
|
|
94
94
|
'''
|
|
95
|
-
return
|
|
95
|
+
return {
|
|
96
96
|
'type': 'transfer',
|
|
97
97
|
'campaign_id': self.campaign_id,
|
|
98
98
|
'observations': self.observations,
|
|
99
|
-
}
|
|
99
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: chatgraph
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: A user-friendly chatbot library
|
|
5
5
|
Home-page: https://github.com/irissonnlima/chatgraph
|
|
6
6
|
License: MIT
|
|
@@ -12,6 +12,7 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
14
|
Requires-Dist: pika (>=1.3.2,<2.0.0)
|
|
15
|
+
Requires-Dist: rich (>=13.8.1,<14.0.0)
|
|
15
16
|
Project-URL: Repository, https://github.com/irissonnlima/chatgraph
|
|
16
17
|
Description-Content-Type: text/markdown
|
|
17
18
|
|
|
@@ -1,17 +1,17 @@
|
|
|
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=IBmFLGRkFh4eEwNInIMw3czQ5Kdry8NmQ4dCg81Yqro,6626
|
|
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
|
-
chatgraph/messages/base_message_consumer.py,sha256=
|
|
8
|
-
chatgraph/messages/rabbitMQ_message_consumer.py,sha256=
|
|
7
|
+
chatgraph/messages/base_message_consumer.py,sha256=4qZj69eDtqeqmSDSfGsCRt6hyypSPTSry3pmRh8r8nM,1269
|
|
8
|
+
chatgraph/messages/rabbitMQ_message_consumer.py,sha256=xdKrHeq1zV_0FDy1JtcLpWGW0RoUD-8q32ZWvnsdEOQ,8851
|
|
9
9
|
chatgraph/messages/test_message_consumer.py,sha256=9XIkbCHd1S6S8pINRT-SLEvUT0TQWBCsdPhYN6PpZ2s,518
|
|
10
10
|
chatgraph/types/message_types.py,sha256=7eB45hrlbYKV1Lp9vysR6V7OXNsySpeKYbGBc2Ux6xE,1363
|
|
11
|
-
chatgraph/types/output_state.py,sha256=
|
|
11
|
+
chatgraph/types/output_state.py,sha256=C8kNy3bqSKBW3jAF-37Jrph-1Kqw08cY5dS3_bo3czA,3028
|
|
12
12
|
chatgraph/types/route.py,sha256=nKTqzwGl7d_Bu8G6Sr0EmmhuuiZWKEoSozITRrdyi1g,2587
|
|
13
13
|
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.
|
|
14
|
+
chatgraph-0.2.4.dist-info/LICENSE,sha256=rVJozpRzDlplOpvI8A1GvmfVS0ReYdZvMWc1j2jV0v8,1090
|
|
15
|
+
chatgraph-0.2.4.dist-info/METADATA,sha256=6JnfS0l3ArZorgyQNUX93L9S-3hA6NuA-IMgPyDXsy0,5868
|
|
16
|
+
chatgraph-0.2.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
17
|
+
chatgraph-0.2.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|