feat: Save automation rules (#3359)
This commit is contained in:
@@ -69,6 +69,7 @@ class Account < ApplicationRecord
|
||||
has_many :webhooks, dependent: :destroy_async
|
||||
has_many :whatsapp_channels, dependent: :destroy_async, class_name: '::Channel::Whatsapp'
|
||||
has_many :working_hours, dependent: :destroy_async
|
||||
has_many :automation_rules, dependent: :destroy
|
||||
|
||||
has_flags ACCOUNT_SETTINGS_FLAGS.merge(column: 'settings_flags').merge(DEFAULT_QUERY_SETTING)
|
||||
|
||||
|
||||
44
app/models/automation_rule.rb
Normal file
44
app/models/automation_rule.rb
Normal file
@@ -0,0 +1,44 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: automation_rules
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# actions :jsonb not null
|
||||
# conditions :jsonb not null
|
||||
# description :text
|
||||
# event_name :string not null
|
||||
# name :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_automation_rules_on_account_id (account_id)
|
||||
#
|
||||
class AutomationRule < ApplicationRecord
|
||||
belongs_to :account
|
||||
|
||||
validates :account, presence: true
|
||||
validate :json_conditions_format
|
||||
validate :json_actions_format
|
||||
|
||||
CONDITIONS_ATTRS = %w[country_code status browser_language assignee_id team_id referer].freeze
|
||||
ACTIONS_ATTRS = %w[send_message add_label send_email_to_team assign_team assign_best_agents].freeze
|
||||
|
||||
private
|
||||
|
||||
def json_conditions_format
|
||||
return if conditions.nil?
|
||||
|
||||
attributes = conditions.map { |obj, _| obj['attribute_key'] }
|
||||
(attributes - CONDITIONS_ATTRS).blank?
|
||||
end
|
||||
|
||||
def json_actions_format
|
||||
return if actions.nil?
|
||||
|
||||
attributes = actions.map { |obj, _| obj['attribute_key'] }
|
||||
(attributes - ACTIONS_ATTRS).blank?
|
||||
end
|
||||
end
|
||||
@@ -8,4 +8,9 @@ module Labelable
|
||||
def update_labels(labels = nil)
|
||||
update!(label_list: labels)
|
||||
end
|
||||
|
||||
def add_labels(new_labels = nil)
|
||||
new_labels << labels
|
||||
update!(label_list: new_labels)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user