chatgraph 0.6.0__tar.gz → 0.6.1__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.
- {chatgraph-0.6.0 → chatgraph-0.6.1}/PKG-INFO +1 -1
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/__init__.py +2 -2
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/gRPC/gRPCCall.py +14 -1
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/pb/router.proto +12 -5
- chatgraph-0.6.1/chatgraph/pb/router_pb2.py +79 -0
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/pb/router_pb2_grpc.py +47 -0
- chatgraph-0.6.1/chatgraph/types/image.py +92 -0
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/types/request_types.py +18 -6
- {chatgraph-0.6.0 → chatgraph-0.6.1}/pyproject.toml +1 -1
- chatgraph-0.6.0/chatgraph/pb/router_pb2.py +0 -81
- chatgraph-0.6.0/chatgraph/types/image.py +0 -36
- {chatgraph-0.6.0 → chatgraph-0.6.1}/LICENSE +0 -0
- {chatgraph-0.6.0 → chatgraph-0.6.1}/README.md +0 -0
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/auth/credentials.py +0 -0
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/bot/chatbot_model.py +0 -0
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/bot/chatbot_router.py +0 -0
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/cli/__init__.py +0 -0
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/error/chatbot_error.py +0 -0
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/error/route_error.py +0 -0
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/messages/message_consumer.py +0 -0
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/types/background_task.py +0 -0
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/types/end_types.py +0 -0
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/types/message_types.py +0 -0
- {chatgraph-0.6.0 → chatgraph-0.6.1}/chatgraph/types/route.py +0 -0
|
@@ -12,7 +12,7 @@ from .types.end_types import (
|
|
|
12
12
|
from .types.message_types import Message, Button
|
|
13
13
|
from .types.route import Route
|
|
14
14
|
from .types.background_task import BackgroundTask
|
|
15
|
-
from .types.image import ImageData,
|
|
15
|
+
from .types.image import ImageData, ImageMessage
|
|
16
16
|
|
|
17
17
|
__all__ = [
|
|
18
18
|
"ChatbotApp",
|
|
@@ -32,5 +32,5 @@ __all__ = [
|
|
|
32
32
|
"Button",
|
|
33
33
|
"BackgroundTask",
|
|
34
34
|
"ImageData",
|
|
35
|
-
"
|
|
35
|
+
"ImageMessage",
|
|
36
36
|
]
|
|
@@ -74,13 +74,26 @@ class RouterServiceClient:
|
|
|
74
74
|
|
|
75
75
|
try:
|
|
76
76
|
response = self.send_message_stub.SendImage(request)
|
|
77
|
-
if not response.status:
|
|
77
|
+
if not response.status and response.message != "arquivo não encontrado":
|
|
78
78
|
print(f"Erro ao chamar SendImage: {response.message}")
|
|
79
|
+
elif response.message == "arquivo não encontrado":
|
|
80
|
+
print("Arquivo não encontrado, Carregando arquivo...")
|
|
79
81
|
return response
|
|
80
82
|
except grpc.RpcError as e:
|
|
81
83
|
print(f"Erro ao chamar SendImage: {e}")
|
|
82
84
|
return None
|
|
83
85
|
|
|
86
|
+
def upload_file(self, file_data):
|
|
87
|
+
request = chatbot_pb2.UploadFileRequest(**file_data)
|
|
88
|
+
try:
|
|
89
|
+
response = self.send_message_stub.UploadFile(request)
|
|
90
|
+
if not response.status:
|
|
91
|
+
print(f"Erro ao chamar UploadFile: {response.message}")
|
|
92
|
+
return response
|
|
93
|
+
except grpc.RpcError as e:
|
|
94
|
+
print(f"Erro ao chamar UploadFile: {e}")
|
|
95
|
+
return None
|
|
96
|
+
|
|
84
97
|
def transfer_to_human(self, transfer_request_data):
|
|
85
98
|
request = chatbot_pb2.TransferToHumanRequest(**transfer_request_data)
|
|
86
99
|
try:
|
|
@@ -7,6 +7,7 @@ option go_package = "./chatbot";
|
|
|
7
7
|
///// Serviços de Estado do Usuário /////
|
|
8
8
|
service UserStateService {
|
|
9
9
|
rpc InsertUpdateUserState(UserState) returns (RequestStatus);
|
|
10
|
+
rpc SetRoute(RouteRequest) returns (RequestStatus);
|
|
10
11
|
rpc DeleteUserState(ChatID) returns (RequestStatus);
|
|
11
12
|
rpc GetUserState(ChatID) returns (UserState);
|
|
12
13
|
rpc GetAllUserStates(Void) returns (UserStateList);
|
|
@@ -60,6 +61,10 @@ message UserStateList {
|
|
|
60
61
|
repeated UserState user_states = 1;
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
message RouteRequest {
|
|
65
|
+
ChatID chat_id = 1;
|
|
66
|
+
string route = 2;
|
|
67
|
+
}
|
|
63
68
|
///// Mensagens para Serviços de Mensagens /////
|
|
64
69
|
message TextMessage {
|
|
65
70
|
string type = 1;
|
|
@@ -89,10 +94,11 @@ message FileMessage {
|
|
|
89
94
|
}
|
|
90
95
|
|
|
91
96
|
message UploadFileRequest {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
string file_url = 1;
|
|
98
|
+
string file_type = 2;
|
|
99
|
+
string file_extension = 3;
|
|
100
|
+
string expiration = 4;
|
|
101
|
+
bytes file_content = 5;
|
|
96
102
|
}
|
|
97
103
|
|
|
98
104
|
///// Mensagens para Serviços de Transfer /////
|
|
@@ -105,7 +111,8 @@ message TransferToHumanRequest{
|
|
|
105
111
|
message TransferToMenuRequest{
|
|
106
112
|
ChatID chat_id = 1;
|
|
107
113
|
string menu = 2;
|
|
108
|
-
string
|
|
114
|
+
string route = 3;
|
|
115
|
+
string user_message = 4;
|
|
109
116
|
}
|
|
110
117
|
|
|
111
118
|
message TabulationName{
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
3
|
+
# NO CHECKED-IN PROTOBUF GENCODE
|
|
4
|
+
# source: router.proto
|
|
5
|
+
# Protobuf Python Version: 6.31.0
|
|
6
|
+
"""Generated protocol buffer code."""
|
|
7
|
+
from google.protobuf import descriptor as _descriptor
|
|
8
|
+
from google.protobuf import descriptor_pool as _descriptor_pool
|
|
9
|
+
from google.protobuf import runtime_version as _runtime_version
|
|
10
|
+
from google.protobuf import symbol_database as _symbol_database
|
|
11
|
+
from google.protobuf.internal import builder as _builder
|
|
12
|
+
|
|
13
|
+
_runtime_version.ValidateProtobufRuntimeVersion(
|
|
14
|
+
_runtime_version.Domain.PUBLIC, 6, 31, 0, "", "router.proto"
|
|
15
|
+
)
|
|
16
|
+
# @@protoc_insertion_point(imports)
|
|
17
|
+
|
|
18
|
+
_sym_db = _symbol_database.Default()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(
|
|
22
|
+
b'\n\x0crouter.proto\x12\x07\x63hatbot"\x06\n\x04Void"0\n\rRequestStatus\x12\x0e\n\x06status\x18\x01 \x01(\x08\x12\x0f\n\x07message\x18\x02 \x01(\t"-\n\x06\x43hatID\x12\x0f\n\x07user_id\x18\x01 \x01(\t\x12\x12\n\ncompany_id\x18\x02 \x01(\t"q\n\tUserState\x12 \n\x07\x63hat_id\x18\x01 \x01(\x0b\x32\x0f.chatbot.ChatID\x12\x0c\n\x04menu\x18\x02 \x01(\t\x12\r\n\x05route\x18\x03 \x01(\t\x12\x10\n\x08protocol\x18\x04 \x01(\t\x12\x13\n\x0bobservation\x18\x05 \x01(\t"8\n\rUserStateList\x12\'\n\x0buser_states\x18\x01 \x03(\x0b\x32\x12.chatbot.UserState"?\n\x0cRouteRequest\x12 \n\x07\x63hat_id\x18\x01 \x01(\x0b\x32\x0f.chatbot.ChatID\x12\r\n\x05route\x18\x02 \x01(\t"j\n\x0bTextMessage\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x0b\n\x03url\x18\x02 \x01(\t\x12\x10\n\x08\x66ilename\x18\x03 \x01(\t\x12\r\n\x05title\x18\x04 \x01(\t\x12\x0e\n\x06\x64\x65tail\x18\x05 \x01(\t\x12\x0f\n\x07\x63\x61ption\x18\x06 \x01(\t"5\n\x06\x42utton\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\r\n\x05title\x18\x02 \x01(\t\x12\x0e\n\x06\x64\x65tail\x18\x03 \x01(\t"\x9d\x01\n\x07Message\x12 \n\x07\x63hat_id\x18\x01 \x01(\x0b\x32\x0f.chatbot.ChatID\x12%\n\x07message\x18\x02 \x01(\x0b\x32\x14.chatbot.TextMessage\x12 \n\x07\x62uttons\x18\x03 \x03(\x0b\x32\x0f.chatbot.Button\x12\'\n\x0e\x64isplay_button\x18\x04 \x01(\x0b\x32\x0f.chatbot.Button"A\n\x0b\x46ileMessage\x12!\n\x07message\x18\x01 \x01(\x0b\x32\x10.chatbot.Message\x12\x0f\n\x07\x66ile_id\x18\x02 \x01(\t"z\n\x11UploadFileRequest\x12\x10\n\x08\x66ile_url\x18\x01 \x01(\t\x12\x11\n\tfile_type\x18\x02 \x01(\t\x12\x16\n\x0e\x66ile_extension\x18\x03 \x01(\t\x12\x12\n\nexpiration\x18\x04 \x01(\t\x12\x14\n\x0c\x66ile_content\x18\x05 \x01(\x0c"d\n\x16TransferToHumanRequest\x12 \n\x07\x63hat_id\x18\x01 \x01(\x0b\x32\x0f.chatbot.ChatID\x12\x13\n\x0b\x63\x61mpaign_id\x18\x02 \x01(\t\x12\x13\n\x0bobservation\x18\x03 \x01(\t"l\n\x15TransferToMenuRequest\x12 \n\x07\x63hat_id\x18\x01 \x01(\x0b\x32\x0f.chatbot.ChatID\x12\x0c\n\x04menu\x18\x02 \x01(\t\x12\r\n\x05route\x18\x03 \x01(\t\x12\x14\n\x0cuser_message\x18\x04 \x01(\t"\x1e\n\x0eTabulationName\x12\x0c\n\x04name\x18\x01 \x01(\t"B\n\x11TabulationDetails\x12\n\n\x02id\x18\x01 \x01(\t\x12\x0c\n\x04name\x18\x02 \x01(\t\x12\x13\n\x0blast_update\x18\x03 \x01(\t"B\n\x0fTabulationsList\x12/\n\x0btabulations\x18\x01 \x03(\x0b\x32\x1a.chatbot.TabulationDetails"^\n\x0e\x45ndChatRequest\x12 \n\x07\x63hat_id\x18\x01 \x01(\x0b\x32\x0f.chatbot.ChatID\x12\x15\n\rtabulation_id\x18\x02 \x01(\t\x12\x13\n\x0bobservation\x18\x03 \x01(\t"\x1c\n\x0c\x43\x61mpaignName\x12\x0c\n\x04name\x18\x01 \x01(\t"@\n\x0f\x43\x61mpaignDetails\x12\n\n\x02id\x18\x01 \x01(\t\x12\x0c\n\x04name\x18\x02 \x01(\t\x12\x13\n\x0blast_update\x18\x03 \x01(\t"<\n\rCampaignsList\x12+\n\tcampaigns\x18\x01 \x03(\x0b\x32\x18.chatbot.CampaignDetails2\xbe\x02\n\x10UserStateService\x12\x43\n\x15InsertUpdateUserState\x12\x12.chatbot.UserState\x1a\x16.chatbot.RequestStatus\x12\x39\n\x08SetRoute\x12\x15.chatbot.RouteRequest\x1a\x16.chatbot.RequestStatus\x12:\n\x0f\x44\x65leteUserState\x12\x0f.chatbot.ChatID\x1a\x16.chatbot.RequestStatus\x12\x33\n\x0cGetUserState\x12\x0f.chatbot.ChatID\x1a\x12.chatbot.UserState\x12\x39\n\x10GetAllUserStates\x12\r.chatbot.Void\x1a\x16.chatbot.UserStateList2\xfd\x01\n\x0bSendMessage\x12\x37\n\x0bSendMessage\x12\x10.chatbot.Message\x1a\x16.chatbot.RequestStatus\x12\x39\n\tSendImage\x12\x14.chatbot.FileMessage\x1a\x16.chatbot.RequestStatus\x12\x38\n\x08SendFile\x12\x14.chatbot.FileMessage\x1a\x16.chatbot.RequestStatus\x12@\n\nUploadFile\x12\x1a.chatbot.UploadFileRequest\x1a\x16.chatbot.RequestStatus2\x9c\x02\n\x08Transfer\x12\x38\n\x0fGetAllCampaigns\x12\r.chatbot.Void\x1a\x16.chatbot.CampaignsList\x12@\n\rGetCampaignID\x12\x15.chatbot.CampaignName\x1a\x18.chatbot.CampaignDetails\x12J\n\x0fTransferToHuman\x12\x1f.chatbot.TransferToHumanRequest\x1a\x16.chatbot.RequestStatus\x12H\n\x0eTransferToMenu\x12\x1e.chatbot.TransferToMenuRequest\x1a\x16.chatbot.RequestStatus2\xcb\x01\n\x07\x45ndChat\x12<\n\x11GetAllTabulations\x12\r.chatbot.Void\x1a\x18.chatbot.TabulationsList\x12\x46\n\x0fGetTabulationID\x12\x17.chatbot.TabulationName\x1a\x1a.chatbot.TabulationDetails\x12:\n\x07\x45ndChat\x12\x17.chatbot.EndChatRequest\x1a\x16.chatbot.RequestStatusB\x0bZ\t./chatbotb\x06proto3'
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
_globals = globals()
|
|
26
|
+
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
|
|
27
|
+
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, "router_pb2", _globals)
|
|
28
|
+
if not _descriptor._USE_C_DESCRIPTORS:
|
|
29
|
+
_globals["DESCRIPTOR"]._loaded_options = None
|
|
30
|
+
_globals["DESCRIPTOR"]._serialized_options = b"Z\t./chatbot"
|
|
31
|
+
_globals["_VOID"]._serialized_start = 25
|
|
32
|
+
_globals["_VOID"]._serialized_end = 31
|
|
33
|
+
_globals["_REQUESTSTATUS"]._serialized_start = 33
|
|
34
|
+
_globals["_REQUESTSTATUS"]._serialized_end = 81
|
|
35
|
+
_globals["_CHATID"]._serialized_start = 83
|
|
36
|
+
_globals["_CHATID"]._serialized_end = 128
|
|
37
|
+
_globals["_USERSTATE"]._serialized_start = 130
|
|
38
|
+
_globals["_USERSTATE"]._serialized_end = 243
|
|
39
|
+
_globals["_USERSTATELIST"]._serialized_start = 245
|
|
40
|
+
_globals["_USERSTATELIST"]._serialized_end = 301
|
|
41
|
+
_globals["_ROUTEREQUEST"]._serialized_start = 303
|
|
42
|
+
_globals["_ROUTEREQUEST"]._serialized_end = 366
|
|
43
|
+
_globals["_TEXTMESSAGE"]._serialized_start = 368
|
|
44
|
+
_globals["_TEXTMESSAGE"]._serialized_end = 474
|
|
45
|
+
_globals["_BUTTON"]._serialized_start = 476
|
|
46
|
+
_globals["_BUTTON"]._serialized_end = 529
|
|
47
|
+
_globals["_MESSAGE"]._serialized_start = 532
|
|
48
|
+
_globals["_MESSAGE"]._serialized_end = 689
|
|
49
|
+
_globals["_FILEMESSAGE"]._serialized_start = 691
|
|
50
|
+
_globals["_FILEMESSAGE"]._serialized_end = 756
|
|
51
|
+
_globals["_UPLOADFILEREQUEST"]._serialized_start = 758
|
|
52
|
+
_globals["_UPLOADFILEREQUEST"]._serialized_end = 880
|
|
53
|
+
_globals["_TRANSFERTOHUMANREQUEST"]._serialized_start = 882
|
|
54
|
+
_globals["_TRANSFERTOHUMANREQUEST"]._serialized_end = 982
|
|
55
|
+
_globals["_TRANSFERTOMENUREQUEST"]._serialized_start = 984
|
|
56
|
+
_globals["_TRANSFERTOMENUREQUEST"]._serialized_end = 1092
|
|
57
|
+
_globals["_TABULATIONNAME"]._serialized_start = 1094
|
|
58
|
+
_globals["_TABULATIONNAME"]._serialized_end = 1124
|
|
59
|
+
_globals["_TABULATIONDETAILS"]._serialized_start = 1126
|
|
60
|
+
_globals["_TABULATIONDETAILS"]._serialized_end = 1192
|
|
61
|
+
_globals["_TABULATIONSLIST"]._serialized_start = 1194
|
|
62
|
+
_globals["_TABULATIONSLIST"]._serialized_end = 1260
|
|
63
|
+
_globals["_ENDCHATREQUEST"]._serialized_start = 1262
|
|
64
|
+
_globals["_ENDCHATREQUEST"]._serialized_end = 1356
|
|
65
|
+
_globals["_CAMPAIGNNAME"]._serialized_start = 1358
|
|
66
|
+
_globals["_CAMPAIGNNAME"]._serialized_end = 1386
|
|
67
|
+
_globals["_CAMPAIGNDETAILS"]._serialized_start = 1388
|
|
68
|
+
_globals["_CAMPAIGNDETAILS"]._serialized_end = 1452
|
|
69
|
+
_globals["_CAMPAIGNSLIST"]._serialized_start = 1454
|
|
70
|
+
_globals["_CAMPAIGNSLIST"]._serialized_end = 1514
|
|
71
|
+
_globals["_USERSTATESERVICE"]._serialized_start = 1517
|
|
72
|
+
_globals["_USERSTATESERVICE"]._serialized_end = 1835
|
|
73
|
+
_globals["_SENDMESSAGE"]._serialized_start = 1838
|
|
74
|
+
_globals["_SENDMESSAGE"]._serialized_end = 2091
|
|
75
|
+
_globals["_TRANSFER"]._serialized_start = 2094
|
|
76
|
+
_globals["_TRANSFER"]._serialized_end = 2378
|
|
77
|
+
_globals["_ENDCHAT"]._serialized_start = 2381
|
|
78
|
+
_globals["_ENDCHAT"]._serialized_end = 2584
|
|
79
|
+
# @@protoc_insertion_point(module_scope)
|
|
@@ -43,6 +43,12 @@ class UserStateServiceStub(object):
|
|
|
43
43
|
response_deserializer=router__pb2.RequestStatus.FromString,
|
|
44
44
|
_registered_method=True,
|
|
45
45
|
)
|
|
46
|
+
self.SetRoute = channel.unary_unary(
|
|
47
|
+
"/chatbot.UserStateService/SetRoute",
|
|
48
|
+
request_serializer=router__pb2.RouteRequest.SerializeToString,
|
|
49
|
+
response_deserializer=router__pb2.RequestStatus.FromString,
|
|
50
|
+
_registered_method=True,
|
|
51
|
+
)
|
|
46
52
|
self.DeleteUserState = channel.unary_unary(
|
|
47
53
|
"/chatbot.UserStateService/DeleteUserState",
|
|
48
54
|
request_serializer=router__pb2.ChatID.SerializeToString,
|
|
@@ -72,6 +78,12 @@ class UserStateServiceServicer(object):
|
|
|
72
78
|
context.set_details("Method not implemented!")
|
|
73
79
|
raise NotImplementedError("Method not implemented!")
|
|
74
80
|
|
|
81
|
+
def SetRoute(self, request, context):
|
|
82
|
+
"""Missing associated documentation comment in .proto file."""
|
|
83
|
+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
|
84
|
+
context.set_details("Method not implemented!")
|
|
85
|
+
raise NotImplementedError("Method not implemented!")
|
|
86
|
+
|
|
75
87
|
def DeleteUserState(self, request, context):
|
|
76
88
|
"""Missing associated documentation comment in .proto file."""
|
|
77
89
|
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
|
@@ -98,6 +110,11 @@ def add_UserStateServiceServicer_to_server(servicer, server):
|
|
|
98
110
|
request_deserializer=router__pb2.UserState.FromString,
|
|
99
111
|
response_serializer=router__pb2.RequestStatus.SerializeToString,
|
|
100
112
|
),
|
|
113
|
+
"SetRoute": grpc.unary_unary_rpc_method_handler(
|
|
114
|
+
servicer.SetRoute,
|
|
115
|
+
request_deserializer=router__pb2.RouteRequest.FromString,
|
|
116
|
+
response_serializer=router__pb2.RequestStatus.SerializeToString,
|
|
117
|
+
),
|
|
101
118
|
"DeleteUserState": grpc.unary_unary_rpc_method_handler(
|
|
102
119
|
servicer.DeleteUserState,
|
|
103
120
|
request_deserializer=router__pb2.ChatID.FromString,
|
|
@@ -157,6 +174,36 @@ class UserStateService(object):
|
|
|
157
174
|
_registered_method=True,
|
|
158
175
|
)
|
|
159
176
|
|
|
177
|
+
@staticmethod
|
|
178
|
+
def SetRoute(
|
|
179
|
+
request,
|
|
180
|
+
target,
|
|
181
|
+
options=(),
|
|
182
|
+
channel_credentials=None,
|
|
183
|
+
call_credentials=None,
|
|
184
|
+
insecure=False,
|
|
185
|
+
compression=None,
|
|
186
|
+
wait_for_ready=None,
|
|
187
|
+
timeout=None,
|
|
188
|
+
metadata=None,
|
|
189
|
+
):
|
|
190
|
+
return grpc.experimental.unary_unary(
|
|
191
|
+
request,
|
|
192
|
+
target,
|
|
193
|
+
"/chatbot.UserStateService/SetRoute",
|
|
194
|
+
router__pb2.RouteRequest.SerializeToString,
|
|
195
|
+
router__pb2.RequestStatus.FromString,
|
|
196
|
+
options,
|
|
197
|
+
channel_credentials,
|
|
198
|
+
insecure,
|
|
199
|
+
call_credentials,
|
|
200
|
+
compression,
|
|
201
|
+
wait_for_ready,
|
|
202
|
+
timeout,
|
|
203
|
+
metadata,
|
|
204
|
+
_registered_method=True,
|
|
205
|
+
)
|
|
206
|
+
|
|
160
207
|
@staticmethod
|
|
161
208
|
def DeleteUserState(
|
|
162
209
|
request,
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from datetime import datetime, timedelta
|
|
2
|
+
import hashlib
|
|
3
|
+
import base64
|
|
4
|
+
from chatgraph.types.message_types import Message
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ImageData:
|
|
8
|
+
"""
|
|
9
|
+
Representa dados de uma imagem, seja por URL ou arquivo local. Caso fornecido um url e um caminho de arquivo, o url será utilizado.
|
|
10
|
+
Atributos:
|
|
11
|
+
type (str): Tipo de imagem, "link" para URL ou "file" para arquivo local.
|
|
12
|
+
url (str): URL da imagem, se aplicável.
|
|
13
|
+
image_path (str): Caminho do arquivo de imagem, se aplicável.
|
|
14
|
+
expiration (int): Tempo de expiração em minutos, 0 para sem expiração.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, *, url: str = None, image_path: str = None, expiration: int = 0):
|
|
18
|
+
|
|
19
|
+
if not url and not image_path:
|
|
20
|
+
raise ValueError("URL or image path must be provided.")
|
|
21
|
+
|
|
22
|
+
self.type = "link" if url else "file"
|
|
23
|
+
self.url = url
|
|
24
|
+
self.expiration = expiration
|
|
25
|
+
|
|
26
|
+
self.image_bytes = None
|
|
27
|
+
self.file_extension = None
|
|
28
|
+
if self.type == "file":
|
|
29
|
+
if not image_path:
|
|
30
|
+
raise ValueError("Image path must be provided for file type.")
|
|
31
|
+
self.file_extension = image_path.split(".")[-1]
|
|
32
|
+
with open(image_path, "rb") as f:
|
|
33
|
+
self.image_bytes = f.read()
|
|
34
|
+
|
|
35
|
+
# Create hash of image bytes if available, otherwise use URL
|
|
36
|
+
hash_input = self.image_bytes if self.image_bytes else url.encode("utf-8")
|
|
37
|
+
|
|
38
|
+
# Create SHA-256 hash and encode in base64
|
|
39
|
+
self.image_id = base64.b64encode(hashlib.sha256(hash_input).digest()).decode(
|
|
40
|
+
"utf-8"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
def get_upload_dict(self):
|
|
44
|
+
dict_data = {}
|
|
45
|
+
if self.expiration > 0:
|
|
46
|
+
now = datetime.now()
|
|
47
|
+
expiration_time = now + timedelta(minutes=self.expiration)
|
|
48
|
+
dict_data["expiration"] = expiration_time.strftime("%Y-%m-%d %H:%M:%S")
|
|
49
|
+
|
|
50
|
+
if self.type == "file":
|
|
51
|
+
dict_data["file_type"] = self.type
|
|
52
|
+
dict_data["file_content"] = self.image_bytes
|
|
53
|
+
dict_data["file_extension"] = self.file_extension
|
|
54
|
+
else:
|
|
55
|
+
dict_data["file_type"] = self.type
|
|
56
|
+
dict_data["file_url"] = self.url
|
|
57
|
+
|
|
58
|
+
return dict_data
|
|
59
|
+
|
|
60
|
+
def get_dict(self):
|
|
61
|
+
dict_data = {
|
|
62
|
+
"image_id": self.image_id,
|
|
63
|
+
"file_type": self.type,
|
|
64
|
+
}
|
|
65
|
+
if self.type == "file":
|
|
66
|
+
dict_data["file_content"] = self.image_bytes
|
|
67
|
+
dict_data["file_extension"] = self.file_extension
|
|
68
|
+
else:
|
|
69
|
+
dict_data["file_url"] = self.url
|
|
70
|
+
return dict_data
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class ImageMessage:
|
|
74
|
+
def __init__(self, image: ImageData, message: Message = None):
|
|
75
|
+
if not isinstance(image, ImageData):
|
|
76
|
+
raise TypeError("Expected an instance of ImageData.")
|
|
77
|
+
|
|
78
|
+
self.type = "image"
|
|
79
|
+
self.image = image
|
|
80
|
+
self.message = message
|
|
81
|
+
|
|
82
|
+
def to_dict(self):
|
|
83
|
+
if not self.message:
|
|
84
|
+
return {
|
|
85
|
+
"file_id": self.image.image_id,
|
|
86
|
+
"message": {},
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
"file_id": self.image.image_id,
|
|
91
|
+
"message": self.message.to_dict(),
|
|
92
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from chatgraph.gRPC.gRPCCall import RouterServiceClient
|
|
2
|
-
from chatgraph.types.image import ImageData,
|
|
2
|
+
from chatgraph.types.image import ImageData, ImageMessage
|
|
3
3
|
from chatgraph.types.message_types import Message, Button, MessageTypes, messageTypes
|
|
4
4
|
from typing import Optional
|
|
5
5
|
from datetime import datetime
|
|
@@ -176,25 +176,37 @@ class UserCall:
|
|
|
176
176
|
)
|
|
177
177
|
|
|
178
178
|
if isinstance(message, ImageData):
|
|
179
|
-
message =
|
|
179
|
+
message = ImageMessage(
|
|
180
180
|
image=message,
|
|
181
|
-
message=Message(type="message", detail=""),
|
|
182
181
|
)
|
|
183
182
|
|
|
184
183
|
if isinstance(message, Message):
|
|
185
184
|
self.__send(message)
|
|
186
|
-
elif isinstance(message,
|
|
185
|
+
elif isinstance(message, ImageMessage):
|
|
187
186
|
self.__send_image(message)
|
|
188
187
|
else:
|
|
189
188
|
raise ValueError("Tipo de mensagem inválido.")
|
|
190
189
|
|
|
191
|
-
def
|
|
190
|
+
def __upload_file(self, image: ImageData) -> None:
|
|
191
|
+
dict_image = image.get_upload_dict()
|
|
192
|
+
response = self.__router_client.upload_file(dict_image)
|
|
193
|
+
|
|
194
|
+
if not response.status:
|
|
195
|
+
raise ValueError("Erro ao fazer upload do arquivo.")
|
|
196
|
+
else:
|
|
197
|
+
print("Arquivo enviado com sucesso.")
|
|
198
|
+
|
|
199
|
+
def __send_image(self, message: ImageMessage) -> None:
|
|
192
200
|
dict_message = message.to_dict()
|
|
193
201
|
dict_message["message"]["chat_id"] = self.__user_state.chatID.to_dict()
|
|
194
202
|
response = self.__router_client.send_image(dict_message)
|
|
195
203
|
|
|
196
|
-
if not response.status:
|
|
204
|
+
if not response.status and response.message != "arquivo não encontrado":
|
|
197
205
|
raise ValueError("Erro ao enviar imagem.")
|
|
206
|
+
elif response.message == "arquivo não encontrado":
|
|
207
|
+
self.__upload_file(message.image)
|
|
208
|
+
print("tentando enviar imagem novamente...")
|
|
209
|
+
self.__send_image(message)
|
|
198
210
|
|
|
199
211
|
def __send(self, message: Message) -> None:
|
|
200
212
|
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
3
|
-
# NO CHECKED-IN PROTOBUF GENCODE
|
|
4
|
-
# source: router.proto
|
|
5
|
-
# Protobuf Python Version: 6.31.0
|
|
6
|
-
"""Generated protocol buffer code."""
|
|
7
|
-
from google.protobuf import descriptor as _descriptor
|
|
8
|
-
from google.protobuf import descriptor_pool as _descriptor_pool
|
|
9
|
-
from google.protobuf import runtime_version as _runtime_version
|
|
10
|
-
from google.protobuf import symbol_database as _symbol_database
|
|
11
|
-
from google.protobuf.internal import builder as _builder
|
|
12
|
-
_runtime_version.ValidateProtobufRuntimeVersion(
|
|
13
|
-
_runtime_version.Domain.PUBLIC,
|
|
14
|
-
6,
|
|
15
|
-
31,
|
|
16
|
-
0,
|
|
17
|
-
'',
|
|
18
|
-
'router.proto'
|
|
19
|
-
)
|
|
20
|
-
# @@protoc_insertion_point(imports)
|
|
21
|
-
|
|
22
|
-
_sym_db = _symbol_database.Default()
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0crouter.proto\x12\x07\x63hatbot\"\x06\n\x04Void\"0\n\rRequestStatus\x12\x0e\n\x06status\x18\x01 \x01(\x08\x12\x0f\n\x07message\x18\x02 \x01(\t\"-\n\x06\x43hatID\x12\x0f\n\x07user_id\x18\x01 \x01(\t\x12\x12\n\ncompany_id\x18\x02 \x01(\t\"q\n\tUserState\x12 \n\x07\x63hat_id\x18\x01 \x01(\x0b\x32\x0f.chatbot.ChatID\x12\x0c\n\x04menu\x18\x02 \x01(\t\x12\r\n\x05route\x18\x03 \x01(\t\x12\x10\n\x08protocol\x18\x04 \x01(\t\x12\x13\n\x0bobservation\x18\x05 \x01(\t\"8\n\rUserStateList\x12\'\n\x0buser_states\x18\x01 \x03(\x0b\x32\x12.chatbot.UserState\"j\n\x0bTextMessage\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x0b\n\x03url\x18\x02 \x01(\t\x12\x10\n\x08\x66ilename\x18\x03 \x01(\t\x12\r\n\x05title\x18\x04 \x01(\t\x12\x0e\n\x06\x64\x65tail\x18\x05 \x01(\t\x12\x0f\n\x07\x63\x61ption\x18\x06 \x01(\t\"5\n\x06\x42utton\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\r\n\x05title\x18\x02 \x01(\t\x12\x0e\n\x06\x64\x65tail\x18\x03 \x01(\t\"\x9d\x01\n\x07Message\x12 \n\x07\x63hat_id\x18\x01 \x01(\x0b\x32\x0f.chatbot.ChatID\x12%\n\x07message\x18\x02 \x01(\x0b\x32\x14.chatbot.TextMessage\x12 \n\x07\x62uttons\x18\x03 \x03(\x0b\x32\x0f.chatbot.Button\x12\'\n\x0e\x64isplay_button\x18\x04 \x01(\x0b\x32\x0f.chatbot.Button\"A\n\x0b\x46ileMessage\x12!\n\x07message\x18\x01 \x01(\x0b\x32\x10.chatbot.Message\x12\x0f\n\x07\x66ile_id\x18\x02 \x01(\t\"_\n\x11UploadFileRequest\x12\x0f\n\x07\x66ile_id\x18\x01 \x01(\t\x12\x10\n\x08\x66ile_url\x18\x02 \x01(\t\x12\x11\n\tfile_type\x18\x03 \x01(\t\x12\x14\n\x0c\x66ile_content\x18\x04 \x01(\x0c\"d\n\x16TransferToHumanRequest\x12 \n\x07\x63hat_id\x18\x01 \x01(\x0b\x32\x0f.chatbot.ChatID\x12\x13\n\x0b\x63\x61mpaign_id\x18\x02 \x01(\t\x12\x13\n\x0bobservation\x18\x03 \x01(\t\"]\n\x15TransferToMenuRequest\x12 \n\x07\x63hat_id\x18\x01 \x01(\x0b\x32\x0f.chatbot.ChatID\x12\x0c\n\x04menu\x18\x02 \x01(\t\x12\x14\n\x0cuser_message\x18\x03 \x01(\t\"\x1e\n\x0eTabulationName\x12\x0c\n\x04name\x18\x01 \x01(\t\"B\n\x11TabulationDetails\x12\n\n\x02id\x18\x01 \x01(\t\x12\x0c\n\x04name\x18\x02 \x01(\t\x12\x13\n\x0blast_update\x18\x03 \x01(\t\"B\n\x0fTabulationsList\x12/\n\x0btabulations\x18\x01 \x03(\x0b\x32\x1a.chatbot.TabulationDetails\"^\n\x0e\x45ndChatRequest\x12 \n\x07\x63hat_id\x18\x01 \x01(\x0b\x32\x0f.chatbot.ChatID\x12\x15\n\rtabulation_id\x18\x02 \x01(\t\x12\x13\n\x0bobservation\x18\x03 \x01(\t\"\x1c\n\x0c\x43\x61mpaignName\x12\x0c\n\x04name\x18\x01 \x01(\t\"@\n\x0f\x43\x61mpaignDetails\x12\n\n\x02id\x18\x01 \x01(\t\x12\x0c\n\x04name\x18\x02 \x01(\t\x12\x13\n\x0blast_update\x18\x03 \x01(\t\"<\n\rCampaignsList\x12+\n\tcampaigns\x18\x01 \x03(\x0b\x32\x18.chatbot.CampaignDetails2\x83\x02\n\x10UserStateService\x12\x43\n\x15InsertUpdateUserState\x12\x12.chatbot.UserState\x1a\x16.chatbot.RequestStatus\x12:\n\x0f\x44\x65leteUserState\x12\x0f.chatbot.ChatID\x1a\x16.chatbot.RequestStatus\x12\x33\n\x0cGetUserState\x12\x0f.chatbot.ChatID\x1a\x12.chatbot.UserState\x12\x39\n\x10GetAllUserStates\x12\r.chatbot.Void\x1a\x16.chatbot.UserStateList2\xfd\x01\n\x0bSendMessage\x12\x37\n\x0bSendMessage\x12\x10.chatbot.Message\x1a\x16.chatbot.RequestStatus\x12\x39\n\tSendImage\x12\x14.chatbot.FileMessage\x1a\x16.chatbot.RequestStatus\x12\x38\n\x08SendFile\x12\x14.chatbot.FileMessage\x1a\x16.chatbot.RequestStatus\x12@\n\nUploadFile\x12\x1a.chatbot.UploadFileRequest\x1a\x16.chatbot.RequestStatus2\x9c\x02\n\x08Transfer\x12\x38\n\x0fGetAllCampaigns\x12\r.chatbot.Void\x1a\x16.chatbot.CampaignsList\x12@\n\rGetCampaignID\x12\x15.chatbot.CampaignName\x1a\x18.chatbot.CampaignDetails\x12J\n\x0fTransferToHuman\x12\x1f.chatbot.TransferToHumanRequest\x1a\x16.chatbot.RequestStatus\x12H\n\x0eTransferToMenu\x12\x1e.chatbot.TransferToMenuRequest\x1a\x16.chatbot.RequestStatus2\xcb\x01\n\x07\x45ndChat\x12<\n\x11GetAllTabulations\x12\r.chatbot.Void\x1a\x18.chatbot.TabulationsList\x12\x46\n\x0fGetTabulationID\x12\x17.chatbot.TabulationName\x1a\x1a.chatbot.TabulationDetails\x12:\n\x07\x45ndChat\x12\x17.chatbot.EndChatRequest\x1a\x16.chatbot.RequestStatusB\x0bZ\t./chatbotb\x06proto3')
|
|
28
|
-
|
|
29
|
-
_globals = globals()
|
|
30
|
-
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
|
|
31
|
-
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'router_pb2', _globals)
|
|
32
|
-
if not _descriptor._USE_C_DESCRIPTORS:
|
|
33
|
-
_globals['DESCRIPTOR']._loaded_options = None
|
|
34
|
-
_globals['DESCRIPTOR']._serialized_options = b'Z\t./chatbot'
|
|
35
|
-
_globals['_VOID']._serialized_start=25
|
|
36
|
-
_globals['_VOID']._serialized_end=31
|
|
37
|
-
_globals['_REQUESTSTATUS']._serialized_start=33
|
|
38
|
-
_globals['_REQUESTSTATUS']._serialized_end=81
|
|
39
|
-
_globals['_CHATID']._serialized_start=83
|
|
40
|
-
_globals['_CHATID']._serialized_end=128
|
|
41
|
-
_globals['_USERSTATE']._serialized_start=130
|
|
42
|
-
_globals['_USERSTATE']._serialized_end=243
|
|
43
|
-
_globals['_USERSTATELIST']._serialized_start=245
|
|
44
|
-
_globals['_USERSTATELIST']._serialized_end=301
|
|
45
|
-
_globals['_TEXTMESSAGE']._serialized_start=303
|
|
46
|
-
_globals['_TEXTMESSAGE']._serialized_end=409
|
|
47
|
-
_globals['_BUTTON']._serialized_start=411
|
|
48
|
-
_globals['_BUTTON']._serialized_end=464
|
|
49
|
-
_globals['_MESSAGE']._serialized_start=467
|
|
50
|
-
_globals['_MESSAGE']._serialized_end=624
|
|
51
|
-
_globals['_FILEMESSAGE']._serialized_start=626
|
|
52
|
-
_globals['_FILEMESSAGE']._serialized_end=691
|
|
53
|
-
_globals['_UPLOADFILEREQUEST']._serialized_start=693
|
|
54
|
-
_globals['_UPLOADFILEREQUEST']._serialized_end=788
|
|
55
|
-
_globals['_TRANSFERTOHUMANREQUEST']._serialized_start=790
|
|
56
|
-
_globals['_TRANSFERTOHUMANREQUEST']._serialized_end=890
|
|
57
|
-
_globals['_TRANSFERTOMENUREQUEST']._serialized_start=892
|
|
58
|
-
_globals['_TRANSFERTOMENUREQUEST']._serialized_end=985
|
|
59
|
-
_globals['_TABULATIONNAME']._serialized_start=987
|
|
60
|
-
_globals['_TABULATIONNAME']._serialized_end=1017
|
|
61
|
-
_globals['_TABULATIONDETAILS']._serialized_start=1019
|
|
62
|
-
_globals['_TABULATIONDETAILS']._serialized_end=1085
|
|
63
|
-
_globals['_TABULATIONSLIST']._serialized_start=1087
|
|
64
|
-
_globals['_TABULATIONSLIST']._serialized_end=1153
|
|
65
|
-
_globals['_ENDCHATREQUEST']._serialized_start=1155
|
|
66
|
-
_globals['_ENDCHATREQUEST']._serialized_end=1249
|
|
67
|
-
_globals['_CAMPAIGNNAME']._serialized_start=1251
|
|
68
|
-
_globals['_CAMPAIGNNAME']._serialized_end=1279
|
|
69
|
-
_globals['_CAMPAIGNDETAILS']._serialized_start=1281
|
|
70
|
-
_globals['_CAMPAIGNDETAILS']._serialized_end=1345
|
|
71
|
-
_globals['_CAMPAIGNSLIST']._serialized_start=1347
|
|
72
|
-
_globals['_CAMPAIGNSLIST']._serialized_end=1407
|
|
73
|
-
_globals['_USERSTATESERVICE']._serialized_start=1410
|
|
74
|
-
_globals['_USERSTATESERVICE']._serialized_end=1669
|
|
75
|
-
_globals['_SENDMESSAGE']._serialized_start=1672
|
|
76
|
-
_globals['_SENDMESSAGE']._serialized_end=1925
|
|
77
|
-
_globals['_TRANSFER']._serialized_start=1928
|
|
78
|
-
_globals['_TRANSFER']._serialized_end=2212
|
|
79
|
-
_globals['_ENDCHAT']._serialized_start=2215
|
|
80
|
-
_globals['_ENDCHAT']._serialized_end=2418
|
|
81
|
-
# @@protoc_insertion_point(module_scope)
|
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|