feat(ee): Add reporting events for bots (#9027)

Added a new event conversation_bot_resolved and added a job to auto resolve the bot conversations if there was no activity for the last 1 hour.
This commit is contained in:
Sojan Jose
2024-02-28 04:23:28 +05:30
committed by GitHub
parent b7a83dcbcd
commit 41e269e873
20 changed files with 194 additions and 15 deletions

View File

@@ -0,0 +1,10 @@
module Enterprise::Account::ConversationsResolutionSchedulerJob
def perform
super
Account.feature_response_bot.all.find_each(batch_size: 100) do |account|
account.inboxes.each do |inbox|
ResponseBot::InboxPendingConversationsResolutionJob.perform_later(inbox) if inbox.response_bot_enabled?
end
end
end
end

View File

@@ -0,0 +1,19 @@
class ResponseBot::InboxPendingConversationsResolutionJob < ApplicationJob
queue_as :low
def perform(inbox)
# limiting the number of conversations to be resolved to avoid any performance issues
resolvable_conversations = inbox.conversations.pending.where('last_activity_at < ? ', Time.now.utc - 1.hour).limit(Limits::BULK_ACTIONS_LIMIT)
resolvable_conversations.each do |conversation|
conversation.messages.create!(
{
message_type: :outgoing,
account_id: conversation.account_id,
inbox_id: conversation.inbox_id,
content: 'Resolving the conversation as it has been inactive for a while. Please start a new conversation if you need further assistance.'
}
)
conversation.resolved!
end
end
end

View File

@@ -1,4 +1,4 @@
class ResponseBotJob < ApplicationJob
class ResponseBot::ResponseBotJob < ApplicationJob
queue_as :medium
def perform(conversation)

View File

@@ -1,4 +1,4 @@
class ResponseBuilderJob < ApplicationJob
class ResponseBot::ResponseBuilderJob < ApplicationJob
queue_as :default
def perform(response_document)

View File

@@ -1,5 +1,5 @@
# app/jobs/response_document_content_job.rb
class ResponseDocumentContentJob < ApplicationJob
class ResponseBot::ResponseDocumentContentJob < ApplicationJob
queue_as :default
def perform(response_document)