Skip to content

Commit

Permalink
chore: Conversation history in email notifications (#3414)
Browse files Browse the repository at this point in the history
Display recent messages in the notification email when a new conversation is created.

Fixes: #2041
  • Loading branch information
shivamsinghchahar committed Nov 27, 2021
1 parent 6a98a81 commit bfcde9b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
15 changes: 14 additions & 1 deletion app/drops/conversation_drop.rb
Expand Up @@ -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
3 changes: 3 additions & 0 deletions app/drops/inbox_drop.rb
@@ -1,2 +1,5 @@
class InboxDrop < BaseDrop
def name
@obj.try(:name)
end
end
@@ -1,8 +1,30 @@
<p>Hi {{user.available_name}}</p>


<p>Time to save the world. A new conversation has been created in {{ inbox.name }}</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>

{% 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 %}

0 comments on commit bfcde9b

Please sign in to comment.