chore: Conversation history in email notifications (#3414)

Display recent messages in the notification email when a new conversation is created.

Fixes: #2041
This commit is contained in:
Shivam Chahar
2021-11-27 15:38:27 +05:30
committed by GitHub
parent 6a98a812e7
commit bfcde9b022
3 changed files with 43 additions and 5 deletions

View File

@@ -5,13 +5,26 @@ class ConversationDrop < BaseDrop
@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