Fixes #3107 - Improve CTI / open user profile or new ticket screen based on last customer activity.
This commit is contained in:
parent
9d3c0e3984
commit
25c7e81667
4 changed files with 113 additions and 0 deletions
|
@ -134,6 +134,24 @@ class Cti::Driver::Base
|
|||
|
||||
customer_id = log.best_customer_id_of_log_entry
|
||||
|
||||
# open user profile if user has a ticket in the last 30 days
|
||||
if customer_id
|
||||
last_activity = Setting.get('cti_customer_last_activity')
|
||||
if Ticket.where(customer_id: customer_id).where('updated_at > ?', last_activity.seconds.ago).exists?
|
||||
PushMessages.send_to(user.id, {
|
||||
event: 'remote_task',
|
||||
data: {
|
||||
key: "User-#{customer_id}",
|
||||
controller: 'UserProfile',
|
||||
params: { user_id: customer_id.to_s },
|
||||
show: true,
|
||||
url: "user/profile/#{customer_id}"
|
||||
},
|
||||
})
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
id = rand(999_999_999)
|
||||
PushMessages.send_to(user.id, {
|
||||
event: 'remote_task',
|
||||
|
|
21
db/migrate/20200806122951_cti_user_profile.rb
Normal file
21
db/migrate/20200806122951_cti_user_profile.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
class CtiUserProfile < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
|
||||
# return if it's a new setup
|
||||
return if !Setting.exists?(name: 'system_init_done')
|
||||
|
||||
Setting.create_if_not_exists(
|
||||
title: 'cti customer last activity',
|
||||
name: 'cti_customer_last_activity',
|
||||
area: 'Integration::Cti',
|
||||
description: 'Defines the range in seconds of customer activity to trigger the user profile dialog on call.',
|
||||
options: {},
|
||||
state: 30.days,
|
||||
preferences: {
|
||||
prio: 2,
|
||||
permission: ['admin.integration'],
|
||||
},
|
||||
frontend: false,
|
||||
)
|
||||
end
|
||||
end
|
|
@ -4212,6 +4212,19 @@ Setting.create_if_not_exists(
|
|||
},
|
||||
frontend: false
|
||||
)
|
||||
Setting.create_if_not_exists(
|
||||
title: 'cti customer last activity',
|
||||
name: 'cti_customer_last_activity',
|
||||
area: 'Integration::Cti',
|
||||
description: 'Defines the range in seconds of customer activity to trigger the user profile dialog on call.',
|
||||
options: {},
|
||||
state: 30.days,
|
||||
preferences: {
|
||||
prio: 2,
|
||||
permission: ['admin.integration'],
|
||||
},
|
||||
frontend: false,
|
||||
)
|
||||
Setting.create_if_not_exists(
|
||||
title: 'Placetel integration',
|
||||
name: 'placetel_integration',
|
||||
|
|
61
spec/system/cti_spec.rb
Normal file
61
spec/system/cti_spec.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Caller log', type: %i[system request], authenticated_as: true do # rubocop:disable RSpec/DescribeClass
|
||||
let(:admin) do
|
||||
create(:admin, groups: Group.all)
|
||||
end
|
||||
|
||||
let!(:customer) { create(:customer, phone: '0190333') }
|
||||
|
||||
let(:params) do
|
||||
{
|
||||
direction: 'in',
|
||||
from: '0190333',
|
||||
to: '0190111',
|
||||
callId: '111',
|
||||
cause: 'busy'
|
||||
}
|
||||
end
|
||||
|
||||
def prepare
|
||||
Setting.set('cti_integration', true)
|
||||
Setting.set('cti_token', 'token1234')
|
||||
current_user.update(phone: '0190111')
|
||||
end
|
||||
|
||||
context 'without active tickets' do
|
||||
it 'checks opening of the ticket creation screen after phone call inbound' do
|
||||
prepare
|
||||
|
||||
travel(-2.months)
|
||||
create(:ticket, customer: customer)
|
||||
travel_back
|
||||
|
||||
visit 'cti'
|
||||
|
||||
post "#{Capybara.app_host}/api/v1/cti/token1234", params: params.merge(event: 'newCall'), as: :json
|
||||
post "#{Capybara.app_host}/api/v1/cti/token1234", params: params.merge(event: 'answer', answeringNumber: '0190111' ), as: :json
|
||||
|
||||
within(:active_content) do
|
||||
expect(page).to have_text('New Ticket', wait: 5)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with active tickets' do
|
||||
it 'checks opening of the user profile screen after phone call inbound with tickets in the last month' do
|
||||
prepare
|
||||
|
||||
create(:ticket, customer: customer)
|
||||
|
||||
visit 'cti'
|
||||
|
||||
post "#{Capybara.app_host}/api/v1/cti/token1234", params: params.merge(event: 'newCall'), as: :json
|
||||
post "#{Capybara.app_host}/api/v1/cti/token1234", params: params.merge(event: 'answer', answeringNumber: '0190111' ), as: :json
|
||||
|
||||
within(:active_content) do
|
||||
expect(page).to have_text(customer.fullname, wait: 5)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue