From 5a92791bcc7715fc6f03fe68b20c30cc5bac97dd Mon Sep 17 00:00:00 2001 From: Duda Nogueira Date: Fri, 8 Mar 2024 16:06:56 -0300 Subject: [PATCH] [EVOLUTION] support message deletion in Rocket.Chat --- rocket_connect/plugins/evolution.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/rocket_connect/plugins/evolution.py b/rocket_connect/plugins/evolution.py index 47146dc..34006d9 100644 --- a/rocket_connect/plugins/evolution.py +++ b/rocket_connect/plugins/evolution.py @@ -365,6 +365,25 @@ def incoming(self): ) return JsonResponse({}) # + # messages deletion + # + if self.message.get("event") == "messages.delete": + if self.connector.server.type == "rocketchat": + # TODO: move this code do base? + ref_id = self.message.get("data").get("id") + if ref_id: + self.get_rocket_client() + msg = self.rocket.chat_get_message(msg_id=ref_id) + if msg: + new_message = ":warning: DELETED: ~{}~".format( + msg.json()["message"]["msg"] + ) + room = self.get_room() + self.rocket.chat_update( + room_id=room.room_id, msg_id=ref_id, text=new_message + ) + + # # handle calls # if self.message.get("event") == "call": @@ -538,6 +557,8 @@ def get_visitor_phone(self): # the phone can come both as remoteJid or chatId, for when it if self.message.get("event") == "call": remoteJid = self.message.get("data", {}).get("from") + elif self.message.get("event") == "messages.delete": + remoteJid = self.message.get("data", {}).get("remoteJid") else: remoteJid = self.message.get("data", {}).get("key", {}).get("remoteJid") if remoteJid: