From 8632e66fa7f758c93d53b32399c1f3f0caef8e13 Mon Sep 17 00:00:00 2001 From: Duda Nogueira Date: Sat, 20 Apr 2024 15:02:18 -0300 Subject: [PATCH] [EVOLUTION] support for quoted message and better rendering for reactions. Fix agent name not being sent --- local.yml | 15 +++++++++++++++ rocket_connect/plugins/evolution.py | 25 +++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/local.yml b/local.yml index 3416a87..70e70d3 100644 --- a/local.yml +++ b/local.yml @@ -5,6 +5,8 @@ volumes: rocketconnect_local_postgres_data_backups: {} evolution_local_store: {} evolution_local_instances: {} + local_wppconnect_data: {} + local_wppconnect_tokens: {} services: django: &django @@ -108,3 +110,16 @@ services: env_file: - ./compose/local/evolution/env command: ['node', './dist/src/main.js'] + + wppconnect: + #image: wppconnect/server-cli:main + # for some reason, the server-cli is not working properly + # in mac, so build it locally and use it here: + image: server-cli-local + # for command options: https://github.com/wppconnect-team/server-cli/blob/main/src/program.js + command: wppserver --startAllSession + volumes: + - local_wppconnect_data:/usr/src/server-cli/userDataDir + - local_wppconnect_tokens:/usr/src/server-cli/tokens + ports: + - "21465:21465" diff --git a/rocket_connect/plugins/evolution.py b/rocket_connect/plugins/evolution.py index 7cb88c5..1062056 100644 --- a/rocket_connect/plugins/evolution.py +++ b/rocket_connect/plugins/evolution.py @@ -580,6 +580,23 @@ def incoming(self): room = self.get_room(department) if not room: return JsonResponse({"message": "no room generated"}) + + # + # outcome if a quoted message + # + quoted = message.get("extendedTextMessage", {}).get("contextInfo", {}).get("quotedMessage") + if quoted: + msg = message.get("extendedTextMessage", {}).get("text") + quoted_message = quoted.get("conversation") + # add > to beginning of quoted message + formatted_text = "\n".join([f">{line}" for line in quoted_message.split("\n")]) + new_message = f"{formatted_text} \n {msg}" + self.outcome_text( + room_id=room.room_id, + text=new_message, + message_id=self.get_message_id(), + ).json() + return JsonResponse({"message": "Quoted incoming message"}) # # outcome if is a reaction # @@ -610,7 +627,8 @@ def incoming(self): else: msg = "some message (audio, for example)" reaction = ref_message.get("text") - new_message = f"Reacted: {reaction} to: {msg}" + formatted_text = "\n".join([f">{line}" for line in msg.split("\n")]) + new_message = f"{formatted_text}\n{reaction}" room = self.get_room() self.outcome_text( room_id=room.room_id, @@ -769,7 +787,7 @@ def incoming(self): else: self.logger_info( - f"Message Object {message.id} Already delivered. Ignoring", + f"Message Object {str(message)} Already delivered. Ignoring", ) return JsonResponse({}) # @@ -868,6 +886,9 @@ def outgo_text_message(self, message, agent_name=None): content = message else: content = message["msg"] + if agent_name: + content = self.render_message_agent_template(content, agent_name) + # content = "*[" + agent_name + "]*\n" + content payload = { "number": self.get_ingoing_visitor_phone() or self.get_visitor_phone(), "options": {"delay": self.connector.config.get("send_message_delay", 1200)},