feat: allow auto resolve waiting option (#11436)

This commit is contained in:
Shivam Mishra
2025-05-08 12:52:17 +05:30
committed by GitHub
parent bfddc4da24
commit c87b2109a9
10 changed files with 92 additions and 27 deletions

View File

@@ -34,10 +34,11 @@ class Account < ApplicationRecord
'properties':
{
'auto_resolve_after': { 'type': %w[integer null], 'minimum': 10, 'maximum': 1_439_856 },
'auto_resolve_message': { 'type': %w[string null] }
'auto_resolve_message': { 'type': %w[string null] },
'auto_resolve_ignore_waiting': { 'type': %w[boolean null] }
},
'required': [],
'additionalProperties': false
'additionalProperties': true
}.to_json.freeze
DEFAULT_QUERY_SETTING = {
@@ -50,7 +51,7 @@ class Account < ApplicationRecord
schema: SETTINGS_PARAMS_SCHEMA,
attribute_resolver: ->(record) { record.settings }
store_accessor :settings, :auto_resolve_after, :auto_resolve_message
store_accessor :settings, :auto_resolve_after, :auto_resolve_message, :auto_resolve_ignore_waiting
has_many :account_users, dependent: :destroy_async
has_many :agent_bot_inboxes, dependent: :destroy_async

View File

@@ -76,11 +76,16 @@ class Conversation < ApplicationRecord
scope :assigned, -> { where.not(assignee_id: nil) }
scope :assigned_to, ->(agent) { where(assignee_id: agent.id) }
scope :unattended, -> { where(first_reply_created_at: nil).or(where.not(waiting_since: nil)) }
scope :resolvable, lambda { |auto_resolve_after|
scope :resolvable_not_waiting, lambda { |auto_resolve_after|
return none if auto_resolve_after.to_i.zero?
open.where('last_activity_at < ? AND waiting_since IS NULL', Time.now.utc - auto_resolve_after.minutes)
}
scope :resolvable_all, lambda { |auto_resolve_after|
return none if auto_resolve_after.to_i.zero?
open.where('last_activity_at < ?', Time.now.utc - auto_resolve_after.minutes)
}
scope :last_user_message_at, lambda {
joins(