Skip to content

Commit

Permalink
[EVOLUTION] full active chat
Browse files Browse the repository at this point in the history
  • Loading branch information
dudanogueira committed Mar 9, 2024
1 parent fb3da61 commit b42895f
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions rocket_connect/plugins/evolution.py
Expand Up @@ -286,7 +286,7 @@ def active_chat(self):
agent
for agent in agents["users"]
if agent["status"] == "online"
and agent["statusLivechat"] == "available"
and agent.get("statusLivechat") == "available"
]
self.logger_info(
"NO DEPARTMENT FOUND. LOOKING INTO ONLINE AGENTS: {}".format(
Expand Down Expand Up @@ -358,23 +358,20 @@ def active_chat(self):
"message": "MESSAGE ALREADY SENT",
}
# create basic incoming new message, as payload
self.type = "incoming"
self.type = "incoming"
self.message = {
"from": check_number.get("response")
.get("id")
.get("_serialized"),
"chatId": check_number.get("response")
.get("id")
.get("_serialized"),
"id": self.message.get("message_id"),
"visitor": {
"token": "whatsapp:"
+ check_number["response"]["id"]["_serialized"]
"event": "messages.upsert",
"from": check_number.get("jid"),
"data": {
"key": {
"id": self.message.get("message_id"),
"remoteJid": check_number.get("jid")
}
},
}
self.check_number_info(
check_number["response"]["id"]["user"], augment_message=True
)
# self.check_number_info(
# check_number["response"]["id"]["user"], augment_message=True
# )
self.logger_info(
f"ACTIVE MESSAGE PAYLOAD GENERATED: {self.message}"
)
Expand Down Expand Up @@ -913,6 +910,8 @@ def get_incoming_message_id(self):
id = self.message.get("data", {}).get("key", {}).get("id")
elif self.message.get("event") in ["call", "messages.update"]:
id = self.message.get("data", {}).get("id")
if self.message.get("type") == "active_chat":
id = self.message.get("message_id")
return id

def get_visitor_name(self):
Expand All @@ -923,6 +922,7 @@ def get_visitor_name(self):

def get_visitor_phone(self):
# the phone can come both as remoteJid or chatId, for when it
message = self.message
if self.message.get("event") == "call":
remoteJid = self.message.get("data", {}).get("from")
elif self.message.get("event") == "messages.delete":
Expand All @@ -931,6 +931,7 @@ def get_visitor_phone(self):
remoteJid = self.message.get("data", {}).get("key", {}).get("remoteJid")
if remoteJid:
return remoteJid.split("@")[0]

return None

def get_visitor_username(self):
Expand Down

0 comments on commit b42895f

Please sign in to comment.