chatgraph 0.1.4__py3-none-any.whl → 0.2.3__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 +17 -17
- chatgraph/messages/rabbitMQ_message_consumer.py +7 -2
- chatgraph/types/message_types.py +18 -2
- chatgraph/types/output_state.py +6 -6
- chatgraph/types/user_state.py +4 -0
- {chatgraph-0.1.4.dist-info → chatgraph-0.2.3.dist-info}/METADATA +1 -1
- chatgraph-0.2.3.dist-info/RECORD +17 -0
- chatgraph-0.1.4.dist-info/RECORD +0 -17
- {chatgraph-0.1.4.dist-info → chatgraph-0.2.3.dist-info}/LICENSE +0 -0
- {chatgraph-0.1.4.dist-info → chatgraph-0.2.3.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
|
@@ -2,13 +2,13 @@ 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
|
|
8
9
|
from ..types.message_types import Message
|
|
9
10
|
from ..types.output_state import ChatbotResponse, RedirectResponse, EndChatResponse, TransferToHuman
|
|
10
11
|
from ..types.route import Route
|
|
11
|
-
from ..types.user_state import UserState
|
|
12
12
|
from .chatbot_router import ChatbotRouter
|
|
13
13
|
|
|
14
14
|
|
|
@@ -17,16 +17,14 @@ class ChatbotApp(ABC):
|
|
|
17
17
|
Classe principal para a aplicação do chatbot, gerencia as rotas e a lógica de processamento de mensagens.
|
|
18
18
|
"""
|
|
19
19
|
|
|
20
|
-
def __init__(self,
|
|
20
|
+
def __init__(self, message_consumer: MessageConsumer):
|
|
21
21
|
"""
|
|
22
22
|
Inicializa a classe ChatbotApp com um estado de usuário e um consumidor de mensagens.
|
|
23
23
|
|
|
24
24
|
Args:
|
|
25
|
-
user_state (UserState): O estado do usuário, que contém informações persistentes sobre as interações do usuário.
|
|
26
25
|
message_consumer (MessageConsumer): O consumidor de mensagens que lida com a entrada de mensagens no sistema.
|
|
27
26
|
"""
|
|
28
27
|
self.__message_consumer = message_consumer
|
|
29
|
-
self.__user_state = user_state
|
|
30
28
|
self.__routes = {}
|
|
31
29
|
|
|
32
30
|
def include_router(self, router: ChatbotRouter, prefix: str):
|
|
@@ -116,9 +114,9 @@ class ChatbotApp(ABC):
|
|
|
116
114
|
Returns:
|
|
117
115
|
str: A resposta gerada pela função da rota, que pode ser uma mensagem ou o resultado de uma redireção.
|
|
118
116
|
"""
|
|
119
|
-
customer_id = message.customer_id
|
|
120
|
-
|
|
121
|
-
menu =
|
|
117
|
+
customer_id = message.user_state.customer_id
|
|
118
|
+
user_state = message.user_state
|
|
119
|
+
menu = message.user_state.menu
|
|
122
120
|
menu = menu.lower()
|
|
123
121
|
handler = self.__routes.get(menu, None)
|
|
124
122
|
|
|
@@ -139,21 +137,23 @@ class ChatbotApp(ABC):
|
|
|
139
137
|
message_response = func(**kwargs)
|
|
140
138
|
|
|
141
139
|
if type(message_response) in (str, float, int):
|
|
142
|
-
|
|
140
|
+
response = ChatbotResponse(message_response)
|
|
141
|
+
return response.json()
|
|
143
142
|
elif type(message_response) == ChatbotResponse:
|
|
144
143
|
route = self.__adjust_route(message_response.route, menu)
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
response = message_response.json()
|
|
145
|
+
response['user_state'] = {
|
|
146
|
+
'customer_id': customer_id,
|
|
147
|
+
'menu': route,
|
|
148
|
+
'obs': user_state.obs,
|
|
149
|
+
}
|
|
150
|
+
return json.dumps(response)
|
|
151
|
+
elif type(message_response) in (ChatbotResponse, EndChatResponse, TransferToHuman):
|
|
152
|
+
return json.dumps(message_response.json())
|
|
147
153
|
elif type(message_response) == RedirectResponse:
|
|
148
154
|
route = self.__adjust_route(message_response.route, menu)
|
|
149
|
-
|
|
155
|
+
message.user_state.menu = route
|
|
150
156
|
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
157
|
else:
|
|
158
158
|
raise ChatbotError('Tipo de retorno inválido!')
|
|
159
159
|
|
|
@@ -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/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
|
+
}
|
chatgraph/types/user_state.py
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
chatgraph/__init__.py,sha256=6pDNMUOLR8iFK_3mWula1IJQcIoE8io-65mS_QheXXE,642
|
|
2
|
+
chatgraph/auth/credentials.py,sha256=xsMEpLQnc66novPjL6upocMcnUnvFJ7yxINzUenkxmc,2388
|
|
3
|
+
chatgraph/bot/chatbot_model.py,sha256=9EPl6XJKNlu5eZHTnZylSXHu_ANyeUkeSsksSkWyAyI,6498
|
|
4
|
+
chatgraph/bot/chatbot_router.py,sha256=kZ_4X5AhhE2mntx4tcHiapaSKC1T4K1jqIVjLp1Pjg0,2817
|
|
5
|
+
chatgraph/error/chatbot_error.py,sha256=4sEcW8vz0eQk2QDmDygucVM4caHliZW5iH7XJvmLBuk,1897
|
|
6
|
+
chatgraph/error/route_error.py,sha256=CY8m82ap7-Sr-DXPsolltRW50TqD__5RyXBmNNJCWr8,793
|
|
7
|
+
chatgraph/messages/base_message_consumer.py,sha256=OSdTT4dHIzawLDOCZ-4hZ06T8UBxoJIosqvXl7gxpM0,1099
|
|
8
|
+
chatgraph/messages/rabbitMQ_message_consumer.py,sha256=HoVS79PMXfkh0QHsZ7Zj7XuPLwEMnDXpR_9NJU78lqc,7222
|
|
9
|
+
chatgraph/messages/test_message_consumer.py,sha256=9XIkbCHd1S6S8pINRT-SLEvUT0TQWBCsdPhYN6PpZ2s,518
|
|
10
|
+
chatgraph/types/message_types.py,sha256=7eB45hrlbYKV1Lp9vysR6V7OXNsySpeKYbGBc2Ux6xE,1363
|
|
11
|
+
chatgraph/types/output_state.py,sha256=C8kNy3bqSKBW3jAF-37Jrph-1Kqw08cY5dS3_bo3czA,3028
|
|
12
|
+
chatgraph/types/route.py,sha256=nKTqzwGl7d_Bu8G6Sr0EmmhuuiZWKEoSozITRrdyi1g,2587
|
|
13
|
+
chatgraph/types/user_state.py,sha256=nliV-kC_yOmYoFh8CQSfT92DbOv4BLF0vvn8kotnDog,2884
|
|
14
|
+
chatgraph-0.2.3.dist-info/LICENSE,sha256=rVJozpRzDlplOpvI8A1GvmfVS0ReYdZvMWc1j2jV0v8,1090
|
|
15
|
+
chatgraph-0.2.3.dist-info/METADATA,sha256=C5mhEHmgEPYBv3opwU6XKObWHwhv0rB6kYMbRJn2DHU,5829
|
|
16
|
+
chatgraph-0.2.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
17
|
+
chatgraph-0.2.3.dist-info/RECORD,,
|
chatgraph-0.1.4.dist-info/RECORD
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
chatgraph/__init__.py,sha256=qPA9Vw2SZivqVUlB19D-YrRuequMThR6kgO2XsZcwDc,602
|
|
2
|
-
chatgraph/auth/credentials.py,sha256=xsMEpLQnc66novPjL6upocMcnUnvFJ7yxINzUenkxmc,2388
|
|
3
|
-
chatgraph/bot/chatbot_model.py,sha256=6tPoplS9nPHMYK0gSKFGq6cQr3dA2jOiBJTmQVuOb0I,6643
|
|
4
|
-
chatgraph/bot/chatbot_router.py,sha256=kZ_4X5AhhE2mntx4tcHiapaSKC1T4K1jqIVjLp1Pjg0,2817
|
|
5
|
-
chatgraph/error/chatbot_error.py,sha256=4sEcW8vz0eQk2QDmDygucVM4caHliZW5iH7XJvmLBuk,1897
|
|
6
|
-
chatgraph/error/route_error.py,sha256=CY8m82ap7-Sr-DXPsolltRW50TqD__5RyXBmNNJCWr8,793
|
|
7
|
-
chatgraph/messages/base_message_consumer.py,sha256=OSdTT4dHIzawLDOCZ-4hZ06T8UBxoJIosqvXl7gxpM0,1099
|
|
8
|
-
chatgraph/messages/rabbitMQ_message_consumer.py,sha256=mRcJ1Hbd5wPFxC3v6Tj3pYvjd9yAc398Ys6cUox-CTY,7005
|
|
9
|
-
chatgraph/messages/test_message_consumer.py,sha256=9XIkbCHd1S6S8pINRT-SLEvUT0TQWBCsdPhYN6PpZ2s,518
|
|
10
|
-
chatgraph/types/message_types.py,sha256=NBuebmpO2e9ilspBoFgs9O3rY_VQ2AP_Z8Q_nC70nyM,965
|
|
11
|
-
chatgraph/types/output_state.py,sha256=fpJ_hGO4aZ3wr6DV4i9ctnkHytWhK6ZDpKpJ3vSwRyY,3064
|
|
12
|
-
chatgraph/types/route.py,sha256=nKTqzwGl7d_Bu8G6Sr0EmmhuuiZWKEoSozITRrdyi1g,2587
|
|
13
|
-
chatgraph/types/user_state.py,sha256=B17bN300RW_9-WUbI7pWK_BUCvMbdpm6gLQHPqdGly4,2858
|
|
14
|
-
chatgraph-0.1.4.dist-info/LICENSE,sha256=rVJozpRzDlplOpvI8A1GvmfVS0ReYdZvMWc1j2jV0v8,1090
|
|
15
|
-
chatgraph-0.1.4.dist-info/METADATA,sha256=KQyN7GDztKsyFwUM4F_kF9eFE--Bi44ajc7AsaI6-Mg,5829
|
|
16
|
-
chatgraph-0.1.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
17
|
-
chatgraph-0.1.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|