2020-01-09 07:36:40 +00:00
|
|
|
class MessageTemplates::Template::EmailCollect
|
|
|
|
pattr_initialize [:conversation!]
|
|
|
|
|
|
|
|
def perform
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
conversation.messages.create!(ways_to_reach_you_message_params)
|
|
|
|
conversation.messages.create!(email_input_box_template_message_params)
|
|
|
|
end
|
|
|
|
rescue StandardError => e
|
2022-05-09 08:53:19 +00:00
|
|
|
ChatwootExceptionTracker.new(e, account: conversation.account).capture_exception
|
2020-01-09 07:36:40 +00:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
delegate :contact, :account, to: :conversation
|
|
|
|
delegate :inbox, to: :message
|
|
|
|
|
|
|
|
def ways_to_reach_you_message_params
|
|
|
|
content = I18n.t('conversations.templates.ways_to_reach_you_message_body',
|
|
|
|
account_name: account.name)
|
|
|
|
|
|
|
|
{
|
|
|
|
account_id: @conversation.account_id,
|
|
|
|
inbox_id: @conversation.inbox_id,
|
|
|
|
message_type: :template,
|
|
|
|
content: content
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def email_input_box_template_message_params
|
|
|
|
content = I18n.t('conversations.templates.email_input_box_message_body',
|
|
|
|
account_name: account.name)
|
|
|
|
|
|
|
|
{
|
|
|
|
account_id: @conversation.account_id,
|
|
|
|
inbox_id: @conversation.inbox_id,
|
|
|
|
message_type: :template,
|
|
|
|
content_type: :input_email,
|
|
|
|
content: content
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|