Chatwoot/app/mailers/conversation_reply_mailer.rb
Sony Mathew 0afa5c297f
Bug: Fixed conversation reply mail issue when an attachment is sent (#655)
* When an attachment was sent in the reply mailer it was breaking due to the
truncating function applied on the last message content. Here the content was empty
and so it broke.
* Fixed this breakage
* Also addressed the issue that if the attachment was there the content was coming empty.
With these changes, made the content to have a link to the attachment.
2020-03-30 16:07:01 +05:30

27 lines
996 B
Ruby

class ConversationReplyMailer < ApplicationMailer
default from: ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')
layout 'mailer'
def reply_with_summary(conversation, message_queued_time)
return unless smtp_config_set_or_development?
@conversation = conversation
@contact = @conversation.contact
@agent = @conversation.assignee
recap_messages = @conversation.messages.where('created_at < ?', message_queued_time).order(created_at: :asc).last(10)
new_messages = @conversation.messages.where('created_at >= ?', message_queued_time)
@messages = recap_messages + new_messages
@messages = @messages.select(&:reportable?)
mail(to: @contact&.email, reply_to: @agent&.email, subject: mail_subject(@messages.last))
end
private
def mail_subject(last_message, trim_length = 50)
subject_line = last_message&.content&.truncate(trim_length) || 'New messages on this conversation'
"[##{@conversation.display_id}] #{subject_line}"
end
end