feat: Enable Markdown Parsing in emails (#1663)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -29,6 +29,8 @@ gem 'flag_shih_tzu'
|
|||||||
gem 'haikunator'
|
gem 'haikunator'
|
||||||
# Template parsing safetly
|
# Template parsing safetly
|
||||||
gem 'liquid'
|
gem 'liquid'
|
||||||
|
# Parse Markdown to HTML
|
||||||
|
gem 'redcarpet'
|
||||||
|
|
||||||
##-- for active storage --##
|
##-- for active storage --##
|
||||||
gem 'aws-sdk-s3', require: false
|
gem 'aws-sdk-s3', require: false
|
||||||
|
|||||||
@@ -384,6 +384,7 @@ GEM
|
|||||||
rb-fsevent (0.10.4)
|
rb-fsevent (0.10.4)
|
||||||
rb-inotify (0.10.1)
|
rb-inotify (0.10.1)
|
||||||
ffi (~> 1.0)
|
ffi (~> 1.0)
|
||||||
|
redcarpet (3.5.1)
|
||||||
redis (4.2.1)
|
redis (4.2.1)
|
||||||
redis-namespace (1.8.0)
|
redis-namespace (1.8.0)
|
||||||
redis (>= 3.0.4)
|
redis (>= 3.0.4)
|
||||||
@@ -628,6 +629,7 @@ DEPENDENCIES
|
|||||||
pundit
|
pundit
|
||||||
rack-cors
|
rack-cors
|
||||||
rails
|
rails
|
||||||
|
redcarpet
|
||||||
redis
|
redis
|
||||||
redis-namespace
|
redis-namespace
|
||||||
redis-rack-cache
|
redis-rack-cache
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class ContactBuilder
|
|||||||
contact_inbox = inbox.contact_inboxes.find_by(source_id: source_id)
|
contact_inbox = inbox.contact_inboxes.find_by(source_id: source_id)
|
||||||
return contact_inbox if contact_inbox
|
return contact_inbox if contact_inbox
|
||||||
|
|
||||||
build_contact
|
build_contact_inbox
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -26,16 +26,29 @@ class ContactBuilder
|
|||||||
::ContactAvatarJob.perform_later(contact, contact_attributes[:avatar_url]) if contact_attributes[:avatar_url]
|
::ContactAvatarJob.perform_later(contact, contact_attributes[:avatar_url]) if contact_attributes[:avatar_url]
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_contact
|
def create_contact
|
||||||
ActiveRecord::Base.transaction do
|
account.contacts.create!(
|
||||||
contact = account.contacts.create!(
|
name: contact_attributes[:name],
|
||||||
name: contact_attributes[:name],
|
phone_number: contact_attributes[:phone_number],
|
||||||
phone_number: contact_attributes[:phone_number],
|
email: contact_attributes[:email],
|
||||||
email: contact_attributes[:email],
|
identifier: contact_attributes[:identifier],
|
||||||
identifier: contact_attributes[:identifier],
|
additional_attributes: contact_attributes[:additional_attributes]
|
||||||
additional_attributes: contact_attributes[:additional_attributes]
|
)
|
||||||
)
|
end
|
||||||
|
|
||||||
|
def find_contact
|
||||||
|
contact = nil
|
||||||
|
|
||||||
|
contact = account.contacts.find_by(identifier: contact_attributes[:identifier]) if contact_attributes[:identifier].present?
|
||||||
|
|
||||||
|
contact ||= account.contacts.find_by(email: contact_attributes[:email]) if contact_attributes[:email].present?
|
||||||
|
|
||||||
|
contact
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_contact_inbox
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
contact = find_contact || create_contact
|
||||||
contact_inbox = create_contact_inbox(contact)
|
contact_inbox = create_contact_inbox(contact)
|
||||||
update_contact_avatar(contact)
|
update_contact_avatar(contact)
|
||||||
contact_inbox
|
contact_inbox
|
||||||
|
|||||||
@@ -130,8 +130,8 @@ class ConversationReplyMailer < ApplicationMailer
|
|||||||
def conversation_reply_email_id
|
def conversation_reply_email_id
|
||||||
content_attributes = @conversation.messages.incoming.last&.content_attributes
|
content_attributes = @conversation.messages.incoming.last&.content_attributes
|
||||||
|
|
||||||
if content_attributes && content_attributes['email'] && content_attributes['message_id']
|
if content_attributes && content_attributes['email'] && content_attributes['email']['message_id']
|
||||||
"<#{@conversation.messages.incoming.last.content_attributes['email']['message_id']}>"
|
return "<#{content_attributes['email']['message_id']}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
nil
|
nil
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
<% markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true) %>
|
||||||
<% @messages.each do |message| %>
|
<% @messages.each do |message| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
@@ -7,7 +8,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td style="padding-bottom: 16px;">
|
<td style="padding-bottom: 16px;">
|
||||||
<% if message.content %>
|
<% if message.content %>
|
||||||
<%= message.content %>
|
<%= markdown.render(message.content).html_safe %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if message.attachments %>
|
<% if message.attachments %>
|
||||||
<% message.attachments.each do |attachment| %>
|
<% message.attachments.each do |attachment| %>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
<% markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true) %>
|
||||||
<p>Hi <%= @contact.name %>,</p>
|
<p>Hi <%= @contact.name %>,</p>
|
||||||
|
|
||||||
<p>You have new messages on your conversation.</p>
|
<p>You have new messages on your conversation.</p>
|
||||||
@@ -11,7 +12,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td 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;">
|
<td 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 message.content %>
|
<% if message.content %>
|
||||||
<%= message.content %>
|
<%= markdown.render(message.content).html_safe %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if message.attachments %>
|
<% if message.attachments %>
|
||||||
<% message.attachments.each do |attachment| %>
|
<% message.attachments.each do |attachment| %>
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
<% markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true) %>
|
||||||
|
|
||||||
<% @messages.each do |message| %>
|
<% @messages.each do |message| %>
|
||||||
<p style="font-family: Roboto,"Helvetica Neue",Tahoma,Arial,sans-serif; text-align: start; unicode-bidi: plaintext;">
|
<p style="font-family: Roboto,"Helvetica Neue",Tahoma,Arial,sans-serif; text-align: start; unicode-bidi: plaintext;">
|
||||||
<% if message.content %>
|
<% if message.content %>
|
||||||
<%= message.content.gsub("\n", "<br/>").html_safe %>
|
<%= markdown.render(message.content).html_safe %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if message.attachments %>
|
<% if message.attachments %>
|
||||||
<% message.attachments.each do |attachment| %>
|
<% message.attachments.each do |attachment| %>
|
||||||
|
|||||||
Reference in New Issue
Block a user