chatgraph 0.3.16__py3-none-any.whl → 0.4.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.

@@ -31,7 +31,7 @@ class ChatbotApp:
31
31
  self.__message_consumer = message_consumer
32
32
  self.__routes = {}
33
33
 
34
- def include_router(self, router: ChatbotRouter, prefix: str):
34
+ def include_router(self, router: ChatbotRouter):
35
35
  """
36
36
  Inclui um roteador de chatbot com um prefixo nas rotas da aplicação.
37
37
 
@@ -42,18 +42,7 @@ class ChatbotApp:
42
42
  Raises:
43
43
  ChatbotError: Se a rota 'start' não for encontrada no roteador.
44
44
  """
45
- if 'start' not in router.routes.keys():
46
- raise ChatbotError('Erro ao incluir rota, start não encontrado!')
47
-
48
- prefixed_routes = {
49
- (
50
- f'start{prefix.lower()}'
51
- if key.lower() == 'start'
52
- else f'start{prefix.lower()}{key.lower().replace("start", "")}'
53
- ): value
54
- for key, value in router.routes.items()
55
- }
56
- self.__routes.update(prefixed_routes)
45
+ self.__routes.update(router.routes)
57
46
 
58
47
  def route(self, route_name: str):
59
48
  """
@@ -67,9 +56,6 @@ class ChatbotApp:
67
56
  """
68
57
  route_name = route_name.strip().lower()
69
58
 
70
- if 'start' not in route_name:
71
- route_name = f'start{route_name}'
72
-
73
59
  def decorator(func):
74
60
  params = dict()
75
61
  signature = inspect.signature(func)
@@ -121,9 +107,10 @@ class ChatbotApp:
121
107
  """
122
108
  customer_id = userCall.customer_id
123
109
  route = userCall.route.lower()
110
+ route_handler = route.split('.')[-1]
124
111
  menu = userCall.menu.lower()
125
112
  obs = userCall.obs
126
- handler = self.__routes.get(route, None)
113
+ handler = self.__routes.get(route_handler, None)
127
114
 
128
115
  if not handler:
129
116
  raise ChatbotMessageError(
@@ -172,7 +159,7 @@ class ChatbotApp:
172
159
  return
173
160
 
174
161
  elif isinstance(userCall_response, RedirectResponse):
175
- route = self.__adjust_route(userCall_response.route, route)
162
+ route = route + '.' + userCall_response.route
176
163
  userCall.route = route
177
164
  return self.process_message(userCall)
178
165
 
@@ -18,7 +18,17 @@ class ChatbotRouter:
18
18
  """
19
19
  Inicializa a classe ChatbotRouter com um dicionário vazio de rotas.
20
20
  """
21
- self.routes = {}
21
+ self.__routes = {}
22
+
23
+ @property
24
+ def routes(self):
25
+ """
26
+ Retorna as rotas registradas no roteador.
27
+
28
+ Returns:
29
+ dict: Um dicionário contendo as rotas e funções associadas.
30
+ """
31
+ return self.__routes
22
32
 
23
33
  def route(self, route_name: str):
24
34
  """
@@ -30,15 +40,14 @@ class ChatbotRouter:
30
40
  Returns:
31
41
  function: O decorador que adiciona a função à rota especificada.
32
42
  """
33
- if 'start' not in route_name:
34
- route_name = f'start{route_name}'
43
+
44
+ route_name = route_name.strip().lower()
35
45
 
36
46
  def decorator(func):
37
47
  params = dict()
38
48
  signature = inspect.signature(func)
39
49
  output_param = signature.return_annotation
40
50
 
41
- # Itera sobre os parâmetros da função e extrai seus tipos
42
51
  for name, param in signature.parameters.items():
43
52
  param_type = (
44
53
  param.annotation
@@ -48,8 +57,7 @@ class ChatbotRouter:
48
57
  params[param_type] = name
49
58
  debug(f'Parameter: {name}, Type: {param_type}')
50
59
 
51
- # Adiciona a função e seus parâmetros à rota especificada
52
- self.routes[route_name.strip().lower()] = {
60
+ self.__routes[route_name] = {
53
61
  'function': func,
54
62
  'params': params,
55
63
  'return': output_param,
@@ -63,7 +71,7 @@ class ChatbotRouter:
63
71
 
64
72
  return decorator
65
73
 
66
- def include_router(self, router: 'ChatbotRouter', prefix: str):
74
+ def include_router(self, router: 'ChatbotRouter'):
67
75
  """
68
76
  Inclui outro roteador com um prefixo nas rotas do roteador atual.
69
77
 
@@ -74,16 +82,4 @@ class ChatbotRouter:
74
82
  Raises:
75
83
  ChatbotError: Se a rota 'start' não for encontrada no roteador fornecido.
76
84
  """
77
- if 'start' not in router.routes.keys():
78
- raise ChatbotError('Erro ao incluir rota, start não encontrado!')
79
-
80
- # Adiciona prefixo às rotas do roteador incluído
81
- prefixed_routes = {
82
- (
83
- f'{prefix.lower()}'
84
- if key.lower() == 'start'
85
- else f'start{prefix.lower()}{key.lower().replace("start", "")}'
86
- ): value
87
- for key, value in router.routes.items()
88
- }
89
- self.routes.update(prefixed_routes)
85
+ self.__routes.update(router.__routes)
@@ -178,6 +178,7 @@ class MessageConsumer:
178
178
  voll_id=user_state.get('voll_id', ''),
179
179
  platform=user_state.get('platform', ''),
180
180
  obs=obs,
181
+ protocol=user_state.get('protocol', ''),
181
182
  ),
182
183
  channel=message.get('channel', ''),
183
184
  customer_phone=message.get('customer_phone', ''),
@@ -26,6 +26,7 @@ class UserState:
26
26
  voll_id: Optional[str]=None,
27
27
  lst_update: Optional[str]=None,
28
28
  obs: Optional[dict] = None,
29
+ protocol: Optional[str] = None,
29
30
  ) -> None:
30
31
 
31
32
  self.customer_id = customer_id
@@ -36,6 +37,7 @@ class UserState:
36
37
  self.direction_in = direction_in
37
38
  self.voll_id = voll_id
38
39
  self.platform = platform
40
+ self.protocol = protocol
39
41
 
40
42
  def __str__(self):
41
43
  return f"UserState:\n\tcustomer_id={self.customer_id},\n\tmenu={self.menu},\n\troute={self.route},\n\tlst_update={self.lst_update},\n\tobs={self.obs},\n\tdirection_in={self.direction_in}"
@@ -53,6 +55,7 @@ class UserState:
53
55
  'direction': self.direction_in,
54
56
  'voll_id': self.voll_id,
55
57
  'platform': self.platform,
58
+ 'protocol': self.protocol,
56
59
  })
57
60
 
58
61
  def update(self, grpc_uri: Optional[str] = None) -> None:
@@ -318,6 +321,26 @@ class UserCall:
318
321
  def customer_id(self):
319
322
  return self.__user_state.customer_id
320
323
 
324
+ @property
325
+ def voll_id(self):
326
+ return self.__user_state.voll_id
327
+
328
+ @property
329
+ def platform(self):
330
+ return self.__user_state.platform
331
+
332
+ @property
333
+ def direction_in(self):
334
+ return self.__user_state.direction_in
335
+
336
+ @property
337
+ def lst_update(self):
338
+ return self.__user_state.lst_update
339
+
340
+ @property
341
+ def protocol(self):
342
+ return self.__user_state.protocol
343
+
321
344
  @menu.setter
322
345
  def menu(self, menu):
323
346
 
chatgraph/types/route.py CHANGED
@@ -30,6 +30,13 @@ class Route:
30
30
  """
31
31
  return self.get_previous()
32
32
 
33
+ @property
34
+ def current_node(self)->str:
35
+ """
36
+ Retorna o nó atual do usuário
37
+ """
38
+ return self.current.split(self.separator)[-1]
39
+
33
40
  def get_previous(self) -> 'Route':
34
41
  """
35
42
  Retorna o caminho anterior ao caminho atual.
@@ -41,7 +48,7 @@ class Route:
41
48
  str: O caminho anterior à rota atual.
42
49
  """
43
50
  if self.current == 'start':
44
- raise RouteError('Não caminho anterior ao start')
51
+ return Route(self.current, self.routes, self.separator)
45
52
 
46
53
  previous_route = self.separator.join(self.current.split(self.separator)[:-1])
47
54
  return Route(previous_route, self.routes, self.separator)
@@ -60,9 +67,9 @@ class Route:
60
67
  Route: O próximo caminho montado.
61
68
  """
62
69
  next_part = next_part.strip().lower()
63
- next_route = f"{self.current.rstrip(self.separator)}{next_part}"
64
- if next_route not in self.routes:
65
- raise RouteError(f'Rota não encontrada: {next_route}')
70
+ next_route = f"{self.current.rstrip(self.separator)}.{next_part}"
71
+ if next_part not in self.routes:
72
+ raise RouteError(f'Rota não encontrada: {next_part}')
66
73
 
67
74
  return Route(next_route, self.routes, self.separator)
68
75
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chatgraph
3
- Version: 0.3.16
3
+ Version: 0.4.1
4
4
  Summary: A user-friendly chatbot library
5
5
  Home-page: https://github.com/irissonnlima/chatgraph
6
6
  License: MIT
@@ -13,6 +13,8 @@ Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Requires-Dist: grpcio (>=1.67.0,<2.0.0)
15
15
  Requires-Dist: grpcio-tools (>=1.67.0,<2.0.0)
16
+ Requires-Dist: matplotlib (>=3.10.0,<4.0.0)
17
+ Requires-Dist: networkx (>=3.4.2,<4.0.0)
16
18
  Requires-Dist: pika (>=1.3.2,<2.0.0)
17
19
  Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
18
20
  Requires-Dist: rich (>=13.8.1,<14.0.0)
@@ -1,12 +1,12 @@
1
1
  chatgraph/__init__.py,sha256=lUMcFMSxKQeHVFq7CyZV2r_UOHAtGGpeXtac0RUd7po,718
2
2
  chatgraph/auth/credentials.py,sha256=xsMEpLQnc66novPjL6upocMcnUnvFJ7yxINzUenkxmc,2388
3
- chatgraph/bot/chatbot_model.py,sha256=uqnIqsNre2KGM4hJhUfUk3oRcapcVsabgLwx7cx9Ids,7324
4
- chatgraph/bot/chatbot_router.py,sha256=tl-4WP9wqUjCIwvtO9kJVUFjN2-mxNDUTRAFL9PXBgI,3028
3
+ chatgraph/bot/chatbot_model.py,sha256=8KvMDst5ZZDs4l3zw2AeuyBM74UqyPFznHe-Ajbb8Yw,6834
4
+ chatgraph/bot/chatbot_router.py,sha256=bVbm9dBoC2OesetXlQJpCrkaiLM3GUro0GrOyCSgreI,2586
5
5
  chatgraph/cli/__init__.py,sha256=tfgYhGoKy1nD4STN4xDh6J4VV55RICk7v1GZmzAg-bM,7413
6
6
  chatgraph/error/chatbot_error.py,sha256=4sEcW8vz0eQk2QDmDygucVM4caHliZW5iH7XJvmLBuk,1897
7
7
  chatgraph/error/route_error.py,sha256=CY8m82ap7-Sr-DXPsolltRW50TqD__5RyXBmNNJCWr8,793
8
8
  chatgraph/gRPC/gRPCCall.py,sha256=jYZg7CvtKWhtv2sQMrSunSmvnnL83MKmNVO8GWmGZ9U,7696
9
- chatgraph/messages/message_consumer.py,sha256=DYPZA-TTXe4jtcdRZUSfPf-QO0B_aXUzSO3FSwfhWlo,8996
9
+ chatgraph/messages/message_consumer.py,sha256=B6ettgby39r1pUw6KyiUlpzXPy5nhFAJiye54Lckoqs,9054
10
10
  chatgraph/pb/userstate.proto,sha256=GgjD1K2t8VxrMLkceVnY043xBdXWTPxBzaBhAbAg7yw,859
11
11
  chatgraph/pb/userstate_pb2.py,sha256=aCS_Muk_uA78buV28g7yi0O2vriTJedT4HKxgzFFUVw,2856
12
12
  chatgraph/pb/userstate_pb2_grpc.py,sha256=QJEGEmdBL6bkxrTI-gNhGbZpPUFuP5jm7eFu8y21PMI,10340
@@ -15,10 +15,10 @@ chatgraph/pb/voll_pb2.py,sha256=WLwE7F1pe_elcnwRnSFqVDcFihLZ3JBq4ScTHNCqWGA,5328
15
15
  chatgraph/pb/voll_pb2_grpc.py,sha256=U-_nXTAIEzo2GMYjHiphbSyTx3zyipsnKebFuZuoU1k,17685
16
16
  chatgraph/types/end_types.py,sha256=--Ty2gM_y7J-yRAvZV26e4HMUpoguAMAhfOIS9-kQTk,1316
17
17
  chatgraph/types/message_types.py,sha256=l488K4sVhTdOY5bbk47Y-qjfvfyn4h7bpmOFf2xGods,3334
18
- chatgraph/types/request_types.py,sha256=Rju__bOLI3AG-l5aYTNv_SwqH_-pu1tNiiHA9PujN_M,11761
19
- chatgraph/types/route.py,sha256=sg0oAsfPlPciDsVa-GAr1AwwypH5EyUKqfo_IYMLOtU,2801
20
- chatgraph-0.3.16.dist-info/entry_points.txt,sha256=bO9_Q-PqE5vCNNo6ke_-3j2gHfKQMDGnKDTkNuCdBuA,48
21
- chatgraph-0.3.16.dist-info/LICENSE,sha256=rVJozpRzDlplOpvI8A1GvmfVS0ReYdZvMWc1j2jV0v8,1090
22
- chatgraph-0.3.16.dist-info/METADATA,sha256=L9uQXpMFqD75L9xUHxTDxSCwZ15t0waU-rWY-g50Q08,12782
23
- chatgraph-0.3.16.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
24
- chatgraph-0.3.16.dist-info/RECORD,,
18
+ chatgraph/types/request_types.py,sha256=uBnqr1KrwgehQ14_RYd82FxxWy5CBNjApyNDYWUBeKE,12331
19
+ chatgraph/types/route.py,sha256=FO5INy5UXgicuQ8FKEZKcPv6WS5YH10dPx2OaPu_0sE,2978
20
+ chatgraph-0.4.1.dist-info/entry_points.txt,sha256=bO9_Q-PqE5vCNNo6ke_-3j2gHfKQMDGnKDTkNuCdBuA,48
21
+ chatgraph-0.4.1.dist-info/LICENSE,sha256=rVJozpRzDlplOpvI8A1GvmfVS0ReYdZvMWc1j2jV0v8,1090
22
+ chatgraph-0.4.1.dist-info/METADATA,sha256=jjujZIbrgTRF86EPPGBEbtnx0tOgX1zS64WZDSh5I0Y,12866
23
+ chatgraph-0.4.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
24
+ chatgraph-0.4.1.dist-info/RECORD,,