chatgraph 0.1.3__tar.gz → 0.2.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.
- {chatgraph-0.1.3 → chatgraph-0.2.0}/PKG-INFO +1 -1
- {chatgraph-0.1.3 → chatgraph-0.2.0}/chatgraph/__init__.py +5 -4
- {chatgraph-0.1.3 → chatgraph-0.2.0}/chatgraph/bot/chatbot_model.py +9 -12
- {chatgraph-0.1.3 → chatgraph-0.2.0}/chatgraph/messages/rabbitMQ_message_consumer.py +7 -2
- chatgraph-0.2.0/chatgraph/messages/test_message_consumer.py +17 -0
- {chatgraph-0.1.3 → chatgraph-0.2.0}/chatgraph/types/message_types.py +18 -2
- chatgraph-0.2.0/chatgraph/types/output_state.py +99 -0
- {chatgraph-0.1.3 → chatgraph-0.2.0}/chatgraph/types/user_state.py +24 -0
- {chatgraph-0.1.3 → chatgraph-0.2.0}/pyproject.toml +1 -1
- chatgraph-0.1.3/chatgraph/types/output_state.py +0 -42
- {chatgraph-0.1.3 → chatgraph-0.2.0}/LICENSE +0 -0
- {chatgraph-0.1.3 → chatgraph-0.2.0}/README.md +0 -0
- {chatgraph-0.1.3 → chatgraph-0.2.0}/chatgraph/auth/credentials.py +0 -0
- {chatgraph-0.1.3 → chatgraph-0.2.0}/chatgraph/bot/chatbot_router.py +0 -0
- {chatgraph-0.1.3 → chatgraph-0.2.0}/chatgraph/error/chatbot_error.py +0 -0
- {chatgraph-0.1.3 → chatgraph-0.2.0}/chatgraph/error/route_error.py +0 -0
- {chatgraph-0.1.3 → chatgraph-0.2.0}/chatgraph/messages/base_message_consumer.py +0 -0
- {chatgraph-0.1.3 → chatgraph-0.2.0}/chatgraph/types/route.py +0 -0
|
@@ -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
|
]
|
|
@@ -6,9 +6,8 @@ from logging import debug
|
|
|
6
6
|
from ..error.chatbot_error import ChatbotError, ChatbotMessageError
|
|
7
7
|
from ..messages.base_message_consumer import MessageConsumer
|
|
8
8
|
from ..types.message_types import Message
|
|
9
|
-
from ..types.output_state import ChatbotResponse, RedirectResponse
|
|
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,14 +136,14 @@ 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.
|
|
146
|
-
return message_response.
|
|
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)
|
|
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
148
|
else:
|
|
152
149
|
raise ChatbotError('Tipo de retorno inválido!')
|
|
@@ -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', ''),
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from typing import Any, Callable
|
|
2
|
+
from .base_message_consumer import MessageConsumer
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TestMessageConsumer(MessageConsumer):
|
|
6
|
+
"""
|
|
7
|
+
Classe de consumidor de mensagens de teste para uso em testes unitários.
|
|
8
|
+
"""
|
|
9
|
+
def __init__(self) -> None:
|
|
10
|
+
super().__init__()
|
|
11
|
+
|
|
12
|
+
@classmethod
|
|
13
|
+
def load_dotenv(cls) -> 'TestMessageConsumer':
|
|
14
|
+
return cls()
|
|
15
|
+
|
|
16
|
+
def start_consume(self, process_message: Callable) -> Any:
|
|
17
|
+
return super().start_consume(process_message)
|
|
@@ -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
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
messageTypes = Union[str, float, int, None]
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ChatbotResponse:
|
|
8
|
+
"""
|
|
9
|
+
Representa a resposta do chatbot, contendo a mensagem a ser enviada ao usuário e a rota a ser seguida.
|
|
10
|
+
|
|
11
|
+
Atributos:
|
|
12
|
+
message (messageTypes): A mensagem de resposta do chatbot. Pode ser uma string, um número, ou None.
|
|
13
|
+
route (str, opcional): A rota para a qual o chatbot deve direcionar após esta mensagem. Padrão é None.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, message: messageTypes = None, route: str = None) -> None:
|
|
17
|
+
"""
|
|
18
|
+
Inicializa a resposta do chatbot com uma mensagem e uma rota opcional.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
message (messageTypes, opcional): A mensagem a ser enviada ao usuário. Pode ser uma string, um número, ou None.
|
|
22
|
+
route (str, opcional): A rota para a qual o chatbot deve direcionar após esta mensagem. Padrão é None.
|
|
23
|
+
"""
|
|
24
|
+
self.message = message
|
|
25
|
+
self.route = route
|
|
26
|
+
|
|
27
|
+
def json(self):
|
|
28
|
+
'''
|
|
29
|
+
Retorna o objeto em formato json.
|
|
30
|
+
'''
|
|
31
|
+
return json.dumps({
|
|
32
|
+
'type': 'message',
|
|
33
|
+
'message': self.message,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class RedirectResponse:
|
|
38
|
+
"""
|
|
39
|
+
Representa uma resposta que redireciona o fluxo do chatbot para uma nova rota.
|
|
40
|
+
|
|
41
|
+
Atributos:
|
|
42
|
+
route (str): A rota para a qual o chatbot deve redirecionar.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def __init__(self, route: str) -> None:
|
|
46
|
+
"""
|
|
47
|
+
Inicializa a resposta de redirecionamento com a rota especificada.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
route (str): A rota para a qual o chatbot deve redirecionar.
|
|
51
|
+
"""
|
|
52
|
+
self.route = route
|
|
53
|
+
|
|
54
|
+
class EndChatResponse:
|
|
55
|
+
"""
|
|
56
|
+
Representa uma resposta que indica o fim do chatbot.
|
|
57
|
+
|
|
58
|
+
Atributos:
|
|
59
|
+
tabulation_id (str): O ID da tabulação do chatbot.
|
|
60
|
+
observations (str): As observações finais do chatbot.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
def __init__(self, tabulation_id: str, observations:str) -> None:
|
|
64
|
+
'''
|
|
65
|
+
Finzaliza e tabula as informações do chatbot.
|
|
66
|
+
'''
|
|
67
|
+
self.tabulation_id = tabulation_id
|
|
68
|
+
self.observations = observations
|
|
69
|
+
|
|
70
|
+
def json(self):
|
|
71
|
+
'''
|
|
72
|
+
Retorna o objeto em formato json.
|
|
73
|
+
'''
|
|
74
|
+
return json.dumps({
|
|
75
|
+
'type': 'tabulate',
|
|
76
|
+
'tabulation_id': self.tabulation_id,
|
|
77
|
+
'observations': self.observations,
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
class TransferToHuman:
|
|
81
|
+
"""
|
|
82
|
+
Representa uma transferencia para um atendente humano.
|
|
83
|
+
"""
|
|
84
|
+
def __init__(self, campaign_id: str, observations:str) -> None:
|
|
85
|
+
'''
|
|
86
|
+
Finzaliza e tabula as informações do chatbot.
|
|
87
|
+
'''
|
|
88
|
+
self.campaign_id = campaign_id
|
|
89
|
+
self.observations = observations
|
|
90
|
+
|
|
91
|
+
def json(self):
|
|
92
|
+
'''
|
|
93
|
+
Retorna o objeto em formato json.
|
|
94
|
+
'''
|
|
95
|
+
return json.dumps({
|
|
96
|
+
'type': 'transfer',
|
|
97
|
+
'campaign_id': self.campaign_id,
|
|
98
|
+
'observations': self.observations,
|
|
99
|
+
})
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Deprecated!!
|
|
3
|
+
"""
|
|
4
|
+
|
|
1
5
|
from abc import ABC, abstractmethod
|
|
2
6
|
|
|
3
7
|
|
|
@@ -31,6 +35,16 @@ class UserState(ABC):
|
|
|
31
35
|
menu (str): O menu a ser definido para o cliente.
|
|
32
36
|
"""
|
|
33
37
|
pass
|
|
38
|
+
|
|
39
|
+
@abstractmethod
|
|
40
|
+
def delete_menu(self, customer_id: str) -> None:
|
|
41
|
+
"""
|
|
42
|
+
Deleta o menu atual para o ID de cliente fornecido.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
customer_id (str): O ID do cliente.
|
|
46
|
+
"""
|
|
47
|
+
pass
|
|
34
48
|
|
|
35
49
|
|
|
36
50
|
class SimpleUserState(UserState):
|
|
@@ -72,3 +86,13 @@ class SimpleUserState(UserState):
|
|
|
72
86
|
"""
|
|
73
87
|
if menu:
|
|
74
88
|
self.states[customer_id] = menu.lower()
|
|
89
|
+
|
|
90
|
+
def delete_menu(self, customer_id: str) -> None:
|
|
91
|
+
"""
|
|
92
|
+
Deleta o menu atual para o ID de cliente fornecido.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
customer_id (str): O ID do cliente.
|
|
96
|
+
"""
|
|
97
|
+
if customer_id in self.states:
|
|
98
|
+
self.states.pop(customer_id)
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
from typing import Union
|
|
2
|
-
|
|
3
|
-
messageTypes = Union[str, float, int, None]
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class ChatbotResponse:
|
|
7
|
-
"""
|
|
8
|
-
Representa a resposta do chatbot, contendo a mensagem a ser enviada ao usuário e a rota a ser seguida.
|
|
9
|
-
|
|
10
|
-
Atributos:
|
|
11
|
-
message (messageTypes): A mensagem de resposta do chatbot. Pode ser uma string, um número, ou None.
|
|
12
|
-
route (str, opcional): A rota para a qual o chatbot deve direcionar após esta mensagem. Padrão é None.
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
def __init__(self, message: messageTypes = None, route: str = None) -> None:
|
|
16
|
-
"""
|
|
17
|
-
Inicializa a resposta do chatbot com uma mensagem e uma rota opcional.
|
|
18
|
-
|
|
19
|
-
Args:
|
|
20
|
-
message (messageTypes, opcional): A mensagem a ser enviada ao usuário. Pode ser uma string, um número, ou None.
|
|
21
|
-
route (str, opcional): A rota para a qual o chatbot deve direcionar após esta mensagem. Padrão é None.
|
|
22
|
-
"""
|
|
23
|
-
self.message = message
|
|
24
|
-
self.route = route
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class RedirectResponse:
|
|
28
|
-
"""
|
|
29
|
-
Representa uma resposta que redireciona o fluxo do chatbot para uma nova rota.
|
|
30
|
-
|
|
31
|
-
Atributos:
|
|
32
|
-
route (str): A rota para a qual o chatbot deve redirecionar.
|
|
33
|
-
"""
|
|
34
|
-
|
|
35
|
-
def __init__(self, route: str) -> None:
|
|
36
|
-
"""
|
|
37
|
-
Inicializa a resposta de redirecionamento com a rota especificada.
|
|
38
|
-
|
|
39
|
-
Args:
|
|
40
|
-
route (str): A rota para a qual o chatbot deve redirecionar.
|
|
41
|
-
"""
|
|
42
|
-
self.route = route
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|