chatgraph 0.4.0__py3-none-any.whl → 0.5.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.

@@ -3,106 +3,109 @@ from typing import Optional, Union
3
3
  messageTypes = Union[str, float, int]
4
4
  MessageTypes = (str, float, int)
5
5
 
6
- class Message:
7
- """
8
- Representa uma mensagem enviada ou recebida pelo chatbot.
9
-
10
- Atributos:
11
- message (str): O conteúdo textual da mensagem.
12
- absolute_text (bool): Se True, o texto não será modificado.
13
- """
14
-
15
- def __init__(
16
- self,
17
- text:str,
18
- absolute_text: bool = False,
19
- ) -> None:
20
- self.absolute_text = absolute_text
21
-
22
- if not absolute_text:
23
- text = text.replace('\t', '')
24
-
25
- self.text = text
6
+
7
+ TITLE_MAX_LENGTH = 20
8
+ DETAIL_MAX_LENGTH = 72
9
+
26
10
 
27
11
  class Button:
28
12
  """
29
13
  Representa uma lista rápida de botões.
30
-
14
+
31
15
  Atributos:
32
- text (str): O texto da mensagem.
33
- buttons (list[str]): A lista de botões.
34
- title (str): O título da mensagem.
35
- caption (str): A legenda da mensagem.
16
+ typeButton (str): O tipo do botão.
17
+ title (str): O texto do botão.
18
+ detail (str): A descrição do botão.
36
19
  absolute_text (bool): Se True, o texto não será modificado.
37
-
20
+
38
21
  Limitações:
39
- O número máximo de botões é 3.
40
- O texto do botão deve ter no máximo 20 caracteres.
22
+ O título do botão deve ter no máximo 20 caracteres.
23
+ A descrição do botão deve ter no máximo 72 caracteres.
41
24
  """
25
+
42
26
  def __init__(
43
- self,
44
- text:str,
45
- buttons: list[str],
27
+ self,
46
28
  title: Optional[str] = None,
47
- caption: Optional[str] = None,
48
- absolute_text: bool = False,
49
- ) -> None:
29
+ detail: Optional[str] = None,
30
+ typeButton: Optional[str]="postback",
31
+ absolute_text: Optional[bool] = False,
32
+ ) -> None:
33
+
50
34
  self.absolute_text = absolute_text
51
-
35
+
52
36
  if not absolute_text:
53
- text = text.replace('\t', '')
54
-
55
- assert len(buttons) <= 3, "O número máximo de botões é 3."
56
-
57
- for button in buttons:
58
- assert len(button) <= 20, "O texto do botão deve ter no máximo 20 caracteres."
59
-
60
- self.text = text
61
- self.buttons = buttons
37
+ detail = detail.replace("\t", "")
38
+
39
+ assert (
40
+ len(title) <= TITLE_MAX_LENGTH
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."
45
+
46
+ self.type = typeButton
62
47
  self.title = title
63
- self.caption = caption
48
+ self.detail = detail
49
+
50
+ def to_dict(self):
51
+ return {
52
+ "type": self.type,
53
+ "title": self.title,
54
+ "detail": self.detail,
55
+ }
64
56
 
65
- class ListElements:
57
+
58
+ class Message:
66
59
  """
67
- Representa uma lista de elementos.
68
-
69
- atributos:
70
- text (str): O texto da mensagem.
60
+ Representa uma mensagem universal enviada pelo chatbot.
61
+
62
+ Atributos:
63
+ type (str): O tipo da mensagem.
64
+ url (str): A URL da mensagem.
65
+ filename (str): O nome do arquivo da mensagem.
71
66
  title (str): O título da mensagem.
72
- button_title (str): O título do botão.
73
- elements (list[dict]): A lista de elementos.
67
+ detail (str): A descrição da mensagem.
74
68
  caption (str): A legenda da mensagem.
69
+ buttons (list[Button]): A lista de botões da mensagem.
75
70
  absolute_text (bool): Se True, o texto não será modificado.
76
-
77
- Limitações:
78
- O número máximo de elementos é 10.
79
- O título do elemento deve ter no máximo 24 caracteres.
80
- A descrição do elemento deve ter no máximo 72 caracteres.
81
71
  """
72
+
82
73
  def __init__(
83
- self,
84
- text:str,
85
- button_title: str,
86
- elements: dict,
74
+ self,
75
+ detail: Optional[str] = None,
87
76
  title: Optional[str] = None,
88
77
  caption: Optional[str] = None,
89
- absolute_text: bool = False,
90
- ) -> None:
78
+ type: Optional[str]="message",
79
+ url: Optional[str] = None,
80
+ filename: Optional[str] = None,
81
+ buttons: Optional[list[Button]] = None,
82
+ display_button: Optional[Button] = None,
83
+ absolute_text: Optional[bool] = False,
84
+ ) -> None:
91
85
  self.absolute_text = absolute_text
92
-
86
+
93
87
  if not absolute_text:
94
- text = text.replace('\t', '')
95
-
96
- assert len(elements) <= 10, "O número máximo de elementos é 10."
97
-
98
- for key, value in elements.items():
99
- assert len(key) <= 24, "O título do elemento deve ter no máximo 24 caracteres."
100
- assert len(value) <= 72, "A descrição do elemento deve ter no máximo 72 caracteres."
101
-
102
- self.text = text
88
+ detail = detail.replace("\t", "")
89
+
90
+ self.type = type
91
+ self.url = url
92
+ self.filename = filename
103
93
  self.title = title
104
- self.button_title = button_title
105
- self.elements = elements
94
+ self.detail = detail
106
95
  self.caption = caption
96
+ self.buttons = buttons or []
97
+ self.display_button = display_button
107
98
 
108
-
99
+ def to_dict(self):
100
+ return {
101
+ "message": {
102
+ "type": self.type,
103
+ "url": self.url,
104
+ "filename": self.filename,
105
+ "title": self.title,
106
+ "detail": self.detail,
107
+ "caption": self.caption,
108
+ },
109
+ "buttons": [button.to_dict() for button in self.buttons],
110
+ "display_button": self.display_button.to_dict() if self.display_button else None,
111
+ }