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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 5 deletions

View file

@ -5,13 +5,26 @@ class ConversationDrop < BaseDrop
@obj.try(:display_id) @obj.try(:display_id)
end end
def contact_name
@obj.try(:contact).name.capitalize || 'Customer'
end
def recent_messages def recent_messages
@obj.try(:recent_messages).map do |message| @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), 'content' => transform_user_mention_content(message.content),
'attachments' => message.attachments.map(&:file_url) 'attachments' => message.attachments.map(&:file_url)
} }
end end
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 end

View file

@ -1,2 +1,5 @@
class InboxDrop < BaseDrop class InboxDrop < BaseDrop
def name
@obj.try(:name)
end
end end

View file

@ -1,8 +1,30 @@
<p>Hi {{user.available_name}}</p> <p>Hi {{user.available_name}}</p>
<p>Time to save the world. A new conversation has been created in {{ inbox.name }}</p>
<p> <p>
Click <a href="{{ action_url }}">here</a> to get cracking. A new conversation (<a href="{{ action_url }}">#{{conversation.display_id}}</a>) has been created in {{ inbox.name }}.
<strong>{{ conversation.contact_name }}</strong> wrote:
</p> </p>
{% for chat_message in conversation.recent_messages %}
<div>
{% if chat_message.sender == user.available_name %}
<h4 style="margin: 0;">You</h4>
{% else %}
<h4 style="margin: 0;">{{chat_message.sender}}</h4>
{% endif %}
</div>
<div>
<p style="padding: 10px 20px; margin: 5px 0 20px 0; background: #F2F3F7; border-radius: 10px; display: inline-block; font-family: "Helvetica Neue",Tahoma,Arial,sans-serif; text-align: start; unicode-bidi: plaintext;">
{% if chat_message.content %}
{{chat_message.content}}
{% endif %}
{% if chat_message.attachments %}
{% for attachment in chat_message.attachments %}
Attachment [<a href="{{ attachment }}" _target="blank">Click here to view</a>]
{% endfor %}
{% endif %}
</p>
</div>
{% endfor %}