* [#139] Delayed emails for conversations * Added the setex and get methods to Redis wrapper * Set the priorities for the sidekiq queues * Was not able to use mailhog for testing email in local, switched back to letter opener and added comments on using the SMTP settings * Added after create hood in messages to queue the sending of mail after 2 minutes using sidekiq worker and also set the redis key for the conversation to avoid the email sending for every message * Added the sidekiq worker to send the email and delete the conversation redis key * Added the mailer and mail template * mailer sends the last 10 messages along with the new messages from the time it was queued * Send email only in development or if smtp config is set * Send email only in development or if smtp config is set * Set the SMTP_PORT in production variable * Adding redis to circle CI * Specs for the conversation email changes * Added specs for conversation email sidekiq worker * Added specs for conversation mailer * Added specs in message model for the after create hook for notify email * Send emails only when there is a reply from agent * set development to use mailhog * Adding comments for using letter opener
This commit is contained in:
@@ -4,4 +4,8 @@ class ApplicationMailer < ActionMailer::Base
|
||||
|
||||
# helpers
|
||||
helper :frontend_urls
|
||||
|
||||
def smtp_config_set_or_development?
|
||||
ENV.fetch('SMTP_ADDRESS', nil).present? || Rails.env.development?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ class AssignmentMailer < ApplicationMailer
|
||||
layout 'mailer'
|
||||
|
||||
def conversation_assigned(conversation, agent)
|
||||
return if ENV.fetch('SMTP_ADDRESS', nil).blank?
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
@agent = agent
|
||||
@conversation = conversation
|
||||
|
||||
26
app/mailers/conversation_mailer.rb
Normal file
26
app/mailers/conversation_mailer.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
class ConversationMailer < ApplicationMailer
|
||||
default from: ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')
|
||||
layout 'mailer'
|
||||
|
||||
def new_message(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, from: @agent&.email, subject: mail_subject(@messages.last))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def mail_subject(last_message, trim_length = 30)
|
||||
"[##{@conversation.display_id}] #{last_message.content.truncate(trim_length)}"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user