From 37320e247b65164bdcf764336175d63f38096536 Mon Sep 17 00:00:00 2001 From: rafaelcalassara Date: Fri, 3 Jan 2025 21:55:27 -0300 Subject: [PATCH 1/3] feat: add get_messages method to retrieve chat messages by remote JID --- evolutionapi/services/chat.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/evolutionapi/services/chat.py b/evolutionapi/services/chat.py index b2af456..b5d4350 100644 --- a/evolutionapi/services/chat.py +++ b/evolutionapi/services/chat.py @@ -66,4 +66,13 @@ class ChatService: f'chat/sendPresence/{instance_id}', data=data.__dict__, instance_token=instance_token - ) \ No newline at end of file + ) + + def get_messages(self, instance_id: str, remote_jid: str, instance_token: str): + '''Get messages from a chat''' + payload = {"where": {"key": {"remoteJid": remote_jid}}} + return self.client.post( + f'chat/findMessages/{instance_id}', + data=payload, + instance_token=instance_token, + ) From 40ab492eace12534e6944c85a85a37875a10007d Mon Sep 17 00:00:00 2001 From: rafaelcalassara Date: Fri, 3 Jan 2025 22:02:12 -0300 Subject: [PATCH 2/3] chore: add .gitignore to exclude Python-generated files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd9a7b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Python-generated files +__pycache__/ +*.cpython*.pyc \ No newline at end of file From 5d5135ffec50928b098440f28c7e968f2340545a Mon Sep 17 00:00:00 2001 From: rafaelcalassara Date: Fri, 3 Jan 2025 23:07:14 -0300 Subject: [PATCH 3/3] feat: enhance get_messages method to support pagination with page and offset parameters --- evolutionapi/services/chat.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/evolutionapi/services/chat.py b/evolutionapi/services/chat.py index b5d4350..d4d3291 100644 --- a/evolutionapi/services/chat.py +++ b/evolutionapi/services/chat.py @@ -68,9 +68,13 @@ class ChatService: instance_token=instance_token ) - def get_messages(self, instance_id: str, remote_jid: str, instance_token: str): + def get_messages(self, instance_id: str, remote_jid: str, instance_token: str, page: int = 1, offset: int = 50): '''Get messages from a chat''' - payload = {"where": {"key": {"remoteJid": remote_jid}}} + payload = { + "where": {"key": {"remoteJid": remote_jid}}, + "page": page, + "offset": offset, + } return self.client.post( f'chat/findMessages/{instance_id}', data=payload,