chatgraph 0.1.3__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 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
  ]
@@ -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, user_state: UserState, message_consumer: MessageConsumer):
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 = self.__user_state.get_menu(customer_id)
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
- return message_response
143
- elif type(message_response) == ChatbotResponse:
144
- route = self.__adjust_route(message_response.route, menu)
145
- self.__user_state.set_menu(customer_id, route)
146
- return message_response.message
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
- self.__user_state.set_menu(customer_id, route)
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
- customer_id=message.get('customer_id', ''),
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
- customer_id (str): O ID do cliente que enviou ou recebeu a mensagem.
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
- customer_id: str
37
+ user_state: UserState
22
38
  channel: str
23
39
  customer_phone: str
24
40
  company_phone: str
@@ -1,4 +1,5 @@
1
1
  from typing import Union
2
+ import json
2
3
 
3
4
  messageTypes = Union[str, float, int, None]
4
5
 
@@ -22,6 +23,15 @@ class ChatbotResponse:
22
23
  """
23
24
  self.message = message
24
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
+ })
25
35
 
26
36
 
27
37
  class RedirectResponse:
@@ -40,3 +50,50 @@ class RedirectResponse:
40
50
  route (str): A rota para a qual o chatbot deve redirecionar.
41
51
  """
42
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chatgraph
3
- Version: 0.1.3
3
+ Version: 0.2.0
4
4
  Summary: A user-friendly chatbot library
5
5
  Home-page: https://github.com/irissonnlima/chatgraph
6
6
  License: MIT
@@ -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=cy_IzeM8rZps9LxPKvEm9EWBQ_DlMBRm7iViQCxYy7s,6095
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=fpJ_hGO4aZ3wr6DV4i9ctnkHytWhK6ZDpKpJ3vSwRyY,3064
12
+ chatgraph/types/route.py,sha256=nKTqzwGl7d_Bu8G6Sr0EmmhuuiZWKEoSozITRrdyi1g,2587
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,,
@@ -1,16 +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=pyxLKv4PACv6ovAMllS6wd1oqILdOvlRMQ4hR_pjwXQ,6296
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/types/message_types.py,sha256=NBuebmpO2e9ilspBoFgs9O3rY_VQ2AP_Z8Q_nC70nyM,965
10
- chatgraph/types/output_state.py,sha256=ZditFyycd6CEvemrW9c7mThQDP1l6tI_8p19Jgj8pbs,1471
11
- chatgraph/types/route.py,sha256=nKTqzwGl7d_Bu8G6Sr0EmmhuuiZWKEoSozITRrdyi1g,2587
12
- chatgraph/types/user_state.py,sha256=3YkZQ_FfAVrWZqFWLFaNdVOGKYThp-Lip-BbldM35Gc,2321
13
- chatgraph-0.1.3.dist-info/LICENSE,sha256=rVJozpRzDlplOpvI8A1GvmfVS0ReYdZvMWc1j2jV0v8,1090
14
- chatgraph-0.1.3.dist-info/METADATA,sha256=1fDFbBxSMJlEdhb6aPNJpeOHri7QS-SAek-UoJsViy8,5829
15
- chatgraph-0.1.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
16
- chatgraph-0.1.3.dist-info/RECORD,,