Skip to content

Commit

Permalink
[EVOLUTION] handles call only once
Browse files Browse the repository at this point in the history
  • Loading branch information
dudanogueira committed Mar 8, 2024
1 parent 25ee843 commit 3f334f7
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions rocket_connect/plugins/evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,13 @@ def incoming(self):
# handle incoming call
self.get_rocket_client()
message, created = self.register_message()
room = self.get_room()
self.handle_incoming_call()
if not message.delivered:
room = self.get_room()
# adapt message to have the phone
phone = self.message.get("data").get("from").split("@")[0]
message.raw_message["visitor"] = {"phone": [{"phoneNumber": phone}]}
message.save()
self.handle_incoming_call()
return JsonResponse({})

#
Expand Down Expand Up @@ -416,6 +421,8 @@ def get_incoming_message_id(self):
id = None
if self.message.get("event") == "messages.upsert":
id = self.message.get("data", {}).get("key", {}).get("id")
if self.message.get("event") == "call":
id = self.message.get("data", {}).get("id")
return id

def get_visitor_name(self):
Expand All @@ -425,10 +432,13 @@ def get_visitor_name(self):
return None

def get_visitor_phone(self):
remoteJid = self.message.get("data", {}).get("key", {}).get("remoteJid")
# 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")
else:
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 3f334f7

Please sign in to comment.