@@ -4,8 +4,8 @@ class MessageTemplates::HookExecutionService
|
||||
def perform
|
||||
return if inbox.agent_bot_inbox&.active?
|
||||
|
||||
::MessageTemplates::Template::OutOfOffice.new(conversation: conversation).perform if should_send_out_of_office_message?
|
||||
::MessageTemplates::Template::Greeting.new(conversation: conversation).perform if should_send_greeting?
|
||||
|
||||
::MessageTemplates::Template::EmailCollect.new(conversation: conversation).perform if should_send_email_collect?
|
||||
end
|
||||
|
||||
@@ -14,12 +14,16 @@ class MessageTemplates::HookExecutionService
|
||||
delegate :inbox, :conversation, to: :message
|
||||
delegate :contact, to: :conversation
|
||||
|
||||
def should_send_out_of_office_message?
|
||||
inbox.out_of_office? && conversation.messages.today.template.empty? && inbox.out_of_office_message.present?
|
||||
end
|
||||
|
||||
def first_message_from_contact?
|
||||
conversation.messages.outgoing.count.zero? && conversation.messages.template.count.zero?
|
||||
end
|
||||
|
||||
def should_send_greeting?
|
||||
first_message_from_contact? && conversation.inbox.greeting_enabled? && conversation.inbox.greeting_message.present?
|
||||
first_message_from_contact? && inbox.greeting_enabled? && inbox.greeting_message.present?
|
||||
end
|
||||
|
||||
def email_collect_was_sent?
|
||||
@@ -27,7 +31,7 @@ class MessageTemplates::HookExecutionService
|
||||
end
|
||||
|
||||
def should_send_email_collect?
|
||||
!contact_has_email? && conversation.inbox.web_widget? && !email_collect_was_sent?
|
||||
!contact_has_email? && inbox.web_widget? && !email_collect_was_sent?
|
||||
end
|
||||
|
||||
def contact_has_email?
|
||||
|
||||
28
app/services/message_templates/template/out_of_office.rb
Normal file
28
app/services/message_templates/template/out_of_office.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
class MessageTemplates::Template::OutOfOffice
|
||||
pattr_initialize [:conversation!]
|
||||
|
||||
def perform
|
||||
ActiveRecord::Base.transaction do
|
||||
conversation.messages.create!(out_of_office_message_params)
|
||||
end
|
||||
rescue StandardError => e
|
||||
Raven.capture_exception(e)
|
||||
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
|
||||
Reference in New Issue
Block a user