diff --git a/app/assets/javascripts/webchat/library.js b/app/assets/javascripts/webchat/library.js index 1733eb083..2adca0f4b 100644 --- a/app/assets/javascripts/webchat/library.js +++ b/app/assets/javascripts/webchat/library.js @@ -13,7 +13,9 @@ "BUSY", "UNAVAILABLE", "AVAILABLE", - "ERROR" + "ERROR", + "OFFLINE", + "ONLINE" ] var $el = $(options.$el) var openUrl = $el.attr('data-open-url') @@ -22,6 +24,7 @@ var webchatStateClass = 'js-webchat-advisers-' var intervalID = null var lastRecordedState = null + var response_datatype = $el.attr('data-redirect') function init () { if (!availabilityUrl || !openUrl) throw 'urls for webchat not defined' @@ -32,7 +35,7 @@ function handleOpenChat (evt) { evt.preventDefault() - global.open(openUrl, 'newwin', 'width=366,height=516') + this.dataset.redirect =="true" ? window.location.href = openUrl : global.open(openUrl, 'newwin', 'width=366,height=516') trackEvent('opened') } @@ -40,6 +43,7 @@ var ajaxConfig = { url: availabilityUrl, type: 'GET', + dataType: response_datatype, timeout: AJAX_TIMEOUT, success: apiSuccess, error: apiError @@ -48,8 +52,31 @@ } function apiSuccess (result) { - var validState = API_STATES.indexOf(result.response) != -1 - var state = validState ? result.response : "ERROR" + + if(result.hasOwnProperty('inHOP')){ + var validState = API_STATES.indexOf(result.status.toUpperCase()) != -1 + var state = validState ? result.status : "ERROR" + if (result.inHOP == "true"){ + if(result.availability == "true"){ + if(result.status == "online"){ + state="AVAILABLE" + } + if (result.status == "busy"){ + state="BUSY" + } + if (result.status == "offline"){ + state="UNAVAILABLE" + } + }else{ + state="UNAVAILABLE" + } + }else{ + state = "UNAVAILABLE" + } + }else{ + var validState = API_STATES.indexOf(result.response) != -1 + var state = validState ? result.response : "ERROR" + } advisorStateChange(state) } diff --git a/app/models/webchat.rb b/app/models/webchat.rb index 82234d754..b3ebecd32 100644 --- a/app/models/webchat.rb +++ b/app/models/webchat.rb @@ -5,13 +5,14 @@ class Webchat validates_presence_of :base_path, :open_url, :availability_url - attr_reader :base_path, :open_url, :availability_url + attr_reader :base_path, :open_url, :availability_url, :open_url_redirect, :availability_payload_format def initialize(attrs) @base_path = attrs["base_path"] if attrs["base_path"].present? @open_url = attrs["open_url"] if attrs["open_url"].present? @availability_url = attrs["availability_url"] if attrs["availability_url"].present? - + @open_url_redirect = attrs.fetch("open_url_redirect", nil) + @availability_payload_format = attrs.fetch("availability_payload_format", nil) validate! end diff --git a/app/views/shared/_webchat.html.erb b/app/views/shared/_webchat.html.erb index d92d74f53..74a4a3fdf 100644 --- a/app/views/shared/_webchat.html.erb +++ b/app/views/shared/_webchat.html.erb @@ -4,6 +4,7 @@ <% if webchat_unavailable? %> <%= unavailability_message %> @@ -19,7 +20,7 @@ <% end %> diff --git a/lib/webchat.yaml b/lib/webchat.yaml index 08162ccee..9d73805eb 100644 --- a/lib/webchat.yaml +++ b/lib/webchat.yaml @@ -1,45 +1,40 @@ - base_path: /government/organisations/hm-revenue-customs/contact/child-benefit - open_url: https://www.tax.service.gov.uk/csp-partials/open/1027 - availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1027 + open_url: https://tax.service.gov.uk/ask-hmrc/webchat/child-benefit + availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006859&siteID=10006719&businessUnitID=19001235 + open_url_redirect: true - base_path: /government/organisations/hm-revenue-customs/contact/income-tax-enquiries-for-individuals-pensioners-and-employees - open_url: https://www.tax.service.gov.uk/csp-partials/open/1030 - availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1030 + open_url: https://tax.service.gov.uk/ask-hmrc/webchat/income-tax-enquiries-for-individuals-pensioners-and-employees + availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006852&siteID=10006719&businessUnitID=19001235 + open_url_redirect: true - base_path: /government/organisations/hm-revenue-customs/contact/vat-online-services-helpdesk - open_url: https://www.tax.service.gov.uk/csp-partials/open/1026 - availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1026 + open_url: https://tax.service.gov.uk/ask-hmrc/webchat/vat-online-services-helpdesk + availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006860&siteID=10006719&businessUnitID=19001235 + open_url_redirect: true - base_path: /government/organisations/hm-revenue-customs/contact/national-insurance-numbers - open_url: https://www.tax.service.gov.uk/csp-partials/open/1021 - availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1021 + open_url: https://tax.service.gov.uk/ask-hmrc/webchat/national-insurance-numbers + availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006855&siteID=10006719&businessUnitID=19001235 + open_url_redirect: true - base_path: /government/organisations/hm-revenue-customs/contact/self-assessment - open_url: https://www.tax.service.gov.uk/csp-partials/open/1004 - availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1004 + open_url: https://tax.service.gov.uk/ask-hmrc/webchat/self-assessment + availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006851&siteID=10006719&businessUnitID=19001235 + open_url_redirect: true - base_path: /government/organisations/hm-revenue-customs/contact/tax-credits-enquiries - open_url: https://www.tax.service.gov.uk/csp-partials/open/1016 - availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1016 + open_url: https://tax.service.gov.uk/ask-hmrc/webchat/tax-credits-enquiries + availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006858&siteID=10006719&businessUnitID=19001235 + open_url_redirect: true - base_path: /government/organisations/hm-revenue-customs/contact/vat-enquiries - open_url: https://www.tax.service.gov.uk/csp-partials/open/1028 - availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1028 + open_url: https://tax.service.gov.uk/ask-hmrc/webchat/vat-enquiries + availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006860&siteID=10006719&businessUnitID=19001235 + open_url_redirect: true - base_path: /government/organisations/hm-revenue-customs/contact/customs-international-trade-and-excise-enquiries - open_url: https://www.tax.service.gov.uk/csp-partials/open/1034 - availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1034 + open_url: https://tax.service.gov.uk/ask-hmrc/webchat/customs-international-trade-and-excise-enquiries + availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006861&siteID=10006719&businessUnitID=19001235 + open_url_redirect: true - base_path: /government/organisations/hm-revenue-customs/contact/employer-enquiries - open_url: https://www.tax.service.gov.uk/csp-partials/open/1023 - availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1023 + open_url: https://tax.service.gov.uk/ask-hmrc/webchat/employer-enquiries + availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006854&siteID=10006719&businessUnitID=19001235 + open_url_redirect: true - base_path: /government/organisations/hm-revenue-customs/contact/online-services-helpdesk - open_url: https://www.tax.service.gov.uk/csp-partials/open/1003 - availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1003 -- base_path: /government/organisations/hm-revenue-customs/contact/charities-and-community-amateur-sports-clubs-cascs - open_url: https://www.tax.service.gov.uk/csp-partials/open/1087 - availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1087 -- base_path: /government/organisations/hm-revenue-customs/contact/enquiries-from-employers-with-expatriate-employees - open_url: https://www.tax.service.gov.uk/csp-partials/open/1089 - availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1089 -- base_path: /government/organisations/hm-revenue-customs/contact/share-schemes-for-employees - open_url: https://www.tax.service.gov.uk/csp-partials/open/1088 - availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1088 -- base_path: /government/organisations/hm-revenue-customs/contact/non-uk-expatriate-employees-expats - open_url: https://www.tax.service.gov.uk/csp-partials/open/1089 - availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1089 -- base_path: /government/organisations/hm-revenue-customs/contact/non-resident-landlords - open_url: https://www.tax.service.gov.uk/csp-partials/open/1086 - availability_url: https://www.tax.service.gov.uk/csp-partials/availability/1086 + open_url: https://tax.service.gov.uk/ask-hmrc/webchat/online-services-helpdesk + availability_url: https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006856&siteID=10006719&businessUnitID=19001235 + open_url_redirect: true diff --git a/spec/javascripts/webchat.spec.js b/spec/javascripts/webchat.spec.js index 73d5bfba1..436cf4324 100644 --- a/spec/javascripts/webchat.spec.js +++ b/spec/javascripts/webchat.spec.js @@ -8,9 +8,9 @@ describe('Webchat', function () { // Stub analytics. GOVUK.analytics = GOVUK.analytics || {} GOVUK.analytics.trackEvent = function () {} - var CHILD_BENEFIT_API_URL = 'https://www.tax.service.gov.uk/csp-partials/open/' + - 1027 - var INSERTION_HOOK = '
' + + var CHILD_BENEFIT_API_URL = 'https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006859&siteID=10006719&businessUnitID=19001235' + + var INSERTION_HOOK = '
' + '
Error
' + '' + '' + @@ -68,7 +68,7 @@ describe('Webchat', function () { mount() expect( $.ajax - ).toHaveBeenCalledWith({ url: CHILD_BENEFIT_API_URL, type: 'GET', timeout: jasmine.any(Number), success: jasmine.any(Function), error: jasmine.any(Function) }) + ).toHaveBeenCalledWith({ url: CHILD_BENEFIT_API_URL, type: 'GET', dataType: "jsonp" ,timeout: jasmine.any(Number), success: jasmine.any(Function), error: jasmine.any(Function) }) }) it('should inform user whether advisors are available', function () { diff --git a/test/presenters/contact_presenter_test.rb b/test/presenters/contact_presenter_test.rb index 67ef8c498..2afb391ac 100644 --- a/test/presenters/contact_presenter_test.rb +++ b/test/presenters/contact_presenter_test.rb @@ -88,8 +88,8 @@ def schema_name schema = schema_item("contact_with_webchat") presented = present_example(schema) assert_equal true, presented.show_webchat? - assert_equal presented.webchat.availability_url, "https://www.tax.service.gov.uk/csp-partials/availability/1030" - assert_equal presented.webchat.open_url, "https://www.tax.service.gov.uk/csp-partials/open/1030" + assert_equal presented.webchat.availability_url, "https://hmrc-uk.digital.nuance.com/tagserver/launch/agentAvailability?agentGroupID=10006852&siteID=10006719&businessUnitID=19001235" + assert_equal presented.webchat.open_url, "https://tax.service.gov.uk/ask-hmrc/webchat/income-tax-enquiries-for-individuals-pensioners-and-employees" end end end