forked from EvolutionAPI/evolution-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.py
More file actions
122 lines (107 loc) · 4.26 KB
/
chat.py
File metadata and controls
122 lines (107 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from typing import Union, BinaryIO, Optional
from ..models.chat import *
class ChatService:
def __init__(self, client):
self.client = client
def check_is_whatsapp_numbers(self, instance_id: str, data: CheckIsWhatsappNumber, instance_token: str):
return self.client.post(
f'chat/checkIsWhatsappNumber/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def mark_message_as_read(self, instance_id: str, messages: List[ReadMessage], instance_token: str):
return self.client.post(
f'chat/markMessageAsRead/{instance_id}',
data={"readMessages": [m.__dict__ for m in messages]},
instance_token=instance_token
)
def archive_chat(self, instance_id: str, data: ArchiveChat, instance_token: str):
return self.client.post(
f'chat/archiveChat/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def mark_chat_unread(self, instance_id: str, data: UnreadChat, instance_token: str):
return self.client.post(
f'chat/markChatUnread/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def delete_message_for_everyone(self, instance_id: str, data: MessageKey, instance_token: str):
return self.client.delete(
f'chat/deleteMessageForEveryone/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def fetch_profile_picture_url(self, instance_id: str, data: ProfilePicture, instance_token: str):
return self.client.post(
f'chat/fetchProfilePictureUrl/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def get_base64_from_media_message(self, instance_id: str, data: MediaMessage, instance_token: str):
return self.client.post(
f'chat/getBase64FromMediaMessage/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def update_message(self, instance_id: str, data: UpdateMessage, instance_token: str):
return self.client.post(
f'chat/updateMessage/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def send_presence(self, instance_id: str, data: Presence, instance_token: str):
return self.client.post(
f'chat/sendPresence/{instance_id}',
data=data.__dict__,
instance_token=instance_token
)
def get_messages(
self,
instance_id: str,
remote_jid: str,
instance_token: str,
message_id: Optional[str] = None,
whatsapp_message_id: Optional[str] = None,
from_me: Optional[bool] = None,
message_type: Optional[str] = None,
source: Optional[str] = None,
timestamp_start: Optional[str] = None,
timestamp_end: Optional[str] = None,
page: int = 1,
offset: int = 50
):
'''
Obtém mensagens de um chat com filtros opcionais
Args:
timestamp_start: Data inicial no formato ISO (ex: "2025-01-16T00:00:00Z")
timestamp_end: Data final no formato ISO (ex: "2025-01-16T23:59:59Z")
'''
where = {"key": {"remoteJid": remote_jid}}
if message_id:
where["id"] = message_id
if whatsapp_message_id:
where["key"]["id"] = whatsapp_message_id
if from_me is not None:
where["key"]["fromMe"] = from_me
if message_type:
where["messageType"] = message_type
if source:
where["source"] = source
if timestamp_start or timestamp_end:
where["messageTimestamp"] = {}
if timestamp_start:
where["messageTimestamp"]["gte"] = timestamp_start
if timestamp_end:
where["messageTimestamp"]["lte"] = timestamp_end
payload = {
"where": where,
"page": page,
"offset": offset,
}
return self.client.post(
f'chat/findMessages/{instance_id}',
data=payload,
instance_token=instance_token,
)