diff --git a/crm/api/activities.py b/crm/api/activities.py index d3a3a63a..e2aa7ec6 100644 --- a/crm/api/activities.py +++ b/crm/api/activities.py @@ -341,7 +341,20 @@ def get_linked_tasks(name): def get_whatsapp_messages(name): whatsapp_messages = frappe.db.get_all( "WhatsApp Message", - filters={"reference_doctype": "CRM Lead", "reference_name": name, "status": ("not in", ["failed", "Success"])}, + filters={"reference_doctype": "CRM Lead", "reference_name": name, "status": ("not in", ["failed"])}, fields=["name", "type", "to", "from", "content_type", "creation", "message", "status"], ) - return whatsapp_messages or [] \ No newline at end of file + return whatsapp_messages or [] + +@frappe.whitelist() +def create_whatsapp_message(reference_doctype, reference_name, to, message, content_type="text"): + doc = frappe.new_doc("WhatsApp Message") + doc.update({ + "reference_doctype": reference_doctype, + "reference_name": reference_name, + "to": to, + "message": message, + "content_type": content_type, + }) + doc.insert(ignore_permissions=True) + return doc.name \ No newline at end of file diff --git a/frontend/src/components/Activities.vue b/frontend/src/components/Activities.vue index 829468a4..ef228ebe 100644 --- a/frontend/src/components/Activities.vue +++ b/frontend/src/components/Activities.vue @@ -35,16 +35,23 @@ {{ __('New Task') }} - +
+ + +
{{ __('Loading...') }} -
+
+ +
+
-
+ nextTick(() => scroll()), }) function get_activities() { @@ -929,10 +951,8 @@ const activities = computed(() => { } else if (props.title == 'Notes') { if (!all_activities.data?.notes) return [] return sortByCreation(all_activities.data.notes) - } else if (props.title == 'WhatsApp') { - if (!whatsappMessages.data) return [] - return sortByCreation(whatsappMessages.data) } + activities.forEach((activity) => { activity.icon = timelineIcon(activity.activity_type, activity.is_lead) diff --git a/frontend/src/components/WhatsAppArea.vue b/frontend/src/components/WhatsAppArea.vue index 8b70a49e..8104fcbe 100644 --- a/frontend/src/components/WhatsAppArea.vue +++ b/frontend/src/components/WhatsAppArea.vue @@ -3,19 +3,24 @@
-
{{ whatsapp.message }}
-
+
+
-
{{ dateFormat(whatsapp.creation, 'hh:mm a') }}
+
+ {{ dateFormat(whatsapp.creation, 'hh:mm a') }} +
- + $1') + // if message contains *text*, make it bold + message = message.replace(/\*(.*?)\*/g, '$1') + // if message contains ~text~, make it strikethrough + message = message.replace(/~(.*?)~/g, '$1') + // if message contains ```text```, make it monospace + message = message.replace(/```(.*?)```/g, '$1') + // if message contains `text`, make it inline code + message = message.replace(/`(.*?)`/g, '$1') + // if message contains > text, make it a blockquote + message = message.replace(/^> (.*)$/gm, '
$1
') + // if contain /n, make it a new line + message = message.replace(/\n/g, '
') + // if contains *text, make it a bullet point + message = message.replace(/\* (.*?)(?=\s*\*|$)/g, '
  • $1
  • ') + message = message.replace(/- (.*?)(?=\s*-|$)/g, '
  • $1
  • ') + message = message.replace(/(\d+)\. (.*?)(?=\s*(\d+)\.|$)/g, '
  • $2
  • ') + + return message + +} diff --git a/frontend/src/components/WhatsAppBox.vue b/frontend/src/components/WhatsAppBox.vue new file mode 100644 index 00000000..e73da3d9 --- /dev/null +++ b/frontend/src/components/WhatsAppBox.vue @@ -0,0 +1,59 @@ +