Chatwoot/app/services/message_templates/template/greeting.rb
Sojan Jose ab54d9c629
chore: Upgrade rails and ruby versions (#2400)
ruby version: 3.0.2
rails version: 6.1.4
2021-08-03 20:11:52 +05:30

28 lines
613 B
Ruby

class MessageTemplates::Template::Greeting
pattr_initialize [:conversation!]
def perform
ActiveRecord::Base.transaction do
conversation.messages.create!(greeting_message_params)
end
rescue StandardError => e
Sentry.capture_exception(e)
true
end
private
delegate :contact, :account, to: :conversation
delegate :inbox, to: :message
def greeting_message_params
content = @conversation.inbox&.greeting_message
{
account_id: @conversation.account_id,
inbox_id: @conversation.inbox_id,
message_type: :template,
content: content
}
end
end