fix: bots included in time to response metrics (#6409)
* feat: ignore bots in avg_first_response_time * feat: ignore bots in avg_first_response count * feat: add bot handoff event * feat: add handoff event listener and reporting event * fix: ignore agent bot in first response * refactor: calculate first_response with last handoff * refactor: method defn order * test: new reporting events * feat: Revert "feat: ignore bots in avg_first_response count" This reverts commit de1977c219a2e7a9180dd02272244fe3b3f7ce89. * feat: Revert "feat: ignore bots in avg_first_response_time" This reverts commit bb9171945d5e3b2f6015f4f96dd1b76b3efb6987. * fix: business hour calculation for first_reply * fix: event_start_time for first_response * feat: add migration to recompute first_responses * refactor: separate mute helpers for conversation * refactor: rename migration * refactor: migration script * fix: migration typo * fix: typo in query * feat: update schema.rb * Revert "feat: update schema.rb" This reverts commit 353ef355f2d956dd219907bb66982dc90ca5d896. * feat: update schema * refactor: update events as a batch job * fix: ignore the event if value is negative * feat: don't create a new hand-off if it's already present * refactor: break the action into smaller chunks * refactor: update reporting listener spec Handle the case to ensure extra bot handoffs are not created for a give conversation * fix: import error --------- Co-authored-by: Vishnu Narayanan <vishnu@chatwoot.com>
This commit is contained in:
@@ -60,5 +60,56 @@ describe ReportingEventListener do
|
||||
expect(account.reporting_events.where(name: 'first_response')[0]['value_in_business_hours']).to be 144_000.0
|
||||
end
|
||||
end
|
||||
|
||||
# this ensures last_non_human_activity method accurately accounts for handoff events
|
||||
context 'when last handoff event exists' do
|
||||
let(:conversation_updated_at) { 20.seconds.from_now }
|
||||
let(:human_message_created_at) { 62.seconds.from_now }
|
||||
let(:new_conversation) { create(:conversation, account: account, inbox: inbox, assignee: user, updated_at: conversation_updated_at) }
|
||||
let(:new_message) do
|
||||
create(:message, message_type: 'outgoing', created_at: human_message_created_at, account: account, inbox: inbox,
|
||||
conversation: new_conversation)
|
||||
end
|
||||
|
||||
it 'creates first_response event with handoff value' do
|
||||
# this will create a handoff event
|
||||
event = Events::Base.new('conversation.bot_handoff', conversation_updated_at, conversation: new_conversation)
|
||||
listener.conversation_bot_handoff(event)
|
||||
|
||||
# create the first reply event
|
||||
event = Events::Base.new('first.reply.created', human_message_created_at, message: new_message)
|
||||
listener.first_reply_created(event)
|
||||
expect(account.reporting_events.where(name: 'first_response')[0]['value']).to be 42.0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#conversation_bot_handoff' do
|
||||
it 'creates conversation_bot_handoff event only once' do
|
||||
expect(account.reporting_events.where(name: 'conversation_bot_handoff').count).to be 0
|
||||
event = Events::Base.new('conversation.bot_handoff', Time.zone.now, conversation: conversation)
|
||||
listener.conversation_bot_handoff(event)
|
||||
expect(account.reporting_events.where(name: 'conversation_bot_handoff').count).to be 1
|
||||
|
||||
# add extra handoff event for the same and ensure it's not created
|
||||
event = Events::Base.new('conversation.bot_handoff', Time.zone.now, conversation: conversation)
|
||||
listener.conversation_bot_handoff(event)
|
||||
expect(account.reporting_events.where(name: 'conversation_bot_handoff').count).to be 1
|
||||
end
|
||||
|
||||
context 'when business hours enabled for inbox' do
|
||||
let(:created_at) { Time.zone.parse('March 20, 2022 00:00') }
|
||||
let(:updated_at) { Time.zone.parse('March 26, 2022 23:59') }
|
||||
let!(:new_inbox) { create(:inbox, working_hours_enabled: true, account: account) }
|
||||
let!(:new_conversation) do
|
||||
create(:conversation, created_at: created_at, updated_at: updated_at, account: account, inbox: new_inbox, assignee: user)
|
||||
end
|
||||
|
||||
it 'creates conversation_bot_handoff event with business hour value' do
|
||||
event = Events::Base.new('conversation.bot_handoff', Time.zone.now, conversation: new_conversation)
|
||||
listener.conversation_bot_handoff(event)
|
||||
expect(account.reporting_events.where(name: 'conversation_bot_handoff')[0]['value_in_business_hours']).to be 144_000.0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user