feat: Execute macro actions, for the conversation (#5066)
This commit is contained in:
38
app/services/macros/execution_service.rb
Normal file
38
app/services/macros/execution_service.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
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
|
||||
Reference in New Issue
Block a user