feat: Customisable Email Templates (#1095)
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
class AgentNotifications::ConversationNotificationsMailer < ApplicationMailer
|
||||
default from: ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')
|
||||
layout 'mailer'
|
||||
|
||||
def conversation_creation(conversation, agent)
|
||||
return unless smtp_config_set_or_development?
|
||||
|
||||
@agent = agent
|
||||
@conversation = conversation
|
||||
subject = "#{@agent.available_name}, A new conversation [ID - #{@conversation.display_id}] has been created in #{@conversation.inbox&.name}."
|
||||
mail(to: @agent.email, subject: subject)
|
||||
@action_url = app_account_conversation_url(account_id: @conversation.account_id, id: @conversation.display_id)
|
||||
send_mail_with_liquid(to: @agent.email, subject: subject) and return
|
||||
end
|
||||
|
||||
def conversation_assignment(conversation, agent)
|
||||
@@ -16,6 +14,18 @@ class AgentNotifications::ConversationNotificationsMailer < ApplicationMailer
|
||||
|
||||
@agent = agent
|
||||
@conversation = conversation
|
||||
mail(to: @agent.email, subject: "#{@agent.available_name}, A new conversation [ID - #{@conversation.display_id}] has been assigned to you.")
|
||||
subject = "#{@agent.available_name}, A new conversation [ID - #{@conversation.display_id}] has been assigned to you."
|
||||
@action_url = app_account_conversation_url(account_id: @conversation.account_id, id: @conversation.display_id)
|
||||
send_mail_with_liquid(to: @agent.email, subject: subject) and return
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def liquid_droppables
|
||||
super.merge({
|
||||
user: @agent,
|
||||
conversation: @conversation,
|
||||
inbox: @conversation.inbox
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
class ApplicationMailer < ActionMailer::Base
|
||||
default from: ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')
|
||||
layout 'mailer'
|
||||
append_view_path Rails.root.join('app/views/mailers')
|
||||
include ActionView::Helpers::SanitizeHelper
|
||||
|
||||
# helpers
|
||||
default from: ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')
|
||||
before_action { ensure_current_account(params.try(:[], :account)) }
|
||||
layout 'mailer/base'
|
||||
# Fetch template from Database if available
|
||||
# Order: Account Specific > Installation Specific > Fallback to file
|
||||
prepend_view_path ::EmailTemplate.resolver
|
||||
append_view_path Rails.root.join('app/views/mailers')
|
||||
helper :frontend_urls
|
||||
helper do
|
||||
def global_config
|
||||
@@ -14,4 +18,36 @@ class ApplicationMailer < ActionMailer::Base
|
||||
def smtp_config_set_or_development?
|
||||
ENV.fetch('SMTP_ADDRESS', nil).present? || Rails.env.development?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def send_mail_with_liquid(*args)
|
||||
mail(*args) do |format|
|
||||
# explored sending a multipart email containg both text type and html
|
||||
# parsing the html with nokogiri will remove the links as well
|
||||
# might also remove tags like b,li etc. so lets rethink about this later
|
||||
# format.text { Nokogiri::HTML(render(layout: false)).text }
|
||||
format.html { render }
|
||||
end
|
||||
end
|
||||
|
||||
def liquid_droppables
|
||||
# Merge additional objects into this in your mailer
|
||||
# liquid template handler converts these objects into drop objects
|
||||
{
|
||||
account: Current.account
|
||||
}
|
||||
end
|
||||
|
||||
def liquid_locals
|
||||
# expose variables you want to be exposed in liquid
|
||||
{
|
||||
global_config: GlobalConfig.get('INSTALLATION_NAME', 'BRAND_URL'),
|
||||
action_url: @action_url
|
||||
}
|
||||
end
|
||||
|
||||
def ensure_current_account(account)
|
||||
Current.account = account if account.present?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -105,6 +105,6 @@ class ConversationReplyMailer < ApplicationMailer
|
||||
def choose_layout
|
||||
return false if action_name == 'reply_without_summary'
|
||||
|
||||
'mailer'
|
||||
'mailer/base'
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user