Просмотр исходного кода

Fixes #5117 - Caller is not identified if the caller has only entered a telephone number (no firstname, lastname, email).

Martin Edenhofer 10 месяцев назад
Родитель
Сommit
a51103363d

+ 5 - 0
app/assets/javascripts/app/controllers/agent_ticket_create.coffee

@@ -616,6 +616,11 @@ class App.TicketCreate extends App.Controller
     # to replace in text modules properly
     params.customer = App.User.find(params.customer_id) || {}
 
+    # show selected user display name in customer attribute in UI
+    if _.isEmpty(@el.find('input[name=customer_id_completion]').val())
+      if params.customer && params.customer.displayName
+        @el.find('input[name=customer_id_completion]').val(params.customer.displayName())
+
     @sidebarWidget.render(params)
     @textModule.reload(
       config: App.Config.all()

+ 11 - 1
app/models/cti/caller_id.rb

@@ -283,7 +283,7 @@ returns
       preferences_maybe = {}
       preferences_maybe[direction] = []
 
-      lookup(extract_numbers(caller_id)).each do |record|
+      lookup(extract_numbers(caller_id)).each do |record| # rubocop:disable Metrics/BlockLength
         if record.level == 'known'
           preferences_known[direction].push record.attributes
         else
@@ -294,6 +294,16 @@ returns
           user = User.lookup(id: record.user_id)
           if user
             comment += user.fullname
+
+            if comment.blank?
+              %w[phone mobile].each do |item| # rubocop:disable Performance/CollectionLiteralInLoop
+                next if user[item].blank? # rubocop:disable Metrics/BlockNesting
+
+                comment += user[item]
+                break
+              end
+            end
+
           end
         elsif record.comment.present?
           comment += record.comment

+ 26 - 0
spec/system/cti_spec.rb

@@ -111,6 +111,7 @@ RSpec.describe 'Caller log', authenticated_as: :authenticate, type: :system do
           expect(page).to have_text('New Ticket')
           expect(page).to have_css('input[name="title"][value="Call from 0190333"]', visible: :all)
           expect(page).to have_css('.tabsSidebar-tab[data-tab="customer"]', visible: :all)
+          expect(page).to have_css("input[name=customer_id][value='#{customer.id}']", visible: :hide)
         end
       end
     end
@@ -146,6 +147,31 @@ RSpec.describe 'Caller log', authenticated_as: :authenticate, type: :system do
         end
       end
     end
+
+    context 'with phone number only known customer and without active tickets' do
+      let(:customer_phone) { '0190444' }
+      let(:customer)       { create(:customer, phone: customer_phone, email: nil, firstname: nil, lastname: nil) }
+
+      before do
+        travel(-2.months)
+        create(:ticket, customer: customer)
+        travel_back
+
+        visit_cti
+        place_call
+      end
+
+      it 'opens a new ticket after phone call inbound' do
+        within(:active_content) do
+          expect(page).to have_text('New Ticket')
+          expect(page).to have_css('input[name="title"][value="Call from 0190444"]', visible: :all)
+          expect(page).to have_css('.tabsSidebar-tab[data-tab="customer"]', visible: :all)
+          expect(page).to have_css("input[name=customer_id][value='#{customer.id}']", visible: :hide)
+          expect(find('[name=customer_id_completion]').value).to eq '0190444'
+        end
+      end
+    end
+
   end
 
   context 'with incoming call' do