fix: removed send button in whatsapp box

This commit is contained in:
Shariq Ansari 2024-04-24 14:18:14 +05:30
parent 24a0f7a9b4
commit 332bffdf9f
3 changed files with 42 additions and 30 deletions

View File

@ -1,5 +1,6 @@
import frappe
import json
from frappe import _
def validate(doc, method):
if doc.type == "Incoming" and doc.get("from"):
@ -112,6 +113,9 @@ def get_whatsapp_messages(reference_doctype, reference_name):
if reacted_message:
reacted_message['reaction'] = reaction_message['message']
for message in messages:
from_name = get_from_name(message) if message['from'] else _('You')
message['from_name'] = from_name
# Filter messages to get only replies
reply_messages = [message for message in messages if message['is_reply']]
@ -121,15 +125,7 @@ def get_whatsapp_messages(reference_doctype, reference_name):
replied_message = next((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
doc = frappe.get_doc(reply_message['reference_doctype'], reply_message['reference_name'])
from_name = replied_message['from']
if doc.get("contacts"):
for c in doc.get("contacts"):
if c.is_primary:
from_name = c.full_name or c.mobile_no
break
else:
from_name = doc.get("first_name") + " " + doc.get("last_name")
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':
@ -202,4 +198,19 @@ def parse_template_parameters(string, parameters):
placeholder = "{{" + str(i) + "}}"
string = string.replace(placeholder, parameter)
return string
return string
def get_from_name(message):
doc = frappe.get_doc(message['reference_doctype'], message['reference_name'])
from_name = ''
if message['reference_doctype'] == "CRM Deal":
if doc.get("contacts"):
for c in doc.get("contacts"):
if c.is_primary:
from_name = c.full_name or c.mobile_no
break
else:
from_name = doc.get("lead_name")
else:
from_name = doc.get("first_name") + " " + doc.get("last_name")
return from_name

View File

@ -153,7 +153,7 @@
>
<Button
@click="() => (reaction = true) && togglePopover()"
class="rounded-full"
class="rounded-full !size-6 mt-0.5"
>
<ReactIcon class="text-gray-400" />
</Button>
@ -233,7 +233,10 @@ function messageOptions(message) {
label: 'Reply',
onClick: () => {
replyMode.value = true
reply.value = message
reply.value = {
...message,
message: formatWhatsAppMessage(message.message)
}
},
},
// {

View File

@ -1,11 +1,22 @@
<template>
<div v-if="reply?.message" class="flex justify-around items-center gap-2 px-10 pt-2">
<div
v-if="reply?.message"
class="flex items-center justify-around gap-2 px-10 pt-2"
>
<div
class="rounded-md flex-1 border-0 border-l-4 border-green-500 bg-gray-50 px-2 py-4 ml-13"
class="mb-1 ml-13 flex-1 cursor-pointer rounded border-0 border-l-4 border-green-500 bg-gray-100 p-2 text-base text-gray-600"
:class="reply.type == 'Incoming' ? 'border-green-500' : 'border-blue-400'"
>
{{ reply.message }}
<div
class="mb-1 text-sm font-bold"
:class="reply.type == 'Incoming' ? 'text-green-500' : 'text-blue-400'"
>
{{ reply.from_name || __('You') }}
</div>
<div class="max-h-12 overflow-hidden" v-html="reply.message" />
</div>
<Button class="mx-[11px]" variant="ghost" icon="x" @click="reply = {}" />
<Button variant="ghost" icon="x" @click="reply = {}" />
</div>
<div class="flex items-end gap-2 px-10 py-2.5">
<div class="flex h-8 items-center gap-2">
@ -51,15 +62,6 @@
@blur="rows = 1"
@keydown.enter="(e) => sendTextMessage(e)"
/>
<div class="flex justify-end gap-2">
<Button
class="min-h-8"
variant="solid"
:label="__('Send')"
@click="sendWhatsAppMessage"
:disabled="isEmpty"
/>
</div>
</div>
</template>
@ -85,10 +87,6 @@ const content = ref('')
const placeholder = ref(__('Type your message here...'))
const fileType = ref('')
const isEmpty = computed(() => {
return !content.value || content.value === '<p></p>'
})
function show() {
nextTick(() => textarea.value.$el.focus())
}
@ -158,7 +156,7 @@ function uploadOptions(openFileSelector) {
]
}
watch(() => reply.value, (value) => {
watch(reply, (value) => {
if (value?.message) {
show()
}