chore: add human agent check in instagram channel
This commit is contained in:
@@ -117,7 +117,9 @@ class Conversation < ApplicationRecord
|
||||
def can_reply?
|
||||
channel = inbox&.channel
|
||||
|
||||
return can_reply_on_instagram? if additional_attributes['type'] == 'instagram_direct_message'
|
||||
return can_reply_on_instagram_via_messenger? if additional_attributes['type'] == 'instagram_direct_message'
|
||||
|
||||
return can_reply_on_instagram? if inbox.instagram_direct?
|
||||
|
||||
return true unless channel&.messaging_window_enabled?
|
||||
|
||||
@@ -143,7 +145,7 @@ class Conversation < ApplicationRecord
|
||||
Time.current < last_incoming_message.created_at + time.hours
|
||||
end
|
||||
|
||||
def can_reply_on_instagram?
|
||||
def can_reply_on_instagram_via_messenger?
|
||||
global_config = GlobalConfig.get('ENABLE_MESSENGER_CHANNEL_HUMAN_AGENT')
|
||||
|
||||
return false if last_incoming_message.nil?
|
||||
@@ -155,6 +157,18 @@ class Conversation < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def can_reply_on_instagram?
|
||||
global_config = GlobalConfig.get('ENABLE_INSTAGRAM_CHANNEL_HUMAN_AGENT')
|
||||
|
||||
return false if last_incoming_message.nil?
|
||||
|
||||
if global_config['ENABLE_INSTAGRAM_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
|
||||
|
||||
@@ -613,7 +613,11 @@ RSpec.describe Conversation do
|
||||
let!(:facebook_inbox) { create(:inbox, channel: facebook_channel, account: facebook_channel.account) }
|
||||
let!(:conversation) { create(:conversation, inbox: facebook_inbox, account: facebook_channel.account) }
|
||||
|
||||
context 'when instagram channel' do
|
||||
let!(:instagram_channel) { create(:channel_instagram) }
|
||||
let!(:instagram_inbox) { create(:inbox, channel: instagram_channel, account: instagram_channel.account) }
|
||||
let!(:instagram_conversation) { create(:conversation, inbox: instagram_inbox, account: instagram_channel.account) }
|
||||
|
||||
context 'when instagram messenger channel' do
|
||||
it 'return true with HUMAN_AGENT if it is outside of 24 hour window' do
|
||||
InstallationConfig.where(name: 'ENABLE_MESSENGER_CHANNEL_HUMAN_AGENT').first_or_create(value: true)
|
||||
|
||||
@@ -644,6 +648,26 @@ RSpec.describe Conversation do
|
||||
expect(conversation.can_reply?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when instagram channel' do
|
||||
it 'return true with HUMAN_AGENT if it is outside of 24 hour window' do
|
||||
InstallationConfig.where(name: 'ENABLE_INSTAGRAM_CHANNEL_HUMAN_AGENT').first_or_create(value: true)
|
||||
|
||||
create(:message, account: instagram_conversation.account, inbox: instagram_inbox, conversation: instagram_conversation,
|
||||
created_at: 48.hours.ago)
|
||||
|
||||
expect(conversation.can_reply?).to be true
|
||||
end
|
||||
|
||||
it 'return false without HUMAN_AGENT if it is outside of 24 hour window' do
|
||||
InstallationConfig.where(name: 'ENABLE_INSTAGRAM_CHANNEL_HUMAN_AGENT').first_or_create(value: false)
|
||||
|
||||
create(:message, account: instagram_conversation.account, inbox: instagram_inbox, conversation: instagram_conversation,
|
||||
created_at: 48.hours.ago)
|
||||
|
||||
expect(conversation.can_reply?).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'on API channels' do
|
||||
|
||||
Reference in New Issue
Block a user