Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬
Ruby actioncablechat-widgetconversationcustomer-supportdashboarddesigndockerdocker-imageherokuintercomjavascriptlivechatopensourcerailsrubysassvuejswhatsappzendesk
feat: configurable auto-resolve minimum and schedule (#16182)
Vishnu Narayanan5c2b3f78bd3f
diff --git a/.env.example b/.env.exampleindex 834e7a5277d..c0f3eb567e0 100644--- a/.env.example+++ b/.env.example@@ -212,6 +212,12 @@ GOOGLE_OAUTH_CLIENT_ID=GOOGLE_OAUTH_CLIENT_SECRET=GOOGLE_OAUTH_CALLBACK_URL=+## Auto resolve+# Minimum inactivity, in minutes, an account can set for auto resolve. Defaults to 10.+# AUTO_RESOLVE_MIN_MINUTES=10+# Cron schedule for the auto resolve job. Defaults to every 5 minutes.+# AUTO_RESOLVE_CRON=*/5 * * * *+### Change this env variable only if you are using a custom build mobile app## Mobile app env variablesIOS_APP_ID=L7YLMN4634.com.chatwoot.appdiff --git a/app/javascript/dashboard/i18n/locale/en/generalSettings.json b/app/javascript/dashboard/i18n/locale/en/generalSettings.jsonindex e96dc2a5e44..5e483a8b76d 100644--- a/app/javascript/dashboard/i18n/locale/en/generalSettings.json+++ b/app/javascript/dashboard/i18n/locale/en/generalSettings.json@@ -80,7 +80,7 @@"LABEL": "Inactivity duration","HELP": "Time period of inactivity after which conversation is auto-resolved","PLACEHOLDER": "30",- "ERROR": "Auto resolve duration should be between 10 minutes and 999 days",+ "ERROR": "Auto resolve duration should be between {minDuration} minutes and 999 days","API": {"SUCCESS": "Auto resolve settings updated successfully","ERROR": "Failed to update auto resolve settings"diff --git a/app/javascript/dashboard/routes/dashboard/settings/account/components/AutoResolve.vue b/app/javascript/dashboard/routes/dashboard/settings/account/components/AutoResolve.vueindex 54eafa59ea3..50a38293c6e 100644--- a/app/javascript/dashboard/routes/dashboard/settings/account/components/AutoResolve.vue+++ b/app/javascript/dashboard/routes/dashboard/settings/account/components/AutoResolve.vue@@ -13,6 +13,7 @@ import SingleSelect from 'dashboard/components-next/filter/inputs/SingleSelect.vimport { DURATION_UNITS } from 'dashboard/components-next/input/constants';const { t } = useI18n();+const minDuration = window.chatwootConfig?.autoResolveMinMinutes || 10;const duration = ref(0);const unit = ref(DURATION_UNITS.MINUTES);const message = ref('');@@ -93,8 +94,10 @@ const updateAccountSettings = async settings => {};const handleSubmit = async () => {- if (duration.value < 10) {- useAlert(t('GENERAL_SETTINGS.FORM.AUTO_RESOLVE.DURATION.ERROR'));+ if (duration.value < minDuration) {+ useAlert(+ t('GENERAL_SETTINGS.FORM.AUTO_RESOLVE.DURATION.ERROR', { minDuration })+ );return Promise.resolve();}diff --git a/app/jobs/trigger_scheduled_items_job.rb b/app/jobs/trigger_scheduled_items_job.rbindex 5b38ccc870a..3929df9a3da 100644--- a/app/jobs/trigger_scheduled_items_job.rb+++ b/app/jobs/trigger_scheduled_items_job.rb@@ -14,9 +14,6 @@ class TriggerScheduledItemsJob < ApplicationJob# Job to reopen snoozed notificationsNotification::ReopenSnoozedNotificationsJob.perform_later- # Job to auto-resolve conversations- Account::ConversationsResolutionSchedulerJob.perform_later-# Job to sync whatsapp templatesChannels::Whatsapp::TemplatesSyncSchedulerJob.perform_laterdiff --git a/app/models/account.rb b/app/models/account.rbindex 6fad5a0af7a..5781d70ea20 100644--- a/app/models/account.rb+++ b/app/models/account.rb@@ -49,6 +49,8 @@ class Account < ApplicationRecordvalidates_with JsonSchemaValidator,schema: SETTINGS_PARAMS_SCHEMA,attribute_resolver: ->(record) { record.settings }+ validates :auto_resolve_after, numericality: { greater_than_or_equal_to: ->(_account) { Limits.auto_resolve_min_minutes } },+ allow_nil: true, if: :auto_resolve_after_changed?validate :validate_reporting_timezonevalidate :validate_support_email_format, if: :will_save_change_to_support_email?diff --git a/app/models/concerns/account_settings_schema.rb b/app/models/concerns/account_settings_schema.rbindex da2cfe3609e..1696a2b0ba8 100644--- a/app/models/concerns/account_settings_schema.rb+++ b/app/models/concerns/account_settings_schema.rb@@ -8,7 +8,7 @@ module AccountSettingsSchema'type': 'object','properties':{- 'auto_resolve_after': { 'type': %w[integer null], 'minimum': 10, 'maximum': 1_439_856 },+ 'auto_resolve_after': { 'type': %w[integer null], 'maximum': 1_439_856 },'auto_resolve_message': { 'type': %w[string null] },'auto_resolve_ignore_waiting': { 'type': %w[boolean null] },'audio_transcriptions': { 'type': %w[boolean null] },diff --git a/app/views/layouts/vueapp.html.erb b/app/views/layouts/vueapp.html.erbindex 24692813b94..75f75660748 100644--- a/app/views/layouts/vueapp.html.erb+++ b/app/views/layouts/vueapp.html.erb@@ -60,6 +60,7 @@helpUrls: <%= feature_help_urls.to_json.html_safe %>,inboxEventsEnabled: '<%= ENV['ENABLE_INBOX_EVENTS'].present? %>',searchTimeRangeLimitDays: <%= Limits.search_time_range_limit_days %>,+ autoResolveMinMinutes: <%= Limits.auto_resolve_min_minutes %>,selectedLocale: '<%= I18n.locale %>'}window.globalConfig = <%= raw @global_config.to_json %>diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rbindex 0cd9bf72c66..7f4fe59608c 100644--- a/config/initializers/sidekiq.rb+++ b/config/initializers/sidekiq.rb@@ -76,7 +76,8 @@ Rails.application.reloader.to_prepare do# jobs that share the same source tag but are no longer in the file.# This ensures deleted schedule entries are cleaned up on deploy.if File.exist?(schedule_file) && Sidekiq.server?- schedule = YAML.load_file(schedule_file)+ # Parsed the same way as sidekiq-cron's own startup loader, which reloads this file after us+ schedule = Sidekiq::Cron::Support.load_yaml(ERB.new(File.read(schedule_file)).result)# Cron entries removed from schedule.yml but possibly still in Redis# with source:'dynamic' (predating the source tag). load_from_hash!@@ -84,6 +85,7 @@ Rails.application.reloader.to_prepare do# Remove names from this list once they've been through a deploy cycle.%w[bulk_auto_assignment_job].each { |name| Sidekiq::Cron::Job.destroy(name) }- Sidekiq::Cron::Job.load_from_hash!(schedule, source: 'schedule')+ errors = Sidekiq::Cron::Job.load_from_hash!(schedule, source: 'schedule')+ Sidekiq.logger.error("Invalid cron schedule entries: #{errors}") if errors.present?endenddiff --git a/config/schedule.yml b/config/schedule.ymlindex 65b38cf2eb6..424c6b9ccc8 100644--- a/config/schedule.yml+++ b/config/schedule.yml@@ -19,6 +19,12 @@ trigger_scheduled_items_job:class: 'TriggerScheduledItemsJob'queue: scheduled_jobs+# executed At every 5th minute by default, AUTO_RESOLVE_CRON overrides it+trigger_conversations_resolution_job:+ cron: <%= ENV.fetch('AUTO_RESOLVE_CRON', '*/5 * * * *').to_json %>+ class: 'Account::ConversationsResolutionSchedulerJob'+ queue: scheduled_jobs+# executed hourly for scheduled jobs that do not need minute-level cadencetrigger_hourly_scheduled_items_job:cron: '0 * * * *'diff --git a/lib/limits.rb b/lib/limits.rbindex 85d406ce838..cc326b0beae 100644--- a/lib/limits.rb+++ b/lib/limits.rb@@ -18,4 +18,9 @@ module Limitsdays = ENV.fetch('SEARCH_TIME_RANGE_LIMIT_DAYS', '90').to_idays.positive? ? days : 90end++ def self.auto_resolve_min_minutes+ minutes = ENV.fetch('AUTO_RESOLVE_MIN_MINUTES', '10').to_i+ minutes.positive? ? minutes : 10+ endenddiff --git a/spec/configs/schedule_spec.rb b/spec/configs/schedule_spec.rbindex 29b4e93993c..9db023ecf67 100644--- a/spec/configs/schedule_spec.rb+++ b/spec/configs/schedule_spec.rb@@ -21,4 +21,21 @@ RSpec.context 'with valid schedule.yml' do# ensure that no duplicates existexpect(schedule_keys.count).to eq(schedule_keys.uniq.count)end++ describe 'auto resolve schedule' do+ def resolution_cron+ schedule = Sidekiq::Cron::Support.load_yaml(ERB.new(Rails.root.join('config/schedule.yml').read).result)+ schedule['trigger_conversations_resolution_job']['cron']+ end++ it 'runs every 5 minutes by default' do+ expect(resolution_cron).to eq('*/5 * * * *')+ end++ it 'uses AUTO_RESOLVE_CRON when set' do+ with_modified_env AUTO_RESOLVE_CRON: '* * * * *' do+ expect(resolution_cron).to eq('* * * * *')+ end+ end+ endenddiff --git a/spec/jobs/trigger_scheduled_items_job_spec.rb b/spec/jobs/trigger_scheduled_items_job_spec.rbindex 2852c4ad5ac..9a8229ffac8 100644--- a/spec/jobs/trigger_scheduled_items_job_spec.rb+++ b/spec/jobs/trigger_scheduled_items_job_spec.rb@@ -20,8 +20,8 @@ RSpec.describe TriggerScheduledItemsJob dodescribed_class.perform_nowend- it 'triggers Account::ConversationsResolutionSchedulerJob' do- expect(Account::ConversationsResolutionSchedulerJob).to receive(:perform_later).once+ it 'does not trigger Account::ConversationsResolutionSchedulerJob' do+ expect(Account::ConversationsResolutionSchedulerJob).not_to receive(:perform_later)described_class.perform_nowenddiff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rbindex dc9a3472cae..bff67193c43 100644--- a/spec/models/account_spec.rb+++ b/spec/models/account_spec.rb@@ -328,6 +328,15 @@ RSpec.describe Account doaccount.settings = { auto_resolve_after: nil }expect(account).to be_validend++ it 'keeps a saved value valid after the minimum is raised' do+ with_modified_env AUTO_RESOLVE_MIN_MINUTES: '5' do+ account.update!(auto_resolve_after: 5)+ end++ expect(account.reload.update(name: 'Renamed')).to be(true)+ expect(account.update(auto_resolve_after: 6)).to be(false)+ endendcontext 'when auto_resolve_message' do