cb22b396eb
Add SDK functions Co-authored-by: Sojan <sojan@pepalo.com>
26 lines
675 B
Ruby
26 lines
675 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?
|
|
!contact_has_email? && conversation.inbox.web_widget? && first_message_from_contact?
|
|
end
|
|
|
|
def contact_has_email?
|
|
contact.email
|
|
end
|
|
end
|