chatgraph 0.5.1__tar.gz → 0.5.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.

Files changed (22) hide show
  1. {chatgraph-0.5.1 → chatgraph-0.5.3}/PKG-INFO +1 -1
  2. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/bot/chatbot_model.py +8 -1
  3. chatgraph-0.5.3/chatgraph/types/background_task.py +27 -0
  4. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/types/message_types.py +6 -5
  5. {chatgraph-0.5.1 → chatgraph-0.5.3}/pyproject.toml +1 -1
  6. chatgraph-0.5.1/chatgraph/types/background_task.py +0 -23
  7. {chatgraph-0.5.1 → chatgraph-0.5.3}/LICENSE +0 -0
  8. {chatgraph-0.5.1 → chatgraph-0.5.3}/README.md +0 -0
  9. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/__init__.py +0 -0
  10. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/auth/credentials.py +0 -0
  11. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/bot/chatbot_router.py +0 -0
  12. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/cli/__init__.py +0 -0
  13. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/error/chatbot_error.py +0 -0
  14. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/error/route_error.py +0 -0
  15. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/gRPC/gRPCCall.py +0 -0
  16. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/messages/message_consumer.py +0 -0
  17. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/pb/router.proto +0 -0
  18. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/pb/router_pb2.py +0 -0
  19. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/pb/router_pb2_grpc.py +0 -0
  20. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/types/end_types.py +0 -0
  21. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/types/request_types.py +0 -0
  22. {chatgraph-0.5.1 → chatgraph-0.5.3}/chatgraph/types/route.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chatgraph
3
- Version: 0.5.1
3
+ Version: 0.5.3
4
4
  Summary: A user-friendly chatbot library
5
5
  Home-page: https://github.com/irissonnlima/chatgraph
6
6
  License: MIT
@@ -10,7 +10,7 @@ from ..types.message_types import Message, Button
10
10
  from ..types.end_types import RedirectResponse, EndChatResponse, TransferToHuman
11
11
  from ..types.route import Route
12
12
  from .chatbot_router import ChatbotRouter
13
-
13
+ from ..types.background_task import BackgroundTask
14
14
 
15
15
  class ChatbotApp:
16
16
  """
@@ -177,8 +177,15 @@ class ChatbotApp:
177
177
  userCall.route = route
178
178
  await self.process_message(userCall)
179
179
 
180
+
180
181
  elif not userCall_response:
182
+ route = route + "." + route.split(".")[-1]
183
+ userCall.route = route
181
184
  return
185
+
186
+ elif isinstance(userCall_response, BackgroundTask):
187
+ response = await userCall_response.run()
188
+ await self.__process_func_response(response, userCall, route=route)
182
189
 
183
190
  else:
184
191
  error("Tipo de retorno inválido!")
@@ -0,0 +1,27 @@
1
+ import asyncio
2
+ from typing import Any, Callable
3
+ import threading
4
+
5
+ class BackgroundTask:
6
+ def __init__(self, func: Callable, *args: Any, **kwargs: Any) -> None:
7
+ """
8
+ Inicia uma função de forma assíncrona em segundo plano e printa sua saída.
9
+
10
+ Args:
11
+ func (Callable): A função a ser executada.
12
+ args (Any): Argumentos posicionais a serem passados para a função.
13
+ kwargs (Any): Argumentos nomeados a serem passados para a função.
14
+ """
15
+
16
+ if not asyncio.iscoroutinefunction(func):
17
+ raise TypeError("A função fornecida deve ser uma coroutine (async def).")
18
+
19
+ self.args = args
20
+ self.kwargs = kwargs
21
+ self.func = func
22
+
23
+ async def run(self):
24
+ """
25
+ Executa a função em segundo plano.
26
+ """
27
+ return await self.func(*self.args, **self.kwargs)
@@ -33,15 +33,16 @@ class Button:
33
33
 
34
34
  self.absolute_text = absolute_text
35
35
 
36
- if not absolute_text:
36
+ if not absolute_text and detail:
37
37
  detail = detail.replace("\t", "")
38
38
 
39
39
  assert (
40
40
  len(title) <= TITLE_MAX_LENGTH
41
41
  ), f"O texto do botão deve ter no máximo {TITLE_MAX_LENGTH} caracteres."
42
- assert (
43
- len(detail) <= DETAIL_MAX_LENGTH
44
- ), f"A descrição do botão deve ter no máximo {DETAIL_MAX_LENGTH} caracteres."
42
+ if detail:
43
+ assert (
44
+ len(detail) <= DETAIL_MAX_LENGTH
45
+ ), f"A descrição do botão deve ter no máximo {DETAIL_MAX_LENGTH} caracteres."
45
46
 
46
47
  self.type = typeButton
47
48
  self.title = title
@@ -84,7 +85,7 @@ class Message:
84
85
  ) -> None:
85
86
  self.absolute_text = absolute_text
86
87
 
87
- if not absolute_text:
88
+ if not absolute_text and type == "message":
88
89
  detail = detail.replace("\t", "")
89
90
 
90
91
  self.type = type
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "chatgraph"
3
- version = "0.5.1"
3
+ version = "0.5.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"
@@ -1,23 +0,0 @@
1
- import asyncio
2
- from typing import Any, Callable
3
- import threading
4
-
5
- def BackgroundTask(func: Callable, *args: Any, **kwargs: Any) -> None:
6
- """
7
- Inicia uma função de forma assíncrona em segundo plano e printa sua saída.
8
-
9
- :param func: Função assíncrona a ser executada.
10
- :param args: Argumentos posicionais para a função.
11
- :param kwargs: Argumentos nomeados para a função.
12
- """
13
- if asyncio.iscoroutinefunction(func):
14
- def start_loop():
15
- loop = asyncio.new_event_loop()
16
- asyncio.set_event_loop(loop)
17
- loop.run_until_complete(func(*args, **kwargs))
18
-
19
- # Executa o loop de eventos em uma thread separada
20
- thread = threading.Thread(target=start_loop)
21
- thread.start()
22
- else:
23
- raise TypeError("A função fornecida deve ser uma coroutine (async def).")
File without changes
File without changes