Files
chatwoot/app/services/automation_rules/action_service.rb
Sojan Jose 45d4d3660c feat: Add private note action to automations (#11926)
## Summary
- allow AutomationRule to accept `add_private_note` action
- support `add_private_note` in automation action service
- expose private note action in frontend constants and i18n
- test new automation rule action

## Testing
- `pnpm eslint
app/javascript/dashboard/routes/dashboard/settings/automation/constants.js`
- `bundle exec rubocop app/services/automation_rules/action_service.rb
app/models/automation_rule.rb
spec/services/automation_rules/action_service_spec.rb`
- `bundle exec rspec
spec/services/automation_rules/action_service_spec.rb`


------
https://chatgpt.com/codex/tasks/task_e_6870c5f7b8b88326a9bd60b2ba710ccd

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
2025-07-16 09:57:35 +05:30

65 lines
1.8 KiB
Ruby

class AutomationRules::ActionService < ActionService
def initialize(rule, account, conversation)
super(conversation)
@rule = rule
@account = account
Current.executed_by = rule
end
def perform
@rule.actions.each do |action|
@conversation.reload
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_attachment(blob_ids)
return if conversation_a_tweet?
return unless @rule.files.attached?
blobs = ActiveStorage::Blob.where(id: blob_ids)
return if blobs.blank?
params = { content: nil, private: false, attachments: blobs }
Messages::MessageBuilder.new(nil, @conversation, params).perform
end
def send_webhook_event(webhook_url)
payload = @conversation.webhook_data.merge(event: "automation_event.#{@rule.event_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: { automation_rule_id: @rule.id } }
Messages::MessageBuilder.new(nil, @conversation, params).perform
end
def add_private_note(message)
return if conversation_a_tweet?
params = { content: message[0], private: true, content_attributes: { automation_rule_id: @rule.id } }
Messages::MessageBuilder.new(nil, @conversation.reload, params).perform
end
def send_email_to_team(params)
teams = Team.where(id: params[0][:team_ids])
teams.each do |team|
TeamNotifications::AutomationNotificationMailer.conversation_creation(@conversation, team, params[0][:message])&.deliver_now
end
end
end