feat: Execute macro actions, for the conversation (#5066)
This commit is contained in:
@@ -30,7 +30,8 @@ class AutomationRule < ApplicationRecord
|
||||
scope :active, -> { where(active: true) }
|
||||
|
||||
CONDITIONS_ATTRS = %w[content email country_code status message_type browser_language assignee_id team_id referer city company inbox_id].freeze
|
||||
ACTIONS_ATTRS = %w[send_message add_label send_email_to_team assign_team assign_best_agents send_attachment].freeze
|
||||
ACTIONS_ATTRS = %w[send_message add_label send_email_to_team assign_team assign_best_agent send_webhook_event mute_conversation send_attachment
|
||||
change_status resolve_conversation snooze_conversation send_email_transcript].freeze
|
||||
|
||||
def file_base_data
|
||||
files.map do |file|
|
||||
@@ -49,7 +50,7 @@ class AutomationRule < ApplicationRecord
|
||||
private
|
||||
|
||||
def json_conditions_format
|
||||
return if conditions.nil?
|
||||
return if conditions.blank?
|
||||
|
||||
attributes = conditions.map { |obj, _| obj['attribute_key'] }
|
||||
conditions = attributes - CONDITIONS_ATTRS
|
||||
@@ -58,9 +59,9 @@ class AutomationRule < ApplicationRecord
|
||||
end
|
||||
|
||||
def json_actions_format
|
||||
return if actions.nil?
|
||||
return if actions.blank?
|
||||
|
||||
attributes = actions.map { |obj, _| obj['attribute_key'] }
|
||||
attributes = actions.map { |obj, _| obj['action_name'] }
|
||||
actions = attributes - ACTIONS_ATTRS
|
||||
|
||||
errors.add(:actions, "Automation actions #{actions.join(',')} not supported.") if actions.any?
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# id :bigint not null, primary key
|
||||
# actions :jsonb not null
|
||||
# name :string not null
|
||||
# visibility :integer default("user")
|
||||
# visibility :integer default("personal")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint not null
|
||||
@@ -31,6 +31,11 @@ class Macro < ApplicationRecord
|
||||
class_name: :User
|
||||
enum visibility: { personal: 0, global: 1 }
|
||||
|
||||
validate :json_actions_format
|
||||
|
||||
ACTIONS_ATTRS = %w[send_message add_label send_email_to_team assign_team assign_best_agent send_webhook_event mute_conversation change_status
|
||||
resolve_conversation snooze_conversation].freeze
|
||||
|
||||
def set_visibility(user, params)
|
||||
self.visibility = params[:visibility]
|
||||
self.visibility = :personal if user.agent?
|
||||
@@ -46,4 +51,15 @@ class Macro < ApplicationRecord
|
||||
def self.current_page(params)
|
||||
params[:page] || 1
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def json_actions_format
|
||||
return if actions.blank?
|
||||
|
||||
attributes = actions.map { |obj, _| obj['action_name'] }
|
||||
actions = attributes - ACTIONS_ATTRS
|
||||
|
||||
errors.add(:actions, "Macro execution actions #{actions.join(',')} not supported.") if actions.any?
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user