diff --git a/app/drops/conversation_drop.rb b/app/drops/conversation_drop.rb index 03bab2f58..1758c29c5 100644 --- a/app/drops/conversation_drop.rb +++ b/app/drops/conversation_drop.rb @@ -1,5 +1,17 @@ class ConversationDrop < BaseDrop + include MessageFormatHelper + def display_id @obj.try(:display_id) end + + def recent_messages + @obj.try(:recent_messages).map do |message| + { + 'sender' => message.sender&.available_name || message.sender&.name, + 'content' => transform_user_mention_content(message.content), + 'attachments' => message.attachments.map(&:file_url) + } + end + end end diff --git a/app/models/conversation.rb b/app/models/conversation.rb index fdfd5002a..a7a5b5b6d 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -147,6 +147,10 @@ class Conversation < ApplicationRecord inbox.inbox_type == 'Twitter' && additional_attributes['type'] == 'tweet' end + def recent_messages + messages.chat.last(5) + end + private def execute_after_update_commit_callbacks diff --git a/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_assignment.liquid b/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_assignment.liquid index 63e22f093..e138fd11a 100644 --- a/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_assignment.liquid +++ b/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_assignment.liquid @@ -2,6 +2,30 @@
Time to save the world. A new conversation has been assigned to you
+{% for chat_message in conversation.recent_messages %} ++ {% 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 %} +
+Click here to get cracking.
diff --git a/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_mention.liquid b/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_mention.liquid index 4783b1dde..9a30e6e09 100644 --- a/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_mention.liquid +++ b/app/views/mailers/agent_notifications/conversation_notifications_mailer/conversation_mention.liquid @@ -5,4 +5,28 @@ {{message.text_content}} +{% for chat_message in conversation.recent_messages %} ++ {% 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 %} +
+