Skip to content

Commit

Permalink
feat: Add an action on automation to change the priority (#6925)
Browse files Browse the repository at this point in the history
  • Loading branch information
muhsin-k committed Apr 20, 2023
1 parent 527042a commit d1584ee
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
24 changes: 24 additions & 0 deletions app/javascript/dashboard/helper/automationHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,9 @@ export const AUTOMATION_ACTION_TYPES = [
label: 'Send a message',
inputType: 'textarea',
},
{
key: 'change_priority',
label: 'Change Priority',
inputType: 'search_select',
},
];
2 changes: 1 addition & 1 deletion app/models/automation_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
4 changes: 4 additions & 0 deletions app/services/action_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def change_status(status)
@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?

Expand Down
16 changes: 16 additions & 0 deletions spec/services/action_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,21 @@
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

0 comments on commit d1584ee

Please sign in to comment.