diff --git a/app/javascript/dashboard/routes/dashboard/conversation/Macros/MacroPreview.vue b/app/javascript/dashboard/routes/dashboard/conversation/Macros/MacroPreview.vue index bf7d09cbd..4893ea7ad 100644 --- a/app/javascript/dashboard/routes/dashboard/conversation/Macros/MacroPreview.vue +++ b/app/javascript/dashboard/routes/dashboard/conversation/Macros/MacroPreview.vue @@ -53,6 +53,7 @@ export default { send_webhook_event: params[0], send_message: params[0], send_email_transcript: params[0], + add_private_note: params[0], }; return actionsMap[key] || ''; }, diff --git a/app/javascript/dashboard/routes/dashboard/settings/macros/constants.js b/app/javascript/dashboard/routes/dashboard/settings/macros/constants.js index d0638d414..9b37b92c3 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/macros/constants.js +++ b/app/javascript/dashboard/routes/dashboard/settings/macros/constants.js @@ -39,4 +39,9 @@ export const MACRO_ACTION_TYPES = [ label: 'Send a message', inputType: 'textarea', }, + { + key: 'add_private_note', + label: 'Add a private note', + inputType: 'textarea', + }, ]; diff --git a/app/models/macro.rb b/app/models/macro.rb index 188c98ab7..16affee09 100644 --- a/app/models/macro.rb +++ b/app/models/macro.rb @@ -33,7 +33,7 @@ class Macro < ApplicationRecord validate :json_actions_format ACTIONS_ATTRS = %w[send_message add_label assign_team assign_best_agent mute_conversation change_status - resolve_conversation snooze_conversation send_email_transcript send_attachment].freeze + resolve_conversation snooze_conversation send_email_transcript send_attachment add_private_note].freeze def set_visibility(user, params) self.visibility = params[:visibility] diff --git a/app/services/macros/execution_service.rb b/app/services/macros/execution_service.rb index 72b0a8a72..4610500ab 100644 --- a/app/services/macros/execution_service.rb +++ b/app/services/macros/execution_service.rb @@ -22,6 +22,16 @@ class Macros::ExecutionService < ActionService private + def add_private_note(message) + return if conversation_a_tweet? + + params = { content: message[0], private: true } + + # Added reload here to ensure conversation us persistent with the latest updates + mb = Messages::MessageBuilder.new(@user, @conversation.reload, params) + mb.perform + end + def send_message(message) return if conversation_a_tweet? diff --git a/spec/controllers/api/v1/accounts/macros_controller_spec.rb b/spec/controllers/api/v1/accounts/macros_controller_spec.rb index 46d932670..c34cf3a86 100644 --- a/spec/controllers/api/v1/accounts/macros_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/macros_controller_spec.rb @@ -234,7 +234,8 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do { 'action_name' => 'add_label', 'action_params' => %w[support priority_customer] }, { 'action_name' => 'snooze_conversation' }, { 'action_name' => 'assign_best_agent', 'action_params' => [user_1.id] }, - { 'action_name' => 'send_message', 'action_params' => ['Send this message.'] } + { 'action_name' => 'send_message', 'action_params' => ['Send this message.'] }, + { 'action_name' => 'add_private_note', 'action_params': ['We are sending greeting message to customer.'] } ]) end @@ -296,6 +297,20 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do expect(conversation.reload.status).to eql('snoozed') end + + it 'Adds the private note' do + expect(conversation.messages).to be_empty + + perform_enqueued_jobs do + post "/api/v1/accounts/#{account.id}/macros/#{macro.id}/execute", + params: { conversation_ids: [conversation.display_id] }, + headers: administrator.create_new_auth_token + end + + expect(conversation.messages.last.content).to eq('We are sending greeting message to customer.') + expect(conversation.messages.last.sender).to eq(administrator) + expect(conversation.messages.last.private).to be_truthy + end end end end