chore: Mark conversations as pending instead of reopen when bot is present (#5751)
With this change, conversations are marked as pending instead of reopening when a bot is connected to that Inbox. Fixes: #5668
This commit is contained in:
@@ -210,7 +210,7 @@ class Conversation < ApplicationRecord
|
|||||||
|
|
||||||
def mark_conversation_pending_if_bot
|
def mark_conversation_pending_if_bot
|
||||||
# TODO: make this an inbox config instead of assuming bot conversations should start as pending
|
# TODO: make this an inbox config instead of assuming bot conversations should start as pending
|
||||||
self.status = :pending if inbox.agent_bot_inbox&.active? || inbox.hooks.pluck(:app_id).include?('dialogflow')
|
self.status = :pending if inbox.active_bot?
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify_conversation_creation
|
def notify_conversation_creation
|
||||||
|
|||||||
@@ -101,6 +101,10 @@ class Inbox < ApplicationRecord
|
|||||||
channel_type == 'Channel::Whatsapp'
|
channel_type == 'Channel::Whatsapp'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def active_bot?
|
||||||
|
agent_bot_inbox&.active? || hooks.pluck(:app_id).include?('dialogflow')
|
||||||
|
end
|
||||||
|
|
||||||
def inbox_type
|
def inbox_type
|
||||||
channel.name
|
channel.name
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -193,7 +193,18 @@ class Message < ApplicationRecord
|
|||||||
return if conversation.muted?
|
return if conversation.muted?
|
||||||
return unless incoming?
|
return unless incoming?
|
||||||
|
|
||||||
conversation.open! if conversation.resolved? || conversation.snoozed?
|
conversation.open! if conversation.snoozed?
|
||||||
|
|
||||||
|
reopen_resolved_conversation if conversation.resolved?
|
||||||
|
end
|
||||||
|
|
||||||
|
def reopen_resolved_conversation
|
||||||
|
# mark resolved bot conversation as pending to be reopened by bot processor service
|
||||||
|
if conversation.inbox.active_bot?
|
||||||
|
conversation.pending!
|
||||||
|
else
|
||||||
|
conversation.open!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute_message_template_hooks
|
def execute_message_template_hooks
|
||||||
|
|||||||
@@ -31,6 +31,17 @@ RSpec.describe Message, type: :model do
|
|||||||
message.save!
|
message.save!
|
||||||
expect(message.conversation.open?).to be false
|
expect(message.conversation.open?).to be false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'will mark the conversation as pending if the agent bot is active' do
|
||||||
|
agent_bot = create(:agent_bot)
|
||||||
|
inbox = conversation.inbox
|
||||||
|
inbox.agent_bot = agent_bot
|
||||||
|
inbox.save!
|
||||||
|
conversation.resolved!
|
||||||
|
message.save!
|
||||||
|
expect(conversation.open?).to be false
|
||||||
|
expect(conversation.pending?).to be true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with webhook_data' do
|
context 'with webhook_data' do
|
||||||
|
|||||||
Reference in New Issue
Block a user