diff --git a/app/javascript/dashboard/helper/automationHelper.js b/app/javascript/dashboard/helper/automationHelper.js index 581d539bc..dc26177ff 100644 --- a/app/javascript/dashboard/helper/automationHelper.js +++ b/app/javascript/dashboard/helper/automationHelper.js @@ -16,6 +16,29 @@ const MESSAGE_CONDITION_VALUES = [ }, ]; +export const PRIORITY_CONDITION_VALUES = [ + { + id: 'nil', + name: 'None', + }, + { + id: 'low', + name: 'Low', + }, + { + id: 'medium', + name: 'Medium', + }, + { + id: 'high', + name: 'High', + }, + { + id: 'urgent', + name: 'Urgent', + }, +]; + export const getCustomAttributeInputType = key => { const customAttributeMap = { date: 'date', @@ -103,6 +126,7 @@ export const getActionOptions = ({ agents, teams, labels, type }) => { assign_team: teams, send_email_to_team: teams, add_label: generateConditionOptions(labels, 'title'), + change_priority: PRIORITY_CONDITION_VALUES, }; return actionsMap[type]; }; diff --git a/app/javascript/dashboard/routes/dashboard/settings/automation/constants.js b/app/javascript/dashboard/routes/dashboard/settings/automation/constants.js index f052be66d..4c19970d8 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/automation/constants.js +++ b/app/javascript/dashboard/routes/dashboard/settings/automation/constants.js @@ -575,4 +575,9 @@ export const AUTOMATION_ACTION_TYPES = [ label: 'Send a message', inputType: 'textarea', }, + { + key: 'change_priority', + label: 'Change Priority', + inputType: 'search_select', + }, ]; diff --git a/app/models/automation_rule.rb b/app/models/automation_rule.rb index 9342bc883..0628a8b7e 100644 --- a/app/models/automation_rule.rb +++ b/app/models/automation_rule.rb @@ -33,7 +33,7 @@ class AutomationRule < ApplicationRecord CONDITIONS_ATTRS = %w[content email country_code status message_type browser_language assignee_id team_id referer city company inbox_id mail_subject phone_number conversation_language].freeze ACTIONS_ATTRS = %w[send_message add_label send_email_to_team assign_team assign_agent send_webhook_event mute_conversation send_attachment - change_status resolve_conversation snooze_conversation send_email_transcript].freeze + change_status resolve_conversation snooze_conversation change_priority send_email_transcript].freeze def file_base_data files.map do |file| diff --git a/app/services/action_service.rb b/app/services/action_service.rb index 77f3c6b9a..6e8a3b8ca 100644 --- a/app/services/action_service.rb +++ b/app/services/action_service.rb @@ -19,6 +19,10 @@ class ActionService @conversation.update!(status: status[0]) end + def change_priority(priority) + @conversation.update!(priority: (priority[0] == 'nil' ? nil : priority[0])) + end + def add_label(labels) return if labels.empty? diff --git a/spec/services/action_service_spec.rb b/spec/services/action_service_spec.rb index 490873592..8cade58a6 100644 --- a/spec/services/action_service_spec.rb +++ b/spec/services/action_service_spec.rb @@ -11,5 +11,21 @@ describe ::ActionService do expect(conversation.reload.status).to eq('resolved') end end + + describe '#change_priority' do + let(:conversation) { create(:conversation) } + let(:action_service) { described_class.new(conversation) } + + it 'changes the priority of the conversation to medium' do + action_service.change_priority(['medium']) + expect(conversation.reload.priority).to eq('medium') + end + + it 'changes the priority of the conversation to nil' do + action_service.change_priority(['nil']) + expect(conversation.reload.priority).to be_nil + end + end + # TODO: Expand this test suite end