chatgraph 0.5.3__py3-none-any.whl → 0.6.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 +25 -16
- chatgraph/bot/chatbot_model.py +17 -3
- chatgraph/gRPC/gRPCCall.py +17 -3
- chatgraph/pb/router.proto +17 -0
- chatgraph/pb/router_pb2.py +35 -31
- chatgraph/pb/router_pb2_grpc.py +505 -319
- chatgraph/types/end_types.py +22 -8
- chatgraph/types/image.py +36 -0
- chatgraph/types/request_types.py +45 -9
- {chatgraph-0.5.3.dist-info → chatgraph-0.6.0.dist-info}/METADATA +2 -1
- chatgraph-0.6.0.dist-info/RECORD +23 -0
- chatgraph-0.5.3.dist-info/RECORD +0 -22
- {chatgraph-0.5.3.dist-info → chatgraph-0.6.0.dist-info}/LICENSE +0 -0
- {chatgraph-0.5.3.dist-info → chatgraph-0.6.0.dist-info}/WHEEL +0 -0
- {chatgraph-0.5.3.dist-info → chatgraph-0.6.0.dist-info}/entry_points.txt +0 -0
chatgraph/types/end_types.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
class RedirectResponse:
|
|
3
2
|
"""
|
|
4
3
|
Representa uma resposta que redireciona o fluxo do chatbot para uma nova rota.
|
|
@@ -16,6 +15,7 @@ class RedirectResponse:
|
|
|
16
15
|
"""
|
|
17
16
|
self.route = route
|
|
18
17
|
|
|
18
|
+
|
|
19
19
|
class EndChatResponse:
|
|
20
20
|
"""
|
|
21
21
|
Representa uma resposta que indica o fim do chatbot.
|
|
@@ -25,21 +25,35 @@ class EndChatResponse:
|
|
|
25
25
|
observations (str): As observações finais do chatbot.
|
|
26
26
|
"""
|
|
27
27
|
|
|
28
|
-
def __init__(self, tabulation_id: str, observations:str) -> None:
|
|
29
|
-
|
|
28
|
+
def __init__(self, tabulation_id: str, observations: str) -> None:
|
|
29
|
+
"""
|
|
30
30
|
Finzaliza e tabula as informações do chatbot.
|
|
31
|
-
|
|
31
|
+
"""
|
|
32
32
|
self.tabulation_id = tabulation_id
|
|
33
33
|
self.observations = observations
|
|
34
34
|
|
|
35
|
+
|
|
35
36
|
class TransferToHuman:
|
|
36
37
|
"""
|
|
37
38
|
Representa uma transferencia para um atendente humano.
|
|
38
39
|
"""
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
|
|
41
|
+
def __init__(self, campaign_id: str, observations: str) -> None:
|
|
42
|
+
"""
|
|
41
43
|
Finzaliza e tabula as informações do chatbot.
|
|
42
|
-
|
|
44
|
+
"""
|
|
43
45
|
self.campaign_id = campaign_id
|
|
44
46
|
self.observations = observations
|
|
45
|
-
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class TransferToMenu:
|
|
50
|
+
"""
|
|
51
|
+
Representa uma transferencia para outro Menu.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(self, menu: str, user_message: str) -> None:
|
|
55
|
+
"""
|
|
56
|
+
Finzaliza e tabula as informações do chatbot.
|
|
57
|
+
"""
|
|
58
|
+
self.menu = menu.lower()
|
|
59
|
+
self.user_message = user_message
|
chatgraph/types/image.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
import base64
|
|
3
|
+
from chatgraph.types.message_types import Message
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ImageData:
|
|
7
|
+
def __init__(self, url: str, image_bytes: bytes = None):
|
|
8
|
+
if not url and not image_bytes:
|
|
9
|
+
raise ValueError("URL or image bytes must be provided.")
|
|
10
|
+
|
|
11
|
+
self.url = url
|
|
12
|
+
self.image_bytes = image_bytes
|
|
13
|
+
|
|
14
|
+
# Create hash of image bytes if available, otherwise use URL
|
|
15
|
+
hash_input = image_bytes if image_bytes else url.encode("utf-8")
|
|
16
|
+
|
|
17
|
+
# Create SHA-256 hash and encode in base64
|
|
18
|
+
self.image_id = base64.b64encode(hashlib.sha256(hash_input).digest()).decode(
|
|
19
|
+
"utf-8"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class SendImage:
|
|
24
|
+
def __init__(self, image: ImageData, message: Message):
|
|
25
|
+
if not isinstance(image, ImageData):
|
|
26
|
+
raise TypeError("Expected an instance of ImageData.")
|
|
27
|
+
|
|
28
|
+
self.type = "image"
|
|
29
|
+
self.image = image
|
|
30
|
+
self.message = message
|
|
31
|
+
|
|
32
|
+
def to_dict(self):
|
|
33
|
+
return {
|
|
34
|
+
"file_id": self.image.image_id,
|
|
35
|
+
"message": self.message.to_dict(),
|
|
36
|
+
}
|
chatgraph/types/request_types.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from chatgraph.gRPC.gRPCCall import RouterServiceClient
|
|
2
|
+
from chatgraph.types.image import ImageData, SendImage
|
|
2
3
|
from chatgraph.types.message_types import Message, Button, MessageTypes, messageTypes
|
|
3
4
|
from typing import Optional
|
|
4
5
|
from datetime import datetime
|
|
@@ -157,7 +158,7 @@ class UserCall:
|
|
|
157
158
|
|
|
158
159
|
def __str__(self):
|
|
159
160
|
return f"UserCall({self.type}, {self.__type_message}, {self.__content_message}, {self.__user_state})"
|
|
160
|
-
|
|
161
|
+
|
|
161
162
|
def send(
|
|
162
163
|
self,
|
|
163
164
|
message: messageTypes | Message,
|
|
@@ -174,11 +175,27 @@ class UserCall:
|
|
|
174
175
|
detail=str(message),
|
|
175
176
|
)
|
|
176
177
|
|
|
178
|
+
if isinstance(message, ImageData):
|
|
179
|
+
message = SendImage(
|
|
180
|
+
image=message,
|
|
181
|
+
message=Message(type="message", detail=""),
|
|
182
|
+
)
|
|
183
|
+
|
|
177
184
|
if isinstance(message, Message):
|
|
178
185
|
self.__send(message)
|
|
186
|
+
elif isinstance(message, SendImage):
|
|
187
|
+
self.__send_image(message)
|
|
179
188
|
else:
|
|
180
189
|
raise ValueError("Tipo de mensagem inválido.")
|
|
181
190
|
|
|
191
|
+
def __send_image(self, message: SendImage) -> None:
|
|
192
|
+
dict_message = message.to_dict()
|
|
193
|
+
dict_message["message"]["chat_id"] = self.__user_state.chatID.to_dict()
|
|
194
|
+
response = self.__router_client.send_image(dict_message)
|
|
195
|
+
|
|
196
|
+
if not response.status:
|
|
197
|
+
raise ValueError("Erro ao enviar imagem.")
|
|
198
|
+
|
|
182
199
|
def __send(self, message: Message) -> None:
|
|
183
200
|
|
|
184
201
|
dict_message = message.to_dict()
|
|
@@ -192,26 +209,41 @@ class UserCall:
|
|
|
192
209
|
raise ValueError("Erro ao enviar mensagem de botões.")
|
|
193
210
|
|
|
194
211
|
def transfer_to_human(self, message: str, campaign_name: str) -> None:
|
|
195
|
-
|
|
212
|
+
|
|
196
213
|
campaign = self.__router_client.get_campaign_id({"name": campaign_name})
|
|
197
|
-
|
|
214
|
+
|
|
198
215
|
response = self.__router_client.transfer_to_human(
|
|
199
216
|
{
|
|
200
217
|
"chat_id": self.__user_state.chatID.to_dict(),
|
|
201
218
|
"campaign_id": campaign.id,
|
|
219
|
+
"observation": message,
|
|
202
220
|
}
|
|
203
221
|
)
|
|
204
222
|
|
|
205
223
|
if not response.status:
|
|
206
224
|
raise ValueError("Erro ao transferir chat para humano.")
|
|
207
225
|
|
|
226
|
+
def transfer_to_menu(self, menu: str, message: str) -> None:
|
|
227
|
+
|
|
228
|
+
response = self.__router_client.transfer_to_menu(
|
|
229
|
+
{
|
|
230
|
+
"chat_id": self.__user_state.chatID.to_dict(),
|
|
231
|
+
"menu": menu,
|
|
232
|
+
"user_message": message,
|
|
233
|
+
}
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
if not response.status:
|
|
237
|
+
raise ValueError("Erro ao transferir chat para menu.")
|
|
238
|
+
|
|
208
239
|
def end_chat(self, message: str, tabulation_name: str) -> None:
|
|
209
240
|
tabulation = self.__router_client.get_tabulation_id({"name": tabulation_name})
|
|
210
|
-
|
|
241
|
+
|
|
211
242
|
response = self.__router_client.end_chat(
|
|
212
243
|
{
|
|
213
244
|
"chat_id": self.__user_state.chatID.to_dict(),
|
|
214
245
|
"tabulation_id": tabulation.id,
|
|
246
|
+
"observation": message,
|
|
215
247
|
}
|
|
216
248
|
)
|
|
217
249
|
|
|
@@ -263,15 +295,15 @@ class UserCall:
|
|
|
263
295
|
@property
|
|
264
296
|
def protocol(self):
|
|
265
297
|
return self.__user_state.protocol
|
|
266
|
-
|
|
298
|
+
|
|
267
299
|
@property
|
|
268
300
|
def observation(self):
|
|
269
301
|
return self.__user_state.observation
|
|
270
|
-
|
|
302
|
+
|
|
271
303
|
@property
|
|
272
304
|
def type_message(self):
|
|
273
305
|
return self.__type_message
|
|
274
|
-
|
|
306
|
+
|
|
275
307
|
@property
|
|
276
308
|
def content_message(self):
|
|
277
309
|
return self.__content_message
|
|
@@ -279,12 +311,16 @@ class UserCall:
|
|
|
279
311
|
@menu.setter
|
|
280
312
|
def menu(self, menu):
|
|
281
313
|
|
|
282
|
-
self.update_user_state(
|
|
314
|
+
self.update_user_state(
|
|
315
|
+
menu, self.__user_state.route, self.__user_state.observation
|
|
316
|
+
)
|
|
283
317
|
|
|
284
318
|
@route.setter
|
|
285
319
|
def route(self, route):
|
|
286
320
|
|
|
287
|
-
self.update_user_state(
|
|
321
|
+
self.update_user_state(
|
|
322
|
+
self.__user_state.menu, route, self.__user_state.observation
|
|
323
|
+
)
|
|
288
324
|
|
|
289
325
|
@observation.setter
|
|
290
326
|
def observation(self, observation):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: chatgraph
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: A user-friendly chatbot library
|
|
5
5
|
Home-page: https://github.com/irissonnlima/chatgraph
|
|
6
6
|
License: MIT
|
|
@@ -16,6 +16,7 @@ Requires-Dist: grpcio-tools (>=1.67.0,<2.0.0)
|
|
|
16
16
|
Requires-Dist: matplotlib (>=3.10.0,<4.0.0)
|
|
17
17
|
Requires-Dist: networkx (>=3.4.2,<4.0.0)
|
|
18
18
|
Requires-Dist: pika (>=1.3.2,<2.0.0)
|
|
19
|
+
Requires-Dist: protobuf (>=6.31.1,<7.0.0)
|
|
19
20
|
Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
|
|
20
21
|
Requires-Dist: rich (>=13.8.1,<14.0.0)
|
|
21
22
|
Requires-Dist: typer (>=0.12.5,<0.13.0)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
chatgraph/__init__.py,sha256=ENRmvWkLHfwErug_flNYgbTa4MUMrIzMqGeaFSlSNhM,929
|
|
2
|
+
chatgraph/auth/credentials.py,sha256=xsMEpLQnc66novPjL6upocMcnUnvFJ7yxINzUenkxmc,2388
|
|
3
|
+
chatgraph/bot/chatbot_model.py,sha256=wLVXehmHEWItRwvl6J8HM96lC69FXmqsNG8KqplBboI,7373
|
|
4
|
+
chatgraph/bot/chatbot_router.py,sha256=bVbm9dBoC2OesetXlQJpCrkaiLM3GUro0GrOyCSgreI,2586
|
|
5
|
+
chatgraph/cli/__init__.py,sha256=tfgYhGoKy1nD4STN4xDh6J4VV55RICk7v1GZmzAg-bM,7413
|
|
6
|
+
chatgraph/error/chatbot_error.py,sha256=4sEcW8vz0eQk2QDmDygucVM4caHliZW5iH7XJvmLBuk,1897
|
|
7
|
+
chatgraph/error/route_error.py,sha256=CY8m82ap7-Sr-DXPsolltRW50TqD__5RyXBmNNJCWr8,793
|
|
8
|
+
chatgraph/gRPC/gRPCCall.py,sha256=8t3Il6C-x6LqvdiUOZ5absfVwAfEWY7MpEfmEVNMgVY,5776
|
|
9
|
+
chatgraph/messages/message_consumer.py,sha256=yHhfLYjtmXQYG44o7SNO6XUaeM4-jH8BpIpPHI-mt8Y,6116
|
|
10
|
+
chatgraph/pb/router.proto,sha256=DkP_ESSy2BNO7mMqtXAmFafsz4OLtxj-IoKBzeDout4,3308
|
|
11
|
+
chatgraph/pb/router_pb2.py,sha256=ohYjPoSwbYfFJp1JQIvi7F-BlrHkifeIEvF5KzfjD8g,7426
|
|
12
|
+
chatgraph/pb/router_pb2_grpc.py,sha256=-khhvX4epBDOqGUhQEhuJSAX_Kh7iJBG3csC18Aa73g,28287
|
|
13
|
+
chatgraph/types/background_task.py,sha256=j-Bpd1l_LCDiWukhfG8wNr1F0_GUaOL_J2_BCUnTof4,928
|
|
14
|
+
chatgraph/types/end_types.py,sha256=ulVq3XybRs-EGcOxw6e1FF6U2p3nbtPfOv3uRe6oJfo,1638
|
|
15
|
+
chatgraph/types/image.py,sha256=f2PnUo4Jp24Cn1F4NQhgeoGJPacQiMZCogVowjJwrIE,1097
|
|
16
|
+
chatgraph/types/message_types.py,sha256=__LOk09Xfvojum0xiq9n157_3QSSLNaDMc02iq8dGpk,3434
|
|
17
|
+
chatgraph/types/request_types.py,sha256=stiEDOtFxn22z2bpgYlIcfSM0ellqVbPaJC2noY8mwQ,9957
|
|
18
|
+
chatgraph/types/route.py,sha256=FO5INy5UXgicuQ8FKEZKcPv6WS5YH10dPx2OaPu_0sE,2978
|
|
19
|
+
chatgraph-0.6.0.dist-info/entry_points.txt,sha256=bO9_Q-PqE5vCNNo6ke_-3j2gHfKQMDGnKDTkNuCdBuA,48
|
|
20
|
+
chatgraph-0.6.0.dist-info/LICENSE,sha256=rVJozpRzDlplOpvI8A1GvmfVS0ReYdZvMWc1j2jV0v8,1090
|
|
21
|
+
chatgraph-0.6.0.dist-info/METADATA,sha256=L5LzW2b54Jj0GzFDBUOu_95HztOVbtCMB0VVa1ozjsA,12908
|
|
22
|
+
chatgraph-0.6.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
23
|
+
chatgraph-0.6.0.dist-info/RECORD,,
|
chatgraph-0.5.3.dist-info/RECORD
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
chatgraph/__init__.py,sha256=QtS8l6UjQ7N9gPNruTaPKUTNP8-EvTYeiTBoiSKGp7E,781
|
|
2
|
-
chatgraph/auth/credentials.py,sha256=xsMEpLQnc66novPjL6upocMcnUnvFJ7yxINzUenkxmc,2388
|
|
3
|
-
chatgraph/bot/chatbot_model.py,sha256=PhWCDDTIfT92rwS-USciugVjXuCDKk44NJbiOfEhvRk,7051
|
|
4
|
-
chatgraph/bot/chatbot_router.py,sha256=bVbm9dBoC2OesetXlQJpCrkaiLM3GUro0GrOyCSgreI,2586
|
|
5
|
-
chatgraph/cli/__init__.py,sha256=tfgYhGoKy1nD4STN4xDh6J4VV55RICk7v1GZmzAg-bM,7413
|
|
6
|
-
chatgraph/error/chatbot_error.py,sha256=4sEcW8vz0eQk2QDmDygucVM4caHliZW5iH7XJvmLBuk,1897
|
|
7
|
-
chatgraph/error/route_error.py,sha256=CY8m82ap7-Sr-DXPsolltRW50TqD__5RyXBmNNJCWr8,793
|
|
8
|
-
chatgraph/gRPC/gRPCCall.py,sha256=d8nobBb8yDSKl_eFd1ZUfozvpyDZSoul2HlBIO8Q288,5308
|
|
9
|
-
chatgraph/messages/message_consumer.py,sha256=yHhfLYjtmXQYG44o7SNO6XUaeM4-jH8BpIpPHI-mt8Y,6116
|
|
10
|
-
chatgraph/pb/router.proto,sha256=pw3hTwjdMN8-yJIAlKHNigVKYqM-w2nme9-2bCTBiJ0,2853
|
|
11
|
-
chatgraph/pb/router_pb2.py,sha256=jw-Rg05NMwgOKrRsoubFFb82v_O80KgWY4tIqwUf2Aw,6571
|
|
12
|
-
chatgraph/pb/router_pb2_grpc.py,sha256=KxhVxCMVD9tpuX7CyXqIkzZ4P3zfXeVT92Bt_Hi7mrE,24109
|
|
13
|
-
chatgraph/types/background_task.py,sha256=j-Bpd1l_LCDiWukhfG8wNr1F0_GUaOL_J2_BCUnTof4,928
|
|
14
|
-
chatgraph/types/end_types.py,sha256=--Ty2gM_y7J-yRAvZV26e4HMUpoguAMAhfOIS9-kQTk,1316
|
|
15
|
-
chatgraph/types/message_types.py,sha256=__LOk09Xfvojum0xiq9n157_3QSSLNaDMc02iq8dGpk,3434
|
|
16
|
-
chatgraph/types/request_types.py,sha256=BeUI2l9XZpBf5c8xyPvKI68WZ5u6n98cC8DmUfWKlQ0,8788
|
|
17
|
-
chatgraph/types/route.py,sha256=FO5INy5UXgicuQ8FKEZKcPv6WS5YH10dPx2OaPu_0sE,2978
|
|
18
|
-
chatgraph-0.5.3.dist-info/entry_points.txt,sha256=bO9_Q-PqE5vCNNo6ke_-3j2gHfKQMDGnKDTkNuCdBuA,48
|
|
19
|
-
chatgraph-0.5.3.dist-info/LICENSE,sha256=rVJozpRzDlplOpvI8A1GvmfVS0ReYdZvMWc1j2jV0v8,1090
|
|
20
|
-
chatgraph-0.5.3.dist-info/METADATA,sha256=X4TtQbT5Bcpbaes_XIrLjuoELAMuYU3y105R8F7Ilnw,12866
|
|
21
|
-
chatgraph-0.5.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
22
|
-
chatgraph-0.5.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|