chore: Centralize outgoing message reply restrictions for all the channels (#11279)

This commit is contained in:
Muhsin Keloth
2025-04-12 08:52:12 +05:30
committed by GitHub
parent bdcb080e40
commit e0097ab102
12 changed files with 721 additions and 179 deletions

View File

@@ -33,10 +33,6 @@ class Channel::Api < ApplicationRecord
'API'
end
def messaging_window_enabled?
additional_attributes.present? && additional_attributes['agent_reply_time_window'].present?
end
private
def ensure_valid_agent_reply_time_window

View File

@@ -32,10 +32,6 @@ class Channel::FacebookPage < ApplicationRecord
'Facebook'
end
def messaging_window_enabled?
false
end
def create_contact_inbox(instagram_id, name)
@contact_inbox = ::ContactInboxWithContactBuilder.new({
source_id: instagram_id,

View File

@@ -41,10 +41,6 @@ class Channel::TwilioSms < ApplicationRecord
medium == 'sms' ? 'Twilio SMS' : 'Whatsapp'
end
def messaging_window_enabled?
medium == 'whatsapp'
end
def send_message(to:, body:, media_url: nil)
params = send_message_from.merge(to: to, body: body)
params[:media_url] = media_url if media_url.present?

View File

@@ -46,10 +46,6 @@ class Channel::Whatsapp < ApplicationRecord
end
end
def messaging_window_enabled?
true
end
def mark_message_templates_updated
# rubocop:disable Rails/SkipsModelValidations
update_column(:message_templates_last_updated, Time.zone.now)

View File

@@ -7,10 +7,6 @@ module Channelable
after_update :create_audit_log_entry
end
def messaging_window_enabled?
false
end
def create_audit_log_entry; end
end

View File

@@ -115,14 +115,7 @@ class Conversation < ApplicationRecord
delegate :auto_resolve_duration, to: :account
def can_reply?
channel = inbox&.channel
return can_reply_on_instagram? if additional_attributes['type'] == 'instagram_direct_message'
return true unless channel&.messaging_window_enabled?
messaging_window = inbox.api? ? channel.additional_attributes['agent_reply_time_window'].to_i : 24
last_message_in_messaging_window?(messaging_window)
Conversations::MessageWindowService.new(self).can_reply?
end
def language
@@ -137,24 +130,6 @@ class Conversation < ApplicationRecord
messages&.incoming&.last
end
def last_message_in_messaging_window?(time)
return false if last_incoming_message.nil?
Time.current < last_incoming_message.created_at + time.hours
end
def can_reply_on_instagram?
global_config = GlobalConfig.get('ENABLE_MESSENGER_CHANNEL_HUMAN_AGENT')
return false if last_incoming_message.nil?
if global_config['ENABLE_MESSENGER_CHANNEL_HUMAN_AGENT']
Time.current < last_incoming_message.created_at + 7.days
else
last_message_in_messaging_window?(24)
end
end
def toggle_status
# FIXME: implement state machine with aasm
self.status = open? ? :resolved : :open