Skip to content

Commit

Permalink
[EVOLUTION] support for quoted message and better rendering for react…
Browse files Browse the repository at this point in the history
…ions.

Fix agent name not being sent
  • Loading branch information
dudanogueira committed Apr 20, 2024
1 parent a0c5166 commit 8632e66
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
15 changes: 15 additions & 0 deletions local.yml
Expand Up @@ -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
Expand Down Expand Up @@ -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"
25 changes: 23 additions & 2 deletions rocket_connect/plugins/evolution.py
Expand Up @@ -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
#
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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({})
#
Expand Down Expand Up @@ -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)},
Expand Down

0 comments on commit 8632e66

Please sign in to comment.