Chatwoot/app/services/message_templates/hook_execution_service.rb
Pranav Raj S b2d5cc7b05
Feature: Introduce bots (#545)
Co-authored-by: Pranav Raj S <pranavrajs@gmail.com>
Co-authored-by: Sojan Jose <sojan@pepalo.com>
2020-03-06 01:43:12 +05:30

22 lines
602 B
Ruby

class MessageTemplates::HookExecutionService
pattr_initialize [:message!]
def perform
return if inbox.agent_bot_inbox&.active?
::MessageTemplates::Template::EmailCollect.new(conversation: conversation).perform if should_send_email_collect?
end
private
delegate :inbox, :conversation, to: :message
delegate :contact, to: :conversation
def first_message_from_contact?
conversation.messages.outgoing.count.zero? && conversation.messages.template.count.zero?
end
def should_send_email_collect?
conversation.inbox.web_widget? && first_message_from_contact?
end
end