Skip to content

Commit

Permalink
Merge pull request #116 from navikt/NKS-1746
Browse files Browse the repository at this point in the history
chat v. 2
  • Loading branch information
EirikFladby authored Jun 25, 2024
2 parents c4421fb + b638deb commit 33f9932
Show file tree
Hide file tree
Showing 24 changed files with 1,055 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<aura:documentation>
<aura:description>Documentation</aura:description>
<aura:example name="ExampleName" ref="exampleComponentName" label="Label">
Example Description
</aura:example>
</aura:documentation>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<aura:component
implements="flexipage:availableForAllPageTypes, force:hasRecordId"
controller="NKS_ChatTranscriptService"
>
<aura:attribute name="loggingEnabled" type="boolean" default="true" />
<aura:attribute name="authenticated" type="boolean" default="false" />
<aura:attribute name="accountFields" type="String" />
<aura:attribute name="caseFields" type="String" />
<aura:attribute name="personFields" type="String" />
<aura:attribute name="copyPersonFields" type="String" />
<aura:attribute name="conversation" type="object[]" />
<aura:attribute name="subscription" type="Map" />
<aura:attribute name="chatRecord" type="Object" />
<aura:attribute name="recordLoadError" type="String" />

<lightning:conversationToolkitApi aura:id="chatToolkit" />
<lightning:workspaceAPI aura:id="workspace" />
<lightning:empApi aura:id="empApi" />

<aura:handler name="init" value="{!this}" action="{!c.onInit}" />

<force:recordData
aura:id="recordLoader"
recordId="{!v.recordId}"
fields="CRM_Authentication_Status__c"
targetFields="{!v.chatRecord}"
targetError="{!v.recordLoadError}"
/>

<c:nksChatAuthenticationInfoV2
recordId="{!v.recordId}"
loggingEnabled="{!v.loggingEnabled}"
onrequestauthentication="{!c.requestAuthentication}"
onauthenticationcomplete="{!c.handleAuthCompleted}"
aura:id="chatAuthInfo"
>
</c:nksChatAuthenticationInfoV2>
</aura:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<description>A Lightning Component Bundle</description>
</AuraDefinitionBundle>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.THIS {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<design:component label="Chat Authentication Container v. 2">
<design:attribute label="Enable logging to console" name="loggingEnabled" default="false" />
</design:component>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
({
onInit: function (component, event, helper) {
const empApi = component.find('empApi');
empApi.onError(
$A.getCallback((error) => {
console.error('EMP API error: ', JSON.stringify(error));
})
);
helper.subscribeEmpApi(component);
},

requestAuthentication: function (component, event) {
const chatToolkit = component.find('chatToolkit');
const recordId = component.get('v.recordId');
const authInfoCmp = component.find('chatAuthInfo');
let authUrl = event.getParam('authUrl');

chatToolkit
.sendMessage({
recordId: recordId,
message: {
text:
'Trykk for å logge inn på nav.no og gi veilederen tilgang til saken din. ' + authUrl + recordId
}
})
.then(function (result) {
authInfoCmp.authRequestHandling(result);
});
},

handleAuthCompleted: function (component, event, helper) {
helper.showLoginMsg(component, event);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
({
showLoginMsg: function (component, event) {
const chatToolkit = component.find('chatToolkit');
const recordId = component.get('v.recordId');
const loginMsg = event.getParam('loginMessage');

chatToolkit
.sendMessage({
recordId: recordId,
message: {
text: loginMsg
}
})
.then(function () {});
},

setTabIcon: function (component, newTabId, iconName, iconAlt) {
let workspace = component.find('workspace');
workspace.setTabIcon({
tabId: newTabId,
icon: iconName,
iconAlt: iconAlt
});
},

subscribeEmpApi: function (component) {
const empApi = component.find('empApi');
const channel = '/topic/Chat_Auth_Status_Changed';
const replayId = -1;

empApi
.subscribe(
channel,
replayId,
$A.getCallback((eventReceived) => {
this.onEmpApiEvent(component, eventReceived);
})
)
.then((subscription) => {
component.set('v.subscription', subscription);
});
},

unsubscribeEmpApi: function (component) {
const empApi = component.find('empApi');
const subscription = component.get('v.subscription');

empApi.unsubscribe(
subscription,
$A.getCallback(() => {
component.set('v.subscription', null);
})
);
},

onEmpApiEvent: function (component, eventReceived) {
const authStatus = eventReceived.data.sobject.CRM_Authentication_Status__c;
const changedRecordId = eventReceived.data.sobject.Id;
const recordId = component.get('v.recordId');

if (changedRecordId === recordId) {
component
.find('workspace')
.getEnclosingTabId()
.then((tabId) => {
if (authStatus === 'Completed') {
this.setTabIcon(component, tabId, 'utility:lock', 'Innlogget chat');
} else {
this.setTabIcon(component, tabId, 'standard:live_chat', 'Uinnlogget chat');
}
});
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
({
// Your renderer method overrides go here
});
2 changes: 1 addition & 1 deletion force-app/main/default/classes/ChatAuthController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public without sharing class ChatAuthController {
}

@AuraEnabled
public static string getCouncellorName(String recordId) {
public static string getCounselorName(String recordId) {
Id ownerId = [SELECT OwnerId FROM LiveChatTranscript WHERE Id = :recordId LIMIT 1]?.OwnerId;
String fullname = [SELECT NKS_FullName__c FROM User WHERE Id = :ownerId LIMIT 1]?.NKS_FullName__c;
return fullname;
Expand Down
4 changes: 2 additions & 2 deletions force-app/main/default/classes/ChatAuthController_Test.cls
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public class ChatAuthController_Test {
}

@isTest
static void testGetCouncellorName() {
static void testGetCounselorName() {
String fullname;
LiveChatTranscript chatTranscript = [SELECT Id FROM LiveChatTranscript LIMIT 1];

Test.startTest();
fullname = ChatAuthController.getCouncellorName(chatTranscript.Id);
fullname = ChatAuthController.getCounselorName(chatTranscript.Id);
Test.stopTest();

System.assert(String.isNotBlank(fullname));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
<allowPause>false</allowPause>
<fields>
<name>ErrorMessage</name>
<fieldText>&lt;p&gt;Noe gikk galt under fullføring av sladdingen&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Feilmelding:&lt;/p&gt;&lt;p&gt;{!Complete_Redaction.errorMessage}&lt;/p&gt;</fieldText>
<fieldText>
&lt;p&gt;Noe gikk galt under fullføring av
sladdingen&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Feilmelding:&lt;/p&gt;&lt;p&gt;{!Complete_Redaction.errorMessage}&lt;/p&gt;</fieldText>
<fieldType>DisplayText</fieldType>
</fields>
<showFooter>true</showFooter>
Expand Down Expand Up @@ -117,4 +119,4 @@
<isInput>true</isInput>
<isOutput>false</isOutput>
</variables>
</Flow>
</Flow>
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@
<allowPause>false</allowPause>
<fields>
<name>SomethingWentWrong</name>
<fieldText>&lt;p&gt;Noe gikk galt ved sladding av Boost samtalen.&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Feilmelding:&lt;/p&gt;&lt;p&gt;{!$Flow.FaultMessage}&lt;/p&gt;</fieldText>
<fieldText>
&lt;p&gt;Noe gikk galt ved sladding av Boost
samtalen.&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Feilmelding:&lt;/p&gt;&lt;p&gt;{!$Flow.FaultMessage}&lt;/p&gt;</fieldText>
<fieldType>DisplayText</fieldType>
</fields>
<showFooter>true</showFooter>
Expand Down Expand Up @@ -174,4 +176,4 @@
<isInput>true</isInput>
<isOutput>false</isOutput>
</variables>
</Flow>
</Flow>
58 changes: 48 additions & 10 deletions force-app/main/default/labels/CustomLabels.labels-meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,78 +6,116 @@
<language>en_US</language>
<protected>false</protected>
<shortDescription>Chat redaction Boost replacement text</shortDescription>
<value>Denne delen av samtalen har blitt slettet fordi den inneholdt informasjon som ikke kan behandles, forvaltes eller lagres av denne tjenesten.</value>
<value>Denne delen av samtalen har blitt slettet fordi den inneholdt informasjon som ikke
kan behandles, forvaltes eller lagres av denne tjenesten.</value>
</labels>
<labels>
<fullName>NKS_Chat_RedactionMessageText_NO</fullName>
<categories>NKS, STO, Chat, Redaction</categories>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Chat Redaction Message Text</shortDescription>
<value>Innhold i samtalen din har blitt slettet fordi den inneholdt informasjon som ikke kan behandles, forvaltes eller lagres av denne tjenesten.</value>
<value>Innhold i samtalen din har blitt slettet fordi den inneholdt informasjon som ikke kan
behandles, forvaltes eller lagres av denne tjenesten.</value>
</labels>
<labels>
<fullName>CRM_Chat_Authentication_Init_Failed</fullName>
<categories>UI, Chat, Authentication</categories>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Chat Authentication Init Failed</shortDescription>
<value>Kunne ikke igangsette autentisering. Hvis problemet vedvarer, kontakt din administrator.</value>
<value>Could not initiate authentication. If the problem persists, contact your
administrator.</value>
</labels>
<labels>
<fullName>CRM_Chat_Authentication_Requested</fullName>
<categories>UI, Chat, Authentication</categories>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Chat Authentication Requested</shortDescription>
<value>Autentiseringsforespørsel sendt</value>
<value>Authentication request sent</value>
</labels>
<labels>
<fullName>CRM_Chat_Authentication_Started</fullName>
<categories>UI, Chat, Authentication</categories>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Chat Authentication Started</shortDescription>
<value>Venter på at brukeren logger inn</value>
<value>Waiting for the user to log in</value>
</labels>
<labels>
<fullName>CRM_Chat_Identity_Confirmed</fullName>
<categories>UI, Chat, Authentication</categories>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Chat Identity Confirmed</shortDescription>
<value>Identitet bekreftet</value>
<value>Identity confirmed</value>
</labels>
<labels>
<fullName>CRM_Chat_Identity_Confirmed_Disclaimer</fullName>
<categories>UI, Chat, Authentication</categories>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Chat Identity Confirmed Disclaimer</shortDescription>
<value>Brukeren har bekreftet sin identitet</value>
<value>The user has confirmed their identity</value>
</labels>
<labels>
<fullName>CRM_Chat_Unconfirmed_Identity_Warning</fullName>
<categories>UI, Chat, Authentication</categories>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Chat Unconfirmed Identity Warning</shortDescription>
<value>Vær oppmerksom - brukeren har ikke bekreftet sin identitet</value>
<value>Please note - the user has not confirmed their identity</value>
</labels>
<labels>
<fullName>NKS_Chat_Login_Message_EN</fullName>
<categories>UI, Chat, Authentication</categories>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Chat Login Message EN</shortDescription>
<value>We advise you according to forvaltningsloven §11. To ensure your right to privacy, we ask you to only provide information regarding your case. The counsellor already has access to your case. The transcript will be stored and cannot be amended after completion. When the chat is over, you will find the transcript on Ditt NAV and it will be available to NAV for future case handling. You can read more about how NAV processes your personal data here (norwegian): https://www.nav.no/no/nav-og-samfunn/om-nav/personvern-i-arbeids-og-velferdsetaten</value>
<value>We advise you according to forvaltningsloven §11. To ensure your right to privacy, we
ask you to only provide information regarding your case. The counsellor already has
access to your case. The transcript will be stored and cannot be amended after
completion. When the chat is over, you will find the transcript on Ditt NAV and it will
be available to NAV for future case handling. You can read more about how NAV processes
your personal data here (norwegian):
https://www.nav.no/no/nav-og-samfunn/om-nav/personvern-i-arbeids-og-velferdsetaten</value>
</labels>
<labels>
<fullName>NKS_Chat_Login_Message_NO</fullName>
<categories>UI, Chat, Authentication</categories>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Chat Login Message NO</shortDescription>
<value>Vi veileder deg etter forvaltningsloven § 11. Av hensyn til personvern, ber vi deg om å kun gi oss opplysninger som gjelder det du kontakter oss om. Veilederen har allerede tilgang til saken din. Samtalen blir lagret og kan ikke endres senere. Når samtalen er avsluttet, finner du chatloggen på Ditt NAV og den vil være tilgjengelig for NAV i videre saksgang. Du kan lese mer om hvordan NAV behandler dine personopplysninger her: https://www.nav.no/no/nav-og-samfunn/om-nav/personvern-i-arbeids-og-velferdsetaten</value>
<value>Vi veileder deg etter forvaltningsloven § 11. Av hensyn til personvern, ber vi deg om
å kun gi oss opplysninger som gjelder det du kontakter oss om. Veilederen har allerede
tilgang til saken din. Samtalen blir lagret og kan ikke endres senere. Når samtalen er
avsluttet, finner du chatloggen på Ditt NAV og den vil være tilgjengelig for NAV i
videre saksgang. Du kan lese mer om hvordan NAV behandler dine personopplysninger her:
https://www.nav.no/no/nav-og-samfunn/om-nav/personvern-i-arbeids-og-velferdsetaten</value>
</labels>
<labels>
<fullName>NKS_Chat_Send_Authentication_Request</fullName>
<categories>UI, Chat, Authentication</categories>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Send authentication request</shortDescription>
<value>Send authentication request</value>
</labels>
<labels>
<fullName>NKS_Chat_Getting_Authentication_Status</fullName>
<categories>UI, Chat, Authentication</categories>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Getting Authentication Status</shortDescription>
<value>Getting authentication status</value>
</labels>
<labels>
<fullName>NKS_Chat_Sending_Authentication_Request</fullName>
<categories>UI, Chat, Authentication</categories>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Sending Authentication Request</shortDescription>
<value>Sending authentication request</value>
</labels>
</CustomLabels>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- Spinner while loading authentication information -->
<template if:true={isLoading}>
<div class="slds-var-p-top_small slds-var-p-bottom_small">
<lightning-spinner size="medium" title="Getting authentication status"> </lightning-spinner>
<lightning-spinner size="medium" title={labels.CHAT_GETTING_AUTH_STATUS}> </lightning-spinner>
</div>
</template>

Expand Down Expand Up @@ -36,10 +36,11 @@ <h2 role="alert">{labels.UNCONFIRMED_IDENTITY_WARNING}</h2>
<template if:false={authenticationRequested}>
<div class="slds-var-p-top_small">
<template if:true={sendingAuthRequest}>
<lightning-spinner size="small" title="Sending authentication request"> </lightning-spinner>
<lightning-spinner size="small" title={labels.CHAT_SENDING_AUTH_REQUEST}>
</lightning-spinner>
</template>
<lightning-button
label="Send autentiseringsforespørsel"
label={labels.SEND_AUTH_REQUEST}
disabled={cannotInitAuth}
variant="neutral"
onclick={requestAuthentication}
Expand Down
Loading

0 comments on commit 33f9932

Please sign in to comment.