diff --git a/config/locales/en.yml b/config/locales/en.yml index 3cc8eb9cf..3d85be498 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -214,6 +214,7 @@ en: activity: captain: resolved: 'Conversation was marked resolved by %{user_name} due to inactivity' + tool_resolved: 'Conversation was resolved by %{user_name}' open: 'Conversation was marked open by %{user_name}' agent_bot: error_moved_to_open: 'Conversation was marked open by system due to an error with the agent bot.' diff --git a/enterprise/app/models/enterprise/activity_message_handler.rb b/enterprise/app/models/enterprise/activity_message_handler.rb index e6a93718f..88a6b640a 100644 --- a/enterprise/app/models/enterprise/activity_message_handler.rb +++ b/enterprise/app/models/enterprise/activity_message_handler.rb @@ -1,22 +1,21 @@ module Enterprise::ActivityMessageHandler def automation_status_change_activity_content - if Current.executed_by.instance_of?(Captain::Assistant) - locale = Current.executed_by.account.locale - if resolved? - I18n.t( - 'conversations.activity.captain.resolved', - user_name: Current.executed_by.name, - locale: locale - ) - elsif open? - I18n.t( - 'conversations.activity.captain.open', - user_name: Current.executed_by.name, - locale: locale - ) - end - else - super - end + return super unless Current.executed_by.instance_of?(Captain::Assistant) + return unless resolved? || open? + + locale = Current.executed_by.account.locale + user_name = Current.executed_by.name + key = captain_activity_key + + I18n.t(key, user_name: user_name, locale: locale) + end + + private + + def captain_activity_key + return 'conversations.activity.captain.open' if open? + return 'conversations.activity.captain.tool_resolved' if Current.tool_name == 'resolve' + + 'conversations.activity.captain.resolved' end end diff --git a/enterprise/lib/captain/tools/resolve_tool.rb b/enterprise/lib/captain/tools/resolve_tool.rb index 00ca96e5c..9c362af94 100644 --- a/enterprise/lib/captain/tools/resolve_tool.rb +++ b/enterprise/lib/captain/tools/resolve_tool.rb @@ -37,7 +37,10 @@ class Captain::Tools::ResolveTool < Captain::Tools::BasePublicTool end # Mark conversation as resolved + Current.tool_name = 'resolve' conversation.resolved! + ensure + Current.tool_name = nil end def permissions diff --git a/lib/current.rb b/lib/current.rb index 3376099f8..e06faa1ac 100644 --- a/lib/current.rb +++ b/lib/current.rb @@ -4,6 +4,7 @@ module Current thread_mattr_accessor :account_user thread_mattr_accessor :executed_by thread_mattr_accessor :contact + thread_mattr_accessor :tool_name def self.reset Current.user = nil @@ -11,5 +12,6 @@ module Current Current.account_user = nil Current.executed_by = nil Current.contact = nil + Current.tool_name = nil end end