diff --git a/app/javascript/dashboard/i18n/locale/en/integrations.json b/app/javascript/dashboard/i18n/locale/en/integrations.json index addba946c..231892079 100644 --- a/app/javascript/dashboard/i18n/locale/en/integrations.json +++ b/app/javascript/dashboard/i18n/locale/en/integrations.json @@ -85,7 +85,8 @@ "UPDATE": "Update", "BUTTON_TEXT": "Connect channel", "DESCRIPTION": "Your Slack workspace is now linked with Chatwoot. However, the integration is currently inactive. To activate the integration and connect a channel to Chatwoot, please click the button below.\n\n**Note:** If you are attempting to connect a private channel, add the Chatwoot app to the Slack channel before proceeding with this step.", - "ATTENTION_REQUIRED": "Attention required" + "ATTENTION_REQUIRED": "Attention required", + "EXPIRED": "Your Slack integration has expired. To continue receiving messages on Slack, please delete the integration and connect your workspace again." }, "UPDATE_ERROR": "There was an error updating the integration, please try again", "UPDATE_SUCCESS": "The channel is connected successfully", diff --git a/app/javascript/dashboard/routes/dashboard/settings/integrations/Slack.vue b/app/javascript/dashboard/routes/dashboard/settings/integrations/Slack.vue index c903a001d..1e6a934a6 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/integrations/Slack.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/integrations/Slack.vue @@ -21,7 +21,10 @@ />
Your Slack integration has expired.
-Please reconnect Slack to continue receiving messages on Slack
+Your Slack integration has expired. To continue receiving messages on Slack, please delete the integration and connect your workspace again.
Click here to re-connect. diff --git a/lib/integrations/slack/send_on_slack_service.rb b/lib/integrations/slack/send_on_slack_service.rb index 3ac595ee5..00497a3e6 100644 --- a/lib/integrations/slack/send_on_slack_service.rb +++ b/lib/integrations/slack/send_on_slack_service.rb @@ -80,10 +80,10 @@ class Integrations::Slack::SendOnSlackService < Base::SendOnChannelService def send_message post_message if message_content.present? upload_file if message.attachments.any? - rescue Slack::Web::Api::Errors::AccountInactive => e + rescue Slack::Web::Api::Errors::AccountInactive, Slack::Web::Api::Errors::MissingScope => e Rails.logger.error e - hook.authorization_error! - hook.disable if hook.enabled? + hook.prompt_reauthorization! + hook.disable end def post_message diff --git a/spec/lib/integrations/slack/send_on_slack_service_spec.rb b/spec/lib/integrations/slack/send_on_slack_service_spec.rb index bf6ff142a..d1704dcd2 100644 --- a/spec/lib/integrations/slack/send_on_slack_service_spec.rb +++ b/spec/lib/integrations/slack/send_on_slack_service_spec.rb @@ -194,11 +194,28 @@ describe Integrations::Slack::SendOnSlackService do unfurl_links: true ).and_raise(Slack::Web::Api::Errors::AccountInactive.new('Account disconnected')) - allow(hook).to receive(:authorization_error!) + allow(hook).to receive(:prompt_reauthorization!) builder.perform expect(hook).to be_disabled - expect(hook).to have_received(:authorization_error!) + expect(hook).to have_received(:prompt_reauthorization!) + end + + it 'disables hook on Slack MissingScope error' do + expect(slack_client).to receive(:chat_postMessage).with( + channel: hook.reference_id, + text: message.content, + username: "#{message.sender.name} (Contact)", + thread_ts: conversation.identifier, + icon_url: anything, + unfurl_links: true + ).and_raise(Slack::Web::Api::Errors::MissingScope.new('Account disconnected')) + + allow(hook).to receive(:prompt_reauthorization!) + + builder.perform + expect(hook).to be_disabled + expect(hook).to have_received(:prompt_reauthorization!) end end diff --git a/spec/models/integrations/hook_spec.rb b/spec/models/integrations/hook_spec.rb index e8b1b8156..fbad9192e 100644 --- a/spec/models/integrations/hook_spec.rb +++ b/spec/models/integrations/hook_spec.rb @@ -1,6 +1,9 @@ require 'rails_helper' +require Rails.root.join 'spec/models/concerns/reauthorizable_shared.rb' RSpec.describe Integrations::Hook do + it_behaves_like 'reauthorizable' + context 'with validations' do it { is_expected.to validate_presence_of(:app_id) } it { is_expected.to validate_presence_of(:account_id) }