Co-authored-by: aakashb95 <aakash@chatwoot.com> Co-authored-by: Shivam Mishra <scm.mymail@gmail.com> Co-authored-by: Vishnu Narayanan <iamwishnu@gmail.com>
37 lines
902 B
Ruby
37 lines
902 B
Ruby
class MessageTemplates::Template::OutOfOffice
|
|
pattr_initialize [:conversation!]
|
|
|
|
def self.perform_if_applicable(conversation)
|
|
inbox = conversation.inbox
|
|
return unless inbox.out_of_office?
|
|
return if inbox.out_of_office_message.blank?
|
|
|
|
new(conversation: conversation).perform
|
|
end
|
|
|
|
def perform
|
|
ActiveRecord::Base.transaction do
|
|
conversation.messages.create!(out_of_office_message_params)
|
|
end
|
|
rescue StandardError => e
|
|
ChatwootExceptionTracker.new(e, account: conversation.account).capture_exception
|
|
true
|
|
end
|
|
|
|
private
|
|
|
|
delegate :contact, :account, to: :conversation
|
|
delegate :inbox, to: :message
|
|
|
|
def out_of_office_message_params
|
|
content = @conversation.inbox&.out_of_office_message
|
|
|
|
{
|
|
account_id: @conversation.account_id,
|
|
inbox_id: @conversation.inbox_id,
|
|
message_type: :template,
|
|
content: content
|
|
}
|
|
end
|
|
end
|