Skip to content

Commit

Permalink
Merge branch 'develop' into chore/response-sources-with-embeddings
Browse files Browse the repository at this point in the history
  • Loading branch information
sojan-official authored Jul 21, 2023
2 parents 1db6b2a + 30f3928 commit e99a8ee
Show file tree
Hide file tree
Showing 20 changed files with 204 additions and 126 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ gem 'devise_token_auth'
gem 'jwt'
gem 'pundit'
# super admin
gem 'administrate'
gem 'administrate', '>= 0.19.0'
gem 'administrate-field-active_storage'

##--- gems for pubsub service ---##
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ GEM
activerecord (>= 6.0, < 7.1)
addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0)
administrate (0.18.0)
administrate (0.19.0)
actionpack (>= 5.0)
actionview (>= 5.0)
activerecord (>= 5.0)
Expand Down Expand Up @@ -376,7 +376,7 @@ GEM
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jmespath (1.6.2)
jquery-rails (4.5.1)
jquery-rails (4.6.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
Expand Down Expand Up @@ -451,7 +451,7 @@ GEM
mime-types-data (3.2023.0218.1)
mini_magick (4.12.0)
mini_mime (1.1.2)
mini_portile2 (2.8.2)
mini_portile2 (2.8.4)
minitest (5.18.1)
mock_redis (0.36.0)
ruby2_keywords
Expand Down Expand Up @@ -829,7 +829,7 @@ DEPENDENCIES
active_record_query_trace
activerecord-import
acts-as-taggable-on
administrate
administrate (>= 0.19.0)
administrate-field-active_storage
annotate
attr_extras
Expand Down
5 changes: 3 additions & 2 deletions app/builders/v2/report_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def timeseries

# For backward compatible with old report
def build
if %w[avg_first_response_time avg_resolution_time].include?(params[:metric])
if %w[avg_first_response_time avg_resolution_time reply_time].include?(params[:metric])
timeseries.each_with_object([]) do |p, arr|
arr << { value: p[1], timestamp: p[0].in_time_zone(@timezone).to_i, count: @grouped_values.count[p[0]] }
end
Expand All @@ -38,7 +38,8 @@ def summary
outgoing_messages_count: outgoing_messages.count,
avg_first_response_time: avg_first_response_time_summary,
avg_resolution_time: avg_resolution_time_summary,
resolutions_count: resolutions.count
resolutions_count: resolutions.count,
reply_time: reply_time_summary
}
end

Expand Down
17 changes: 17 additions & 0 deletions app/helpers/report_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ def avg_first_response_time
grouped_reporting_events.average(:value)
end

def reply_time
grouped_reporting_events = (get_grouped_values scope.reporting_events.where(name: 'reply_time', account_id: account.id))
return grouped_reporting_events.average(:value_in_business_hours) if params[:business_hours]

grouped_reporting_events.average(:value)
end

def avg_resolution_time
grouped_reporting_events = (get_grouped_values scope.reporting_events.where(name: 'conversation_resolved', account_id: account.id))
return grouped_reporting_events.average(:value_in_business_hours) if params[:business_hours]
Expand All @@ -77,6 +84,16 @@ def avg_resolution_time_summary
avg_rt
end

def reply_time_summary
reporting_events = scope.reporting_events
.where(name: 'reply_time', account_id: account.id, created_at: range)
reply_time = params[:business_hours] ? reporting_events.average(:value_in_business_hours) : reporting_events.average(:value)

return 0 if reply_time.blank?

reply_time
end

def avg_first_response_time_summary
reporting_events = scope.reporting_events
.where(name: 'first_response', account_id: account.id, created_at: range)
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/dashboard/i18n/locale/en/report.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
"RESOLUTION_COUNT": {
"NAME": "Resolution Count",
"DESC": "( Total )"
},
"REPLY_TIME": {
"NAME": "Customer waiting time",
"TOOLTIP_TEXT": "Waiting time is %{metricValue} (based on %{conversationCount} conversations)"
}
},
"DATE_RANGE_OPTIONS": {
Expand Down
22 changes: 10 additions & 12 deletions app/javascript/dashboard/mixins/reportMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@ export default {
accountSummary: 'getAccountSummary',
accountReport: 'getAccountReports',
}),
calculateTrend() {
return metric_key => {
if (!this.accountSummary.previous[metric_key]) return 0;
const diff =
this.accountSummary[metric_key] -
this.accountSummary.previous[metric_key];
return Math.round(
(diff / this.accountSummary.previous[metric_key]) * 100
);
};
},
},
methods: {
calculateTrend(key) {
if (!this.accountSummary.previous[key]) return 0;
const diff = this.accountSummary[key] - this.accountSummary.previous[key];
return Math.round((diff / this.accountSummary.previous[key]) * 100);
},
displayMetric(key) {
if (this.isAverageMetricType(key)) {
return formatTime(this.accountSummary[key]);
Expand All @@ -39,7 +33,11 @@ export default {
return '';
},
isAverageMetricType(key) {
return ['avg_first_response_time', 'avg_resolution_time'].includes(key);
return [
'avg_first_response_time',
'avg_resolution_time',
'reply_time',
].includes(key);
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const REPORTS_KEYS = {
FIRST_RESPONSE_TIME: 'avg_first_response_time',
RESOLUTION_TIME: 'avg_resolution_time',
RESOLUTION_COUNT: 'resolutions_count',
REPLY_TIME: 'reply_time',
};
export default {
Expand Down Expand Up @@ -78,6 +79,7 @@ export default {
'FIRST_RESPONSE_TIME',
'RESOLUTION_TIME',
'RESOLUTION_COUNT',
'REPLY_TIME',
].forEach(async key => {
try {
await this.$store.dispatch('fetchAccountReport', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const REPORTS_KEYS = {
FIRST_RESPONSE_TIME: 'avg_first_response_time',
RESOLUTION_TIME: 'avg_resolution_time',
RESOLUTION_COUNT: 'resolutions_count',
REPLY_TIME: 'reply_time',
};
export default {
Expand All @@ -60,6 +61,7 @@ export default {
const reportKeys = [
'CONVERSATIONS',
'FIRST_RESPONSE_TIME',
'REPLY_TIME',
'RESOLUTION_TIME',
'RESOLUTION_COUNT',
'INCOMING_MESSAGES',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const REPORTS_KEYS = {
FIRST_RESPONSE_TIME: 'avg_first_response_time',
RESOLUTION_TIME: 'avg_resolution_time',
RESOLUTION_COUNT: 'resolutions_count',
REPLY_TIME: 'reply_time',
};
export default {
Expand Down Expand Up @@ -106,6 +107,7 @@ export default {
'FIRST_RESPONSE_TIME',
'RESOLUTION_TIME',
'RESOLUTION_COUNT',
'REPLY_TIME',
].forEach(async key => {
try {
const { from, to, groupBy, businessHours } = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,78 +151,48 @@ export const DEFAULT_CHART = {
},
};

export const METRIC_CHART = {
conversations_count: DEFAULT_CHART,
incoming_messages_count: DEFAULT_CHART,
outgoing_messages_count: DEFAULT_CHART,
avg_first_response_time: {
datasets: [DEFAULT_BAR_CHART],
scales: {
xAxes: [
{
ticks: {
fontFamily: CHART_FONT_FAMILY,
},
gridLines: {
drawOnChartArea: false,
},
const TIME_CHART_CONFIG = {
datasets: [DEFAULT_BAR_CHART],
scales: {
xAxes: [
{
ticks: {
fontFamily: CHART_FONT_FAMILY,
},
],
yAxes: [
{
id: 'y-left',
type: 'linear',
position: 'left',
ticks: {
fontFamily: CHART_FONT_FAMILY,
callback: (value, index, values) => {
if (!index || index === values.length - 1) {
return formatTime(value);
}
return '';
},
},
gridLines: {
drawOnChartArea: false,
},
gridLines: {
drawOnChartArea: false,
},
],
},
},
avg_resolution_time: {
datasets: [DEFAULT_BAR_CHART],
scales: {
xAxes: [
{
ticks: {
fontFamily: CHART_FONT_FAMILY,
},
gridLines: {
drawOnChartArea: false,
},
],
yAxes: [
{
id: 'y-left',
type: 'linear',
position: 'left',
ticks: {
fontFamily: CHART_FONT_FAMILY,
callback: (value, index, values) => {
if (!index || index === values.length - 1) {
return formatTime(value);
}
return '';
},
},
],
yAxes: [
{
id: 'y-left',
type: 'linear',
position: 'left',
ticks: {
fontFamily: CHART_FONT_FAMILY,
callback: (value, index, values) => {
if (!index || index === values.length - 1) {
return formatTime(value);
}
return '';
},
},
gridLines: {
drawOnChartArea: false,
},
gridLines: {
drawOnChartArea: false,
},
],
},
},
],
},
};

export const METRIC_CHART = {
conversations_count: DEFAULT_CHART,
incoming_messages_count: DEFAULT_CHART,
outgoing_messages_count: DEFAULT_CHART,
avg_first_response_time: TIME_CHART_CONFIG,
reply_time: TIME_CHART_CONFIG,
avg_resolution_time: TIME_CHART_CONFIG,
resolutions_count: DEFAULT_CHART,
};

Expand Down
3 changes: 3 additions & 0 deletions app/javascript/dashboard/store/modules/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const state = {
avg_first_response_time: false,
avg_resolution_time: false,
resolutions_count: false,
reply_time: false,
},
data: {
conversations_count: [],
Expand All @@ -27,6 +28,7 @@ const state = {
avg_first_response_time: [],
avg_resolution_time: [],
resolutions_count: [],
reply_time: [],
},
},
accountSummary: {
Expand All @@ -35,6 +37,7 @@ const state = {
conversations_count: 0,
incoming_messages_count: 0,
outgoing_messages_count: 0,
reply_time: 0,
resolutions_count: 0,
previous: {},
},
Expand Down
5 changes: 5 additions & 0 deletions app/models/concerns/channelable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ module Channelable
validates :account_id, presence: true
belongs_to :account
has_one :inbox, as: :channel, dependent: :destroy_async, touch: true
after_update :create_audit_log_entry
end

def messaging_window_enabled?
false
end

def create_audit_log_entry; end
end

Channelable.prepend_mod_with('Channelable')
2 changes: 1 addition & 1 deletion config/app.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
shared: &shared
version: '2.18.0'
version: '3.0.0'

development:
<<: *shared
Expand Down
34 changes: 34 additions & 0 deletions enterprise/app/models/enterprise/channelable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Enterprise::Channelable
extend ActiveSupport::Concern

# Active support concern has `included` which changes the order of the method lookup chain
# https://stackoverflow.com/q/40061982/3824876
# manually prepend the instance methods to combat this
included do
prepend InstanceMethods
end

module InstanceMethods
def create_audit_log_entry
account = self.account
associated_type = 'Account'

return if inbox.nil?

auditable_id = inbox.id
auditable_type = 'Inbox'
audited_changes = saved_changes.except('updated_at')

return if audited_changes.blank?

Enterprise::AuditLog.create(
auditable_id: auditable_id,
auditable_type: auditable_type,
action: 'update',
associated_id: account.id,
associated_type: associated_type,
audited_changes: audited_changes
)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def labels_with_messages

character_count = labels.length
conversation = find_conversation

# return nil if conversation has less than 3 incoming messages
return nil if conversation.messages.incoming.count < 3

messages = init_messages_body(false)
add_messages_until_token_limit(conversation, messages, false, character_count)

Expand Down
Loading

0 comments on commit e99a8ee

Please sign in to comment.