chatgraph 0.1.1__tar.gz → 0.1.3__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chatgraph
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: A user-friendly chatbot library
5
5
  Home-page: https://github.com/irissonnlima/chatgraph
6
6
  License: MIT
@@ -108,11 +108,11 @@ from chatgraph import ChatbotApp, ChatbotRouter, SimpleUserState, RabbitMessageC
108
108
  # Definindo rotas com ChatbotRouter
109
109
  router = ChatbotRouter()
110
110
 
111
- @router.route("START")
111
+ @router.route("start")
112
112
  def say_hello():
113
- return ChatbotResponse(message="Hello! How can I assist you today?", route="HELP")
113
+ return ChatbotResponse(message="Hello! How can I assist you today?", route=".help")
114
114
 
115
- @router.route("/HELP")
115
+ @router.route(".help")
116
116
  def provide_help():
117
117
  return ChatbotResponse(message="Here are some things I can help with: ...")
118
118
 
@@ -91,11 +91,11 @@ from chatgraph import ChatbotApp, ChatbotRouter, SimpleUserState, RabbitMessageC
91
91
  # Definindo rotas com ChatbotRouter
92
92
  router = ChatbotRouter()
93
93
 
94
- @router.route("START")
94
+ @router.route("start")
95
95
  def say_hello():
96
- return ChatbotResponse(message="Hello! How can I assist you today?", route="HELP")
96
+ return ChatbotResponse(message="Hello! How can I assist you today?", route=".help")
97
97
 
98
- @router.route("/HELP")
98
+ @router.route(".help")
99
99
  def provide_help():
100
100
  return ChatbotResponse(message="Here are some things I can help with: ...")
101
101
 
@@ -38,16 +38,16 @@ class ChatbotApp(ABC):
38
38
  prefix (str): O prefixo a ser adicionado às rotas do roteador.
39
39
 
40
40
  Raises:
41
- ChatbotError: Se a rota 'START' não for encontrada no roteador.
41
+ ChatbotError: Se a rota 'start' não for encontrada no roteador.
42
42
  """
43
- if 'START' not in router.routes.keys():
44
- raise ChatbotError('Erro ao incluir rota, START não encontrado!')
43
+ if 'start' not in router.routes.keys():
44
+ raise ChatbotError('Erro ao incluir rota, start não encontrado!')
45
45
 
46
46
  prefixed_routes = {
47
47
  (
48
- f'START{prefix.upper()}'
49
- if key.upper() == 'START'
50
- else f'START{prefix.upper()}{key.upper().replace("START", "")}'
48
+ f'start{prefix.lower()}'
49
+ if key.lower() == 'start'
50
+ else f'start{prefix.lower()}{key.lower().replace("start", "")}'
51
51
  ): value
52
52
  for key, value in router.routes.items()
53
53
  }
@@ -63,10 +63,10 @@ class ChatbotApp(ABC):
63
63
  Returns:
64
64
  function: O decorador que adiciona a função à rota especificada.
65
65
  """
66
- route_name = route_name.strip().upper()
66
+ route_name = route_name.strip().lower()
67
67
 
68
- if 'START' not in route_name:
69
- route_name = f'START{route_name}'
68
+ if 'start' not in route_name:
69
+ route_name = f'start{route_name}'
70
70
 
71
71
  def decorator(func):
72
72
  params = dict()
@@ -119,7 +119,7 @@ class ChatbotApp(ABC):
119
119
  customer_id = message.customer_id
120
120
 
121
121
  menu = self.__user_state.get_menu(customer_id)
122
- menu = menu.upper()
122
+ menu = menu.lower()
123
123
  handler = self.__routes.get(menu, None)
124
124
 
125
125
  if not handler:
@@ -165,7 +165,7 @@ class ChatbotApp(ABC):
165
165
  if not route:
166
166
  return absolute_route
167
167
 
168
- if 'START' not in route:
168
+ if 'start' not in route:
169
169
  route = absolute_route + route
170
170
 
171
171
  return route
@@ -29,8 +29,8 @@ class ChatbotRouter:
29
29
  Returns:
30
30
  function: O decorador que adiciona a função à rota especificada.
31
31
  """
32
- if 'START' not in route_name:
33
- route_name = f'START{route_name}'
32
+ if 'start' not in route_name:
33
+ route_name = f'start{route_name}'
34
34
 
35
35
  def decorator(func):
36
36
  params = dict()
@@ -46,7 +46,7 @@ class ChatbotRouter:
46
46
  params[param_type] = name
47
47
  debug(f'Parameter: {name}, Type: {param_type}')
48
48
 
49
- self.routes[route_name.strip().upper()] = {
49
+ self.routes[route_name.strip().lower()] = {
50
50
  'function': func,
51
51
  'params': params,
52
52
  'return': output_param,
@@ -69,16 +69,16 @@ class ChatbotRouter:
69
69
  prefix (str): O prefixo a ser adicionado às rotas do roteador.
70
70
 
71
71
  Raises:
72
- ChatbotError: Se a rota 'START' não for encontrada no roteador fornecido.
72
+ ChatbotError: Se a rota 'start' não for encontrada no roteador fornecido.
73
73
  """
74
- if 'START' not in router.routes.keys():
75
- raise ChatbotError('Erro ao incluir rota, START não encontrado!')
74
+ if 'start' not in router.routes.keys():
75
+ raise ChatbotError('Erro ao incluir rota, start não encontrado!')
76
76
 
77
77
  prefixed_routes = {
78
78
  (
79
- f'{prefix.upper()}'
80
- if key.upper() == 'START'
81
- else f'START{prefix.upper()}{key.upper().replace("START", "")}'
79
+ f'{prefix.lower()}'
80
+ if key.lower() == 'start'
81
+ else f'start{prefix.lower()}{key.lower().replace("start", "")}'
82
82
  ): value
83
83
  for key, value in router.routes.items()
84
84
  }
@@ -10,31 +10,33 @@ class Route:
10
10
  routes (list[str]): A lista de todas as rotas disponíveis no fluxo.
11
11
  """
12
12
 
13
- def __init__(self, current: str, routes: list[str]):
13
+ def __init__(self, current: str, routes: list[str], separator:str='.'):
14
14
  """
15
15
  Inicializa a rota com a rota atual e a lista de rotas disponíveis.
16
16
 
17
17
  Args:
18
18
  current (str): A rota atual.
19
19
  routes (list[str]): A lista de todas as rotas disponíveis no fluxo.
20
+ separator (str): O separador de partes de rota. Padrão é '.'.
20
21
  """
21
22
  self.current = current
22
23
  self.routes = routes
24
+ self.separator = separator
23
25
 
24
26
  def get_previous(self) -> str:
25
27
  """
26
28
  Retorna o caminho anterior ao caminho atual.
27
29
 
28
30
  Raises:
29
- RouteError: Se a rota atual for 'START', indicando que não há caminho anterior.
31
+ RouteError: Se a rota atual for 'start', indicando que não há caminho anterior.
30
32
 
31
33
  Returns:
32
34
  str: O caminho anterior à rota atual.
33
35
  """
34
- if self.current == 'START':
35
- raise RouteError('Não há caminho anterior ao START')
36
+ if self.current == 'start':
37
+ raise RouteError('Não há caminho anterior ao start')
36
38
 
37
- previous_route = '/'.join(self.current.split('/')[:-1])
39
+ previous_route = self.separator.join(self.current.split(self.separator)[:-1])
38
40
  return previous_route
39
41
 
40
42
  def get_next(self, next_part: str) -> str:
@@ -50,8 +52,8 @@ class Route:
50
52
  Returns:
51
53
  str: O próximo caminho construído a partir da rota atual e da parte fornecida.
52
54
  """
53
- next_part = next_part.strip().upper()
54
- next_route = f"{self.current.rstrip('/')}{next_part}"
55
+ next_part = next_part.strip().lower()
56
+ next_route = f"{self.current.rstrip(self.separator)}{next_part}"
55
57
  if next_route not in self.routes:
56
58
  raise RouteError(f'Rota não encontrada: {next_route}')
57
59
  return next_route
@@ -49,7 +49,7 @@ class SimpleUserState(UserState):
49
49
 
50
50
  def get_menu(self, customer_id: str) -> str:
51
51
  """
52
- Retorna o menu atual para o ID de cliente fornecido. Se o cliente não tiver um menu definido, define 'START' como padrão.
52
+ Retorna o menu atual para o ID de cliente fornecido. Se o cliente não tiver um menu definido, define 'start' como padrão.
53
53
 
54
54
  Args:
55
55
  customer_id (str): O ID do cliente.
@@ -57,8 +57,8 @@ class SimpleUserState(UserState):
57
57
  Returns:
58
58
  str: O menu atual associado ao cliente.
59
59
  """
60
- menu = self.states.get(customer_id, 'START')
61
- if menu == 'START':
60
+ menu = self.states.get(customer_id, 'start')
61
+ if menu == 'start':
62
62
  self.set_menu(customer_id, menu)
63
63
  return menu
64
64
 
@@ -71,4 +71,4 @@ class SimpleUserState(UserState):
71
71
  menu (str | None): O menu a ser definido para o cliente. Se None, não faz nenhuma alteração.
72
72
  """
73
73
  if menu:
74
- self.states[customer_id] = menu.upper()
74
+ self.states[customer_id] = menu.lower()
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "chatgraph"
3
- version = "0.1.1"
3
+ version = "0.1.3"
4
4
  description = "A user-friendly chatbot library"
5
5
  authors = ["Irisson N. Lima <irisson.lima@verdecard.com.br>"]
6
6
  readme = "README.md"
File without changes