feat: Instagram reauthorization (#11221)
This PR is part of https://github.com/chatwoot/chatwoot/pull/11054 to make the review cycle easier.
This commit is contained in:
@@ -19,6 +19,8 @@ class Channel::Instagram < ApplicationRecord
|
||||
include Reauthorizable
|
||||
self.table_name = 'channel_instagram'
|
||||
|
||||
AUTHORIZATION_ERROR_THRESHOLD = 1
|
||||
|
||||
validates :access_token, presence: true
|
||||
validates :instagram_id, uniqueness: true, presence: true
|
||||
|
||||
|
||||
@@ -39,18 +39,7 @@ module Reauthorizable
|
||||
def prompt_reauthorization!
|
||||
::Redis::Alfred.set(reauthorization_required_key, true)
|
||||
|
||||
case self.class.name
|
||||
when 'Integrations::Hook'
|
||||
process_integration_hook_reauthorization_emails
|
||||
when 'Channel::FacebookPage'
|
||||
send_channel_reauthorization_email(:facebook_disconnect)
|
||||
when 'Channel::Whatsapp'
|
||||
send_channel_reauthorization_email(:whatsapp_disconnect)
|
||||
when 'Channel::Email'
|
||||
send_channel_reauthorization_email(:email_disconnect)
|
||||
when 'AutomationRule'
|
||||
handle_automation_rule_reauthorization
|
||||
end
|
||||
reauthorization_handlers[self.class.name]&.call(self)
|
||||
|
||||
invalidate_inbox_cache unless instance_of?(::AutomationRule)
|
||||
end
|
||||
@@ -82,6 +71,17 @@ module Reauthorizable
|
||||
|
||||
private
|
||||
|
||||
def reauthorization_handlers
|
||||
{
|
||||
'Integrations::Hook' => ->(obj) { obj.process_integration_hook_reauthorization_emails },
|
||||
'Channel::FacebookPage' => ->(obj) { obj.send_channel_reauthorization_email(:facebook_disconnect) },
|
||||
'Channel::Instagram' => ->(obj) { obj.send_channel_reauthorization_email(:instagram_disconnect) },
|
||||
'Channel::Whatsapp' => ->(obj) { obj.send_channel_reauthorization_email(:whatsapp_disconnect) },
|
||||
'Channel::Email' => ->(obj) { obj.send_channel_reauthorization_email(:email_disconnect) },
|
||||
'AutomationRule' => ->(obj) { obj.handle_automation_rule_reauthorization }
|
||||
}
|
||||
end
|
||||
|
||||
def invalidate_inbox_cache
|
||||
inbox.update_account_cache if inbox.present?
|
||||
end
|
||||
|
||||
@@ -107,7 +107,11 @@ class Inbox < ApplicationRecord
|
||||
end
|
||||
|
||||
def instagram?
|
||||
facebook? && channel.instagram_id.present?
|
||||
(facebook? || instagram_direct?) && channel.instagram_id.present?
|
||||
end
|
||||
|
||||
def instagram_direct?
|
||||
channel_type == 'Channel::Instagram'
|
||||
end
|
||||
|
||||
def web_widget?
|
||||
|
||||
Reference in New Issue
Block a user