mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 12:08:01 +00:00
* 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>
60 lines
1.8 KiB
Ruby
60 lines
1.8 KiB
Ruby
module ReportingEventHelper
|
|
def business_hours(inbox, from, to)
|
|
return 0 unless inbox.working_hours_enabled?
|
|
|
|
inbox_working_hours = configure_working_hours(inbox.working_hours)
|
|
return 0 if inbox_working_hours.blank?
|
|
|
|
# Configure working hours
|
|
WorkingHours::Config.working_hours = inbox_working_hours
|
|
|
|
# Configure timezone
|
|
WorkingHours::Config.time_zone = inbox.timezone
|
|
|
|
# Use inbox timezone to change from & to values.
|
|
from_in_inbox_timezone = from.in_time_zone(inbox.timezone).to_time
|
|
to_in_inbox_timezone = to.in_time_zone(inbox.timezone).to_time
|
|
from_in_inbox_timezone.working_time_until(to_in_inbox_timezone)
|
|
end
|
|
|
|
def last_non_human_activity(conversation)
|
|
# check if a handoff event already exists
|
|
handoff_event = ReportingEvent.where(conversation_id: conversation.id, name: 'conversation_bot_handoff').last
|
|
|
|
# if a handoff exists, last non human activity is when the handoff ended,
|
|
# otherwise it's when the conversation was created
|
|
handoff_event&.event_end_time || conversation.created_at
|
|
end
|
|
|
|
private
|
|
|
|
def configure_working_hours(working_hours)
|
|
working_hours.each_with_object({}) do |working_hour, object|
|
|
object[day(working_hour.day_of_week)] = working_hour_range(working_hour) unless working_hour.closed_all_day?
|
|
end
|
|
end
|
|
|
|
def day(day_of_week)
|
|
week_days = {
|
|
0 => :sun,
|
|
1 => :mon,
|
|
2 => :tue,
|
|
3 => :wed,
|
|
4 => :thu,
|
|
5 => :fri,
|
|
6 => :sat
|
|
}
|
|
week_days[day_of_week]
|
|
end
|
|
|
|
def working_hour_range(working_hour)
|
|
{ format_time(working_hour.open_hour, working_hour.open_minutes) => format_time(working_hour.close_hour, working_hour.close_minutes) }
|
|
end
|
|
|
|
def format_time(hour, minute)
|
|
hour = hour < 10 ? "0#{hour}" : hour
|
|
minute = minute < 10 ? "0#{minute}" : minute
|
|
"#{hour}:#{minute}"
|
|
end
|
|
end
|