chatgraph 0.1.4__py3-none-any.whl → 0.2.0__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 +5 -4
- chatgraph/bot/chatbot_model.py +7 -16
- chatgraph/messages/rabbitMQ_message_consumer.py +7 -2
- chatgraph/types/message_types.py +18 -2
- chatgraph/types/user_state.py +4 -0
- {chatgraph-0.1.4.dist-info → chatgraph-0.2.0.dist-info}/METADATA +1 -1
- {chatgraph-0.1.4.dist-info → chatgraph-0.2.0.dist-info}/RECORD +9 -9
- {chatgraph-0.1.4.dist-info → chatgraph-0.2.0.dist-info}/LICENSE +0 -0
- {chatgraph-0.1.4.dist-info → chatgraph-0.2.0.dist-info}/WHEEL +0 -0
chatgraph/__init__.py
CHANGED
|
@@ -2,19 +2,20 @@ 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.rabbitMQ_message_consumer import RabbitMessageConsumer
|
|
5
|
-
from .types.message_types import Message
|
|
6
|
-
from .types.output_state import ChatbotResponse, RedirectResponse
|
|
5
|
+
from .types.message_types import Message, UserState
|
|
6
|
+
from .types.output_state import ChatbotResponse, RedirectResponse, EndChatResponse, TransferToHuman
|
|
7
7
|
from .types.route import Route
|
|
8
|
-
from .types.user_state import SimpleUserState
|
|
9
8
|
|
|
10
9
|
__all__ = [
|
|
11
10
|
'ChatbotApp',
|
|
12
11
|
'Credential',
|
|
13
|
-
'SimpleUserState',
|
|
14
12
|
'Message',
|
|
15
13
|
'ChatbotRouter',
|
|
16
14
|
'ChatbotResponse',
|
|
17
15
|
'RedirectResponse',
|
|
18
16
|
'RabbitMessageConsumer',
|
|
19
17
|
'Route',
|
|
18
|
+
'EndChatResponse',
|
|
19
|
+
'TransferToHuman',
|
|
20
|
+
'UserState',
|
|
20
21
|
]
|
chatgraph/bot/chatbot_model.py
CHANGED
|
@@ -8,7 +8,6 @@ from ..messages.base_message_consumer import MessageConsumer
|
|
|
8
8
|
from ..types.message_types import Message
|
|
9
9
|
from ..types.output_state import ChatbotResponse, RedirectResponse, EndChatResponse, TransferToHuman
|
|
10
10
|
from ..types.route import Route
|
|
11
|
-
from ..types.user_state import UserState
|
|
12
11
|
from .chatbot_router import ChatbotRouter
|
|
13
12
|
|
|
14
13
|
|
|
@@ -17,16 +16,14 @@ class ChatbotApp(ABC):
|
|
|
17
16
|
Classe principal para a aplicação do chatbot, gerencia as rotas e a lógica de processamento de mensagens.
|
|
18
17
|
"""
|
|
19
18
|
|
|
20
|
-
def __init__(self,
|
|
19
|
+
def __init__(self, message_consumer: MessageConsumer):
|
|
21
20
|
"""
|
|
22
21
|
Inicializa a classe ChatbotApp com um estado de usuário e um consumidor de mensagens.
|
|
23
22
|
|
|
24
23
|
Args:
|
|
25
|
-
user_state (UserState): O estado do usuário, que contém informações persistentes sobre as interações do usuário.
|
|
26
24
|
message_consumer (MessageConsumer): O consumidor de mensagens que lida com a entrada de mensagens no sistema.
|
|
27
25
|
"""
|
|
28
26
|
self.__message_consumer = message_consumer
|
|
29
|
-
self.__user_state = user_state
|
|
30
27
|
self.__routes = {}
|
|
31
28
|
|
|
32
29
|
def include_router(self, router: ChatbotRouter, prefix: str):
|
|
@@ -118,7 +115,7 @@ class ChatbotApp(ABC):
|
|
|
118
115
|
"""
|
|
119
116
|
customer_id = message.customer_id
|
|
120
117
|
|
|
121
|
-
menu =
|
|
118
|
+
menu = message.user_state.menu
|
|
122
119
|
menu = menu.lower()
|
|
123
120
|
handler = self.__routes.get(menu, None)
|
|
124
121
|
|
|
@@ -139,21 +136,15 @@ class ChatbotApp(ABC):
|
|
|
139
136
|
message_response = func(**kwargs)
|
|
140
137
|
|
|
141
138
|
if type(message_response) in (str, float, int):
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
self.
|
|
139
|
+
response = ChatbotResponse(message_response)
|
|
140
|
+
return response.json()
|
|
141
|
+
elif type(message_response) in (ChatbotResponse, EndChatResponse, TransferToHuman):
|
|
142
|
+
# route = self.__adjust_route(message_response.route, menu)
|
|
146
143
|
return message_response.json()
|
|
147
144
|
elif type(message_response) == RedirectResponse:
|
|
148
145
|
route = self.__adjust_route(message_response.route, menu)
|
|
149
|
-
|
|
146
|
+
message.user_state.menu = route
|
|
150
147
|
return self.process_message(message)
|
|
151
|
-
elif type(message_response) == EndChatResponse:
|
|
152
|
-
self.__user_state.delete_menu(customer_id)
|
|
153
|
-
return message_response.json()
|
|
154
|
-
elif type(message_response) == TransferToHuman:
|
|
155
|
-
self.__user_state.delete_menu(customer_id)
|
|
156
|
-
return message_response.json()
|
|
157
148
|
else:
|
|
158
149
|
raise ChatbotError('Tipo de retorno inválido!')
|
|
159
150
|
|
|
@@ -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.message_types import Message
|
|
7
|
+
from ..types.message_types import Message, UserState
|
|
8
8
|
from .base_message_consumer import MessageConsumer
|
|
9
9
|
|
|
10
10
|
|
|
@@ -164,7 +164,12 @@ class RabbitMessageConsumer(MessageConsumer):
|
|
|
164
164
|
return Message(
|
|
165
165
|
type=message.get('type', ''),
|
|
166
166
|
text=message.get('text', ''),
|
|
167
|
-
|
|
167
|
+
user_state=UserState(
|
|
168
|
+
customer_id=message.get('customer_id', ''),
|
|
169
|
+
menu=message.get('menu', ''),
|
|
170
|
+
lst_update=message.get('lst_update', ''),
|
|
171
|
+
obs=message.get('obs', {}),
|
|
172
|
+
),
|
|
168
173
|
channel=message.get('channel', ''),
|
|
169
174
|
customer_phone=message.get('customer_phone', ''),
|
|
170
175
|
company_phone=message.get('company_phone', ''),
|
chatgraph/types/message_types.py
CHANGED
|
@@ -2,6 +2,22 @@ from dataclasses import dataclass
|
|
|
2
2
|
from typing import Optional
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
@dataclass
|
|
6
|
+
class UserState:
|
|
7
|
+
"""
|
|
8
|
+
Representa o estado de um usuário.
|
|
9
|
+
|
|
10
|
+
Atributos:
|
|
11
|
+
customer_id (str): O ID do cliente.
|
|
12
|
+
menu (str): O menu atual.
|
|
13
|
+
lst_update (str): A última atualização do menu.
|
|
14
|
+
obs (dict): Observações adicionais sobre o estado do usuário.
|
|
15
|
+
"""
|
|
16
|
+
customer_id: str
|
|
17
|
+
menu: str
|
|
18
|
+
lst_update: str
|
|
19
|
+
obs: Optional[dict] = None
|
|
20
|
+
|
|
5
21
|
@dataclass
|
|
6
22
|
class Message:
|
|
7
23
|
"""
|
|
@@ -10,7 +26,7 @@ class Message:
|
|
|
10
26
|
Atributos:
|
|
11
27
|
type (str): O tipo da mensagem (por exemplo, texto, imagem, etc.).
|
|
12
28
|
text (str): O conteúdo textual da mensagem.
|
|
13
|
-
|
|
29
|
+
UserState (UserState): O estado do usuário.
|
|
14
30
|
channel (str): O canal pelo qual a mensagem foi enviada ou recebida (por exemplo, WhatsApp, SMS, etc.).
|
|
15
31
|
customer_phone (str): O número de telefone do cliente.
|
|
16
32
|
company_phone (str): O número de telefone da empresa que está enviando ou recebendo a mensagem.
|
|
@@ -18,7 +34,7 @@ class Message:
|
|
|
18
34
|
"""
|
|
19
35
|
type: str
|
|
20
36
|
text: str
|
|
21
|
-
|
|
37
|
+
user_state: UserState
|
|
22
38
|
channel: str
|
|
23
39
|
customer_phone: str
|
|
24
40
|
company_phone: str
|
chatgraph/types/user_state.py
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
chatgraph/__init__.py,sha256=
|
|
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=cy_IzeM8rZps9LxPKvEm9EWBQ_DlMBRm7iViQCxYy7s,6095
|
|
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=OSdTT4dHIzawLDOCZ-4hZ06T8UBxoJIosqvXl7gxpM0,1099
|
|
8
|
-
chatgraph/messages/rabbitMQ_message_consumer.py,sha256=
|
|
8
|
+
chatgraph/messages/rabbitMQ_message_consumer.py,sha256=HoVS79PMXfkh0QHsZ7Zj7XuPLwEMnDXpR_9NJU78lqc,7222
|
|
9
9
|
chatgraph/messages/test_message_consumer.py,sha256=9XIkbCHd1S6S8pINRT-SLEvUT0TQWBCsdPhYN6PpZ2s,518
|
|
10
|
-
chatgraph/types/message_types.py,sha256=
|
|
10
|
+
chatgraph/types/message_types.py,sha256=7eB45hrlbYKV1Lp9vysR6V7OXNsySpeKYbGBc2Ux6xE,1363
|
|
11
11
|
chatgraph/types/output_state.py,sha256=fpJ_hGO4aZ3wr6DV4i9ctnkHytWhK6ZDpKpJ3vSwRyY,3064
|
|
12
12
|
chatgraph/types/route.py,sha256=nKTqzwGl7d_Bu8G6Sr0EmmhuuiZWKEoSozITRrdyi1g,2587
|
|
13
|
-
chatgraph/types/user_state.py,sha256=
|
|
14
|
-
chatgraph-0.
|
|
15
|
-
chatgraph-0.
|
|
16
|
-
chatgraph-0.
|
|
17
|
-
chatgraph-0.
|
|
13
|
+
chatgraph/types/user_state.py,sha256=nliV-kC_yOmYoFh8CQSfT92DbOv4BLF0vvn8kotnDog,2884
|
|
14
|
+
chatgraph-0.2.0.dist-info/LICENSE,sha256=rVJozpRzDlplOpvI8A1GvmfVS0ReYdZvMWc1j2jV0v8,1090
|
|
15
|
+
chatgraph-0.2.0.dist-info/METADATA,sha256=QCo3qrEPo-qPcxIekYUq5jkt-8pgKoDI2Xzp_gASERM,5829
|
|
16
|
+
chatgraph-0.2.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
17
|
+
chatgraph-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|