mirror of
https://github.com/EvolutionAPI/evolution-client-python.git
synced 2025-12-14 20:29:33 -06:00
Merge f3a319516e into 043a7f9b3c
This commit is contained in:
commit
be3f74f092
@ -1,78 +1,91 @@
|
|||||||
from typing import Union, BinaryIO, Optional
|
from typing import Union, BinaryIO, Optional
|
||||||
from ..models.chat import *
|
from ..models.chat import *
|
||||||
|
|
||||||
|
|
||||||
class ChatService:
|
class ChatService:
|
||||||
def __init__(self, client):
|
def __init__(self, client):
|
||||||
self.client = client
|
self.client = client
|
||||||
|
|
||||||
def check_is_whatsapp_numbers(self, instance_id: str, data: CheckIsWhatsappNumber, instance_token: str):
|
def check_is_whatsapp_numbers(
|
||||||
|
self, instance_id: str, data: CheckIsWhatsappNumber, instance_token: str
|
||||||
|
):
|
||||||
return self.client.post(
|
return self.client.post(
|
||||||
f'chat/checkIsWhatsappNumber/{instance_id}',
|
f"chat/whatsappNumbers/{instance_id}",
|
||||||
data=data.__dict__,
|
data=data.__dict__,
|
||||||
instance_token=instance_token
|
instance_token=instance_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
def mark_message_as_read(self, instance_id: str, messages: List[ReadMessage], instance_token: str):
|
def mark_message_as_read(
|
||||||
|
self, instance_id: str, messages: List[ReadMessage], instance_token: str
|
||||||
|
):
|
||||||
return self.client.post(
|
return self.client.post(
|
||||||
f'chat/markMessageAsRead/{instance_id}',
|
f"chat/markMessageAsRead/{instance_id}",
|
||||||
data={"readMessages": [m.__dict__ for m in messages]},
|
data={"readMessages": [m.__dict__ for m in messages]},
|
||||||
instance_token=instance_token
|
instance_token=instance_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
def archive_chat(self, instance_id: str, data: ArchiveChat, instance_token: str):
|
def archive_chat(self, instance_id: str, data: ArchiveChat, instance_token: str):
|
||||||
return self.client.post(
|
return self.client.post(
|
||||||
f'chat/archiveChat/{instance_id}',
|
f"chat/archiveChat/{instance_id}",
|
||||||
data=data.__dict__,
|
data=data.__dict__,
|
||||||
instance_token=instance_token
|
instance_token=instance_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
def mark_chat_unread(self, instance_id: str, data: UnreadChat, instance_token: str):
|
def mark_chat_unread(self, instance_id: str, data: UnreadChat, instance_token: str):
|
||||||
return self.client.post(
|
return self.client.post(
|
||||||
f'chat/markChatUnread/{instance_id}',
|
f"chat/markChatUnread/{instance_id}",
|
||||||
data=data.__dict__,
|
data=data.__dict__,
|
||||||
instance_token=instance_token
|
instance_token=instance_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete_message_for_everyone(self, instance_id: str, data: MessageKey, instance_token: str):
|
def delete_message_for_everyone(
|
||||||
|
self, instance_id: str, data: MessageKey, instance_token: str
|
||||||
|
):
|
||||||
return self.client.delete(
|
return self.client.delete(
|
||||||
f'chat/deleteMessageForEveryone/{instance_id}',
|
f"chat/deleteMessageForEveryone/{instance_id}",
|
||||||
data=data.__dict__,
|
data=data.__dict__,
|
||||||
instance_token=instance_token
|
instance_token=instance_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
def fetch_profile_picture_url(self, instance_id: str, data: ProfilePicture, instance_token: str):
|
def fetch_profile_picture_url(
|
||||||
|
self, instance_id: str, data: ProfilePicture, instance_token: str
|
||||||
|
):
|
||||||
return self.client.post(
|
return self.client.post(
|
||||||
f'chat/fetchProfilePictureUrl/{instance_id}',
|
f"chat/fetchProfilePictureUrl/{instance_id}",
|
||||||
data=data.__dict__,
|
data=data.__dict__,
|
||||||
instance_token=instance_token
|
instance_token=instance_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_base64_from_media_message(self, instance_id: str, data: MediaMessage, instance_token: str):
|
def get_base64_from_media_message(
|
||||||
|
self, instance_id: str, data: MediaMessage, instance_token: str
|
||||||
|
):
|
||||||
return self.client.post(
|
return self.client.post(
|
||||||
f'chat/getBase64FromMediaMessage/{instance_id}',
|
f"chat/getBase64FromMediaMessage/{instance_id}",
|
||||||
data=data.__dict__,
|
data=data.__dict__,
|
||||||
instance_token=instance_token
|
instance_token=instance_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_message(self, instance_id: str, data: UpdateMessage, instance_token: str):
|
def update_message(
|
||||||
|
self, instance_id: str, data: UpdateMessage, instance_token: str
|
||||||
|
):
|
||||||
return self.client.post(
|
return self.client.post(
|
||||||
f'chat/updateMessage/{instance_id}',
|
f"chat/updateMessage/{instance_id}",
|
||||||
data=data.__dict__,
|
data=data.__dict__,
|
||||||
instance_token=instance_token
|
instance_token=instance_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
def send_presence(self, instance_id: str, data: Presence, instance_token: str):
|
def send_presence(self, instance_id: str, data: Presence, instance_token: str):
|
||||||
return self.client.post(
|
return self.client.post(
|
||||||
f'chat/sendPresence/{instance_id}',
|
f"chat/sendPresence/{instance_id}",
|
||||||
data=data.__dict__,
|
data=data.__dict__,
|
||||||
instance_token=instance_token
|
instance_token=instance_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_messages(
|
def get_messages(
|
||||||
self,
|
self,
|
||||||
instance_id: str,
|
instance_id: str,
|
||||||
remote_jid: str,
|
remote_jid: str,
|
||||||
instance_token: str,
|
instance_token: str,
|
||||||
message_id: Optional[str] = None,
|
message_id: Optional[str] = None,
|
||||||
whatsapp_message_id: Optional[str] = None,
|
whatsapp_message_id: Optional[str] = None,
|
||||||
from_me: Optional[bool] = None,
|
from_me: Optional[bool] = None,
|
||||||
@ -80,18 +93,18 @@ class ChatService:
|
|||||||
source: Optional[str] = None,
|
source: Optional[str] = None,
|
||||||
timestamp_start: Optional[str] = None,
|
timestamp_start: Optional[str] = None,
|
||||||
timestamp_end: Optional[str] = None,
|
timestamp_end: Optional[str] = None,
|
||||||
page: int = 1,
|
page: int = 1,
|
||||||
offset: int = 50
|
offset: int = 50,
|
||||||
):
|
):
|
||||||
'''
|
"""
|
||||||
Obtém mensagens de um chat com filtros opcionais
|
Obtém mensagens de um chat com filtros opcionais
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
timestamp_start: Data inicial no formato ISO (ex: "2025-01-16T00:00:00Z")
|
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")
|
timestamp_end: Data final no formato ISO (ex: "2025-01-16T23:59:59Z")
|
||||||
'''
|
"""
|
||||||
where = {"key": {"remoteJid": remote_jid}}
|
where = {"key": {"remoteJid": remote_jid}}
|
||||||
|
|
||||||
if message_id:
|
if message_id:
|
||||||
where["id"] = message_id
|
where["id"] = message_id
|
||||||
if whatsapp_message_id:
|
if whatsapp_message_id:
|
||||||
@ -108,15 +121,15 @@ class ChatService:
|
|||||||
where["messageTimestamp"]["gte"] = timestamp_start
|
where["messageTimestamp"]["gte"] = timestamp_start
|
||||||
if timestamp_end:
|
if timestamp_end:
|
||||||
where["messageTimestamp"]["lte"] = timestamp_end
|
where["messageTimestamp"]["lte"] = timestamp_end
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
"where": where,
|
"where": where,
|
||||||
"page": page,
|
"page": page,
|
||||||
"offset": offset,
|
"offset": offset,
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.client.post(
|
return self.client.post(
|
||||||
f'chat/findMessages/{instance_id}',
|
f"chat/findMessages/{instance_id}",
|
||||||
data=payload,
|
data=payload,
|
||||||
instance_token=instance_token,
|
instance_token=instance_token,
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user