diff --git a/app/drops/conversation_drop.rb b/app/drops/conversation_drop.rb index 1758c29c5243..b24586c301c1 100644 --- a/app/drops/conversation_drop.rb +++ b/app/drops/conversation_drop.rb @@ -5,13 +5,26 @@ def display_id @obj.try(:display_id) end + def contact_name + @obj.try(:contact).name.capitalize || 'Customer' + end + def recent_messages @obj.try(:recent_messages).map do |message| { - 'sender' => message.sender&.available_name || message.sender&.name, + 'sender' => message_sender_name(message.sender), 'content' => transform_user_mention_content(message.content), 'attachments' => message.attachments.map(&:file_url) } end end + + private + + def message_sender_name(sender) + return 'Bot' if sender.blank? + return contact_name if sender.instance_of?(Contact) + + sender&.available_name || sender&.name + end end diff --git a/app/drops/inbox_drop.rb b/app/drops/inbox_drop.rb index 7972e73255db..563916d5f2a5 100644 --- a/app/drops/inbox_drop.rb +++ b/app/drops/inbox_drop.rb @@ -1,2 +1,5 @@ class InboxDrop < BaseDrop + def name + @obj.try(:name) + end end diff --git a/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_creation.liquid b/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_creation.liquid index e324dd9e6ff3..095e1bd7b01d 100644 --- a/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_creation.liquid +++ b/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_creation.liquid @@ -1,8 +1,30 @@

Hi {{user.available_name}}

- -

Time to save the world. A new conversation has been created in {{ inbox.name }}

-

-Click here to get cracking. + A new conversation (#{{conversation.display_id}}) has been created in {{ inbox.name }}. + {{ conversation.contact_name }} wrote:

+ +{% for chat_message in conversation.recent_messages %} +
+ {% if chat_message.sender == user.available_name %} +

You

+ {% else %} +

{{chat_message.sender}}

+ {% endif %} +
+ +
+

+ {% if chat_message.content %} + {{chat_message.content}} + {% endif %} + + {% if chat_message.attachments %} + {% for attachment in chat_message.attachments %} + Attachment [Click here to view] + {% endfor %} + {% endif %} +

+
+{% endfor %}