chatgraph 0.2.6__py3-none-any.whl → 0.3.1__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.

@@ -13,7 +13,12 @@ class ChatbotResponse:
13
13
  route (str, opcional): A rota para a qual o chatbot deve direcionar após esta mensagem. Padrão é None.
14
14
  """
15
15
 
16
- def __init__(self, message: messageTypes = None, route: str = None) -> None:
16
+ def __init__(
17
+ self,
18
+ message: messageTypes = None,
19
+ route: str = None,
20
+ abs_text:bool=False
21
+ ) -> None:
17
22
  """
18
23
  Inicializa a resposta do chatbot com uma mensagem e uma rota opcional.
19
24
 
@@ -21,6 +26,12 @@ class ChatbotResponse:
21
26
  message (messageTypes, opcional): A mensagem a ser enviada ao usuário. Pode ser uma string, um número, ou None.
22
27
  route (str, opcional): A rota para a qual o chatbot deve direcionar após esta mensagem. Padrão é None.
23
28
  """
29
+ if not message:
30
+ message = ''
31
+
32
+ if not abs_text:
33
+ message = message.replace('\t', '')
34
+
24
35
  self.message = message
25
36
  self.route = route
26
37
 
@@ -96,4 +107,32 @@ class TransferToHuman:
96
107
  'type': 'transfer',
97
108
  'campaign_id': self.campaign_id,
98
109
  'observations': self.observations,
110
+ }
111
+
112
+ class RedirectEntireChatbot:
113
+ """
114
+ Representa uma resposta que redireciona o fluxo do chatbot para um outro menu.
115
+
116
+ Atributos:
117
+ menu (str): O menu para o qual o chatbot deve redirecionar.
118
+ route (str): A rota para a qual o chatbot deve redirecionar.
119
+ """
120
+
121
+ def __init__(self, menu:str, route: str) -> None:
122
+ """
123
+ Inicializa a resposta de redirecionamento com a rota especificada.
124
+
125
+ Args:
126
+ route (str): A rota para a qual o chatbot deve redirecionar.
127
+ """
128
+ self.route = route
129
+ self.menu = menu
130
+ def json(self):
131
+ '''
132
+ Retorna o objeto em formato json.
133
+ '''
134
+ return {
135
+ 'type': 'redirect',
136
+ 'menu': self.menu,
137
+ 'route': self.route,
99
138
  }
chatgraph/types/route.py CHANGED
@@ -23,6 +23,13 @@ class Route:
23
23
  self.routes = routes
24
24
  self.separator = separator
25
25
 
26
+ @property
27
+ def previous(self)->str:
28
+ """
29
+ Retorna a rota anterior a atual do usuário
30
+ """
31
+ return self.get_previous()
32
+
26
33
  def get_previous(self) -> str:
27
34
  """
28
35
  Retorna o caminho anterior ao caminho atual.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chatgraph
3
- Version: 0.2.6
3
+ Version: 0.3.1
4
4
  Summary: A user-friendly chatbot library
5
5
  Home-page: https://github.com/irissonnlima/chatgraph
6
6
  License: MIT
@@ -11,7 +11,10 @@ Requires-Python: >=3.12,<4.0
11
11
  Classifier: License :: OSI Approved :: MIT License
12
12
  Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Dist: grpcio (>=1.66.2,<2.0.0)
15
+ Requires-Dist: grpcio-tools (>=1.66.2,<2.0.0)
14
16
  Requires-Dist: pika (>=1.3.2,<2.0.0)
17
+ Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
15
18
  Requires-Dist: rich (>=13.8.1,<14.0.0)
16
19
  Project-URL: Repository, https://github.com/irissonnlima/chatgraph
17
20
  Description-Content-Type: text/markdown
@@ -0,0 +1,21 @@
1
+ chatgraph/__init__.py,sha256=OnPa3kE9pTXlxnkwwc45_2F6bqfR_GZAFal6-FFeT_U,648
2
+ chatgraph/auth/credentials.py,sha256=xsMEpLQnc66novPjL6upocMcnUnvFJ7yxINzUenkxmc,2388
3
+ chatgraph/bot/chatbot_model.py,sha256=DQgEXDs3XWMqYdZ7XA1G2f6XmpD54x1cLbHGub2MAtw,7572
4
+ chatgraph/bot/chatbot_router.py,sha256=tl-4WP9wqUjCIwvtO9kJVUFjN2-mxNDUTRAFL9PXBgI,3028
5
+ chatgraph/error/chatbot_error.py,sha256=4sEcW8vz0eQk2QDmDygucVM4caHliZW5iH7XJvmLBuk,1897
6
+ chatgraph/error/route_error.py,sha256=CY8m82ap7-Sr-DXPsolltRW50TqD__5RyXBmNNJCWr8,793
7
+ chatgraph/gRPC/gRPCCall.py,sha256=g1VGr6z-_IN2J3tSFAXqM1E2F8xx_p5noH3e_klJiKc,4478
8
+ chatgraph/messages/message_consumer.py,sha256=8GOhBPE8ntSf74prw8STCUqi9jfW9gAmMdH9RAqnwEA,8978
9
+ chatgraph/pb/userstate.proto,sha256=3uWtonkgBG-5jk7Du7uKDQwFnoNQaUZYVr1lb77EJSA,630
10
+ chatgraph/pb/userstate_pb2.py,sha256=yJepkWX2mLQpY0I4qhfrObrYfRAmnq4mccPTMlCV-os,2363
11
+ chatgraph/pb/userstate_pb2_grpc.py,sha256=QS8-9X6WDeurl4DAI0dzvCdGbQusHlMON0_p1QqmuEs,8635
12
+ chatgraph/pb/voll.proto,sha256=qFV0_MLUTsVcDdEWz9EVWObn3Nu-tNwX2aGeKPxDtE8,716
13
+ chatgraph/pb/voll_pb2.py,sha256=aspT1ynrGTKh_SQcIoEb_uSJ7j_nKpxEdyj-hkr4lTI,2519
14
+ chatgraph/pb/voll_pb2_grpc.py,sha256=RFW3_dbzz_INJG8D1LQmmdyEr7ajLRqT1JPl0D-Hgso,6742
15
+ chatgraph/types/message_types.py,sha256=ICFa0mG1so2hBo82YM4tx695P781a5I3zqVL48soRog,6529
16
+ chatgraph/types/output_state.py,sha256=lwnQt_Z1MCdvDya1Sv_lJ13MM6qKsYJMaSMfXYhW_aw,4079
17
+ chatgraph/types/route.py,sha256=J1Bm5C3PDwdUy6RCIR4sK94ljyrsLmyKOjKFnyJ6Dsg,2753
18
+ chatgraph-0.3.1.dist-info/LICENSE,sha256=rVJozpRzDlplOpvI8A1GvmfVS0ReYdZvMWc1j2jV0v8,1090
19
+ chatgraph-0.3.1.dist-info/METADATA,sha256=vPUUgVQXPec2pesOTKJhJHzb2rdpp1Pi51c40qR5hgE,6000
20
+ chatgraph-0.3.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
21
+ chatgraph-0.3.1.dist-info/RECORD,,
@@ -1,40 +0,0 @@
1
- from abc import ABC, abstractmethod
2
- from typing import Any, Callable
3
-
4
-
5
- class MessageConsumer(ABC):
6
- """
7
- Classe base abstrata para consumidores de mensagens no sistema do chatbot.
8
-
9
- Esta classe define a interface que todos os consumidores de mensagens devem implementar para serem usados no sistema do chatbot.
10
- """
11
-
12
- @abstractmethod
13
- def start_consume(self, process_message: Callable) -> Any:
14
- """
15
- Inicia o consumo de mensagens e processa cada mensagem usando a função fornecida.
16
-
17
- Args:
18
- process_message (Callable): Função de callback que processa cada mensagem recebida.
19
-
20
- Returns:
21
- Any: O resultado do processo de consumo de mensagens, dependendo da implementação concreta.
22
- """
23
- pass
24
-
25
- @abstractmethod
26
- def load_dotenv(self) -> 'MessageConsumer':
27
- """
28
- Carrega variáveis de ambiente para configurar o consumidor de mensagens.
29
-
30
- Returns:
31
- MessageConsumer: A instância do consumidor de mensagens configurado.
32
- """
33
- pass
34
-
35
- @abstractmethod
36
- def reprer(self) -> str:
37
- '''
38
- Retorna uma representação textual do consumidor de mensagens.
39
- '''
40
- pass
@@ -1,23 +0,0 @@
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
@@ -1,79 +0,0 @@
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
@@ -1,17 +0,0 @@
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)
@@ -1,98 +0,0 @@
1
- """
2
- Deprecated!!
3
- """
4
-
5
- from abc import ABC, abstractmethod
6
-
7
-
8
- class UserState(ABC):
9
- """
10
- Classe abstrata para gerenciar o estado do usuário no fluxo do chatbot.
11
-
12
- Esta classe define a interface para implementar o gerenciamento de estado do usuário, incluindo métodos para obter e definir o menu atual do usuário.
13
- """
14
-
15
- @abstractmethod
16
- def get_menu(self, customer_id: str) -> str:
17
- """
18
- Retorna o menu atual para o ID de cliente fornecido.
19
-
20
- Args:
21
- customer_id (str): O ID do cliente.
22
-
23
- Returns:
24
- str: O menu atual associado ao cliente.
25
- """
26
- pass
27
-
28
- @abstractmethod
29
- def set_menu(self, customer_id: str, menu: str) -> None:
30
- """
31
- Define o menu atual para o ID de cliente fornecido.
32
-
33
- Args:
34
- customer_id (str): O ID do cliente.
35
- menu (str): O menu a ser definido para o cliente.
36
- """
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
48
-
49
-
50
- class SimpleUserState(UserState):
51
- """
52
- Implementação simples de UserState que armazena o estado do usuário em um dicionário em memória.
53
-
54
- Atributos:
55
- states (dict): Dicionário que armazena o estado de menu atual para cada cliente.
56
- """
57
-
58
- def __init__(self):
59
- """
60
- Inicializa o estado do usuário com um dicionário vazio.
61
- """
62
- self.states = {}
63
-
64
- def get_menu(self, customer_id: str) -> str:
65
- """
66
- Retorna o menu atual para o ID de cliente fornecido. Se o cliente não tiver um menu definido, define 'start' como padrão.
67
-
68
- Args:
69
- customer_id (str): O ID do cliente.
70
-
71
- Returns:
72
- str: O menu atual associado ao cliente.
73
- """
74
- menu = self.states.get(customer_id, 'start')
75
- if menu == 'start':
76
- self.set_menu(customer_id, menu)
77
- return menu
78
-
79
- def set_menu(self, customer_id: str, menu: str | None = None) -> None:
80
- """
81
- Define o menu atual para o ID de cliente fornecido. Converte o nome do menu para maiúsculas.
82
-
83
- Args:
84
- customer_id (str): O ID do cliente.
85
- menu (str | None): O menu a ser definido para o cliente. Se None, não faz nenhuma alteração.
86
- """
87
- if menu:
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,19 +0,0 @@
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=4XTlAxFIpEeNp7hwxC3UjhnDeZMFD3QH3AD09GDxD78,6943
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=4qZj69eDtqeqmSDSfGsCRt6hyypSPTSry3pmRh8r8nM,1269
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
11
- chatgraph/messages/test_message_consumer.py,sha256=9XIkbCHd1S6S8pINRT-SLEvUT0TQWBCsdPhYN6PpZ2s,518
12
- chatgraph/types/message_types.py,sha256=7eB45hrlbYKV1Lp9vysR6V7OXNsySpeKYbGBc2Ux6xE,1363
13
- chatgraph/types/output_state.py,sha256=_pbCssNM4ls7tFG1Wbdg8BJN6ih0q3x2onXZdvZcGDo,3025
14
- chatgraph/types/route.py,sha256=nKTqzwGl7d_Bu8G6Sr0EmmhuuiZWKEoSozITRrdyi1g,2587
15
- chatgraph/types/user_state.py,sha256=nliV-kC_yOmYoFh8CQSfT92DbOv4BLF0vvn8kotnDog,2884
16
- chatgraph-0.2.6.dist-info/LICENSE,sha256=rVJozpRzDlplOpvI8A1GvmfVS0ReYdZvMWc1j2jV0v8,1090
17
- chatgraph-0.2.6.dist-info/METADATA,sha256=lRvleQCJFEMf1tjGSNYaXQZ4n_tFzrVpSNp85sWX-1Y,5868
18
- chatgraph-0.2.6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
19
- chatgraph-0.2.6.dist-info/RECORD,,