fix: return [] if twilio-integration app is installed while getting whatsapp messages
This commit is contained in:
parent
3dc7a254b1
commit
bd8b9ca472
@ -1,6 +1,8 @@
|
||||
import frappe
|
||||
import json
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
|
||||
from crm.api.doc import get_assigned_users
|
||||
from crm.fcrm.doctype.crm_notification.crm_notification import notify_user
|
||||
|
||||
@ -82,8 +84,8 @@ def get_lead_or_deal_from_number(number):
|
||||
|
||||
def parse_mobile_no(mobile_no: str):
|
||||
"""Parse mobile number to remove spaces, brackets, etc.
|
||||
>>> parse_mobile_no('+91 (766) 667 6666')
|
||||
... '+917666676666'
|
||||
>>> parse_mobile_no("+91 (766) 667 6666")
|
||||
... "+917666676666"
|
||||
"""
|
||||
return "".join([c for c in mobile_no if c.isdigit() or c == "+"])
|
||||
|
||||
@ -104,6 +106,10 @@ def is_whatsapp_installed():
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_whatsapp_messages(reference_doctype, reference_name):
|
||||
# twilio integration app is not compatible with crm app
|
||||
# crm has its own twilio integration in built
|
||||
if "twilio-integration" in frappe.get_installed_apps():
|
||||
return []
|
||||
if not frappe.db.exists("DocType", "WhatsApp Message"):
|
||||
return []
|
||||
messages = []
|
||||
@ -170,9 +176,7 @@ def get_whatsapp_messages(reference_doctype, reference_name):
|
||||
)
|
||||
|
||||
# Filter messages to get only Template messages
|
||||
template_messages = [
|
||||
message for message in messages if message["message_type"] == "Template"
|
||||
]
|
||||
template_messages = [message for message in messages if message["message_type"] == "Template"]
|
||||
|
||||
# Iterate through template messages
|
||||
for template_message in template_messages:
|
||||
@ -184,35 +188,23 @@ def get_whatsapp_messages(reference_doctype, reference_name):
|
||||
template_message["template_name"] = template.template_name
|
||||
if template_message["template_parameters"]:
|
||||
parameters = json.loads(template_message["template_parameters"])
|
||||
template.template = parse_template_parameters(
|
||||
template.template, parameters
|
||||
)
|
||||
template.template = parse_template_parameters(template.template, parameters)
|
||||
|
||||
template_message["template"] = template.template
|
||||
if template_message["template_header_parameters"]:
|
||||
header_parameters = json.loads(
|
||||
template_message["template_header_parameters"]
|
||||
)
|
||||
template.header = parse_template_parameters(
|
||||
template.header, header_parameters
|
||||
)
|
||||
header_parameters = json.loads(template_message["template_header_parameters"])
|
||||
template.header = parse_template_parameters(template.header, header_parameters)
|
||||
template_message["header"] = template.header
|
||||
template_message["footer"] = template.footer
|
||||
|
||||
# Filter messages to get only reaction messages
|
||||
reaction_messages = [
|
||||
message for message in messages if message["content_type"] == "reaction"
|
||||
]
|
||||
reaction_messages = [message for message in messages if message["content_type"] == "reaction"]
|
||||
|
||||
# Iterate through reaction messages
|
||||
for reaction_message in reaction_messages:
|
||||
# Find the message that this reaction is reacting to
|
||||
reacted_message = next(
|
||||
(
|
||||
m
|
||||
for m in messages
|
||||
if m["message_id"] == reaction_message["reply_to_message_id"]
|
||||
),
|
||||
(m for m in messages if m["message_id"] == reaction_message["reply_to_message_id"]),
|
||||
None,
|
||||
)
|
||||
|
||||
@ -230,18 +222,12 @@ def get_whatsapp_messages(reference_doctype, reference_name):
|
||||
for reply_message in reply_messages:
|
||||
# Find the message that this message is replying to
|
||||
replied_message = next(
|
||||
(
|
||||
m
|
||||
for m in messages
|
||||
if m["message_id"] == reply_message["reply_to_message_id"]
|
||||
),
|
||||
(m for m in messages if m["message_id"] == reply_message["reply_to_message_id"]),
|
||||
None,
|
||||
)
|
||||
|
||||
# If the replied message is found, add the reply details to the reply message
|
||||
from_name = (
|
||||
get_from_name(reply_message) if replied_message["from"] else _("You")
|
||||
)
|
||||
from_name = get_from_name(reply_message) if replied_message["from"] else _("You")
|
||||
if replied_message:
|
||||
message = replied_message["message"]
|
||||
if replied_message["message_type"] == "Template":
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user