diff --git a/crm/api/whatsapp.py b/crm/api/whatsapp.py index 3e3889be..7a7ef240 100644 --- a/crm/api/whatsapp.py +++ b/crm/api/whatsapp.py @@ -10,8 +10,15 @@ from crm.fcrm.doctype.crm_notification.crm_notification import notify_user def validate(doc, method): if doc.type == "Incoming" and doc.get("from"): name, doctype = get_lead_or_deal_from_number(doc.get("from")) - doc.reference_doctype = doctype - doc.reference_name = name + if name != None: + doc.reference_doctype = doctype + doc.reference_name = name + + if doc.type == "Outgoing" and doc.get("to"): + name, doctype = get_lead_or_deal_from_number(doc.get("to")) + if name != None: + doc.reference_doctype = doctype + doc.reference_name = name def on_update(doc, method): @@ -29,7 +36,7 @@ def on_update(doc, method): def notify_agent(doc): if doc.type == "Incoming": doctype = doc.reference_doctype - if doctype.startswith("CRM "): + if doctype and doctype.startswith("CRM "): doctype = doctype[4:].lower() notification_text = f"""