Chatwoot/app/services/macros/execution_service.rb

38 lines
1,010 B
Ruby

class Macros::ExecutionService < ActionService
def initialize(macro, conversation, user)
super(conversation)
@macro = macro
@account = macro.account
Current.user = user
end
def perform
@macro.actions.each do |action|
action = action.with_indifferent_access
begin
send(action[:action_name], action[:action_params])
rescue StandardError => e
ChatwootExceptionTracker.new(e, account: @account).capture_exception
end
end
ensure
Current.reset
end
private
def send_webhook_event(webhook_url)
payload = @conversation.webhook_data.merge(event: "macro_event.#{@macro.name}")
WebhookJob.perform_later(webhook_url[0], payload)
end
def send_message(message)
return if conversation_a_tweet?
params = { content: message[0], private: false, content_attributes: { macro_id: @macro.id } }
mb = Messages::MessageBuilder.new(nil, @conversation, params)
mb.perform
end
def send_email_to_team(_params); end
end