@telia-ace/ace-chat-flamingo 1.1.123-rc.27 → 1.1.123-rc.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -1
- package/index.mjs +10 -7
- package/package.json +3 -3
- package/types.d.ts +2 -2
package/index.js
CHANGED
|
@@ -2244,4 +2244,4 @@ Please report this to https://github.com/markedjs/marked.`,n){const i="<p>An err
|
|
|
2244
2244
|
border: 1px solid var(--border-color-medium);
|
|
2245
2245
|
box-sizing: border-box;
|
|
2246
2246
|
}
|
|
2247
|
-
`];let en=Qs;hp([de({context:ae}),k({attribute:!1})],en.prototype,"application");window.customElements.get("ace-video-iframe")||window.customElements.define("ace-video-iframe",en);class As extends wc{constructor(e,t){var i,s,r,o,a,c;super(e,t),this.pendingMessages=[],this.texts=this.component.application.texts,this.headerComponent=this.component.application.getComponent("widget-header"),this.isThirdPartyParticipant=this.component.properties.chat.isThirdPartyWidget,this.agent=this.createAgent(((i=this.component.application.storage.get("agentInfo"))==null?void 0:i.name)||""),this.user=this.createUser(((s=this.component.application.storage.get("userInfo"))==null?void 0:s.name)||""),this.params=new URLSearchParams(document.location.search),this.invitationUid=this.params.get("invitationUid"),this.customerName=this.params.get("customerName")||void 0,this.idHubUrl="https://idhub.dev-se.telia-ck8s.com/idhub-gateway/public",this.disconnected$=new P,this.agentUsername=null,this.conversationOption=null,this._conversationOptions={},this.sessionId=null,this.contactId=null,this.errand=null,this.entrance=null,this.guestId=null,this.chatOverlayActive=!1,this.inVideoCall=!1,this.onQueueStatusReceived=l=>{this.setQueueStatus(l.text||null)},this.onEstablished=l=>{this.contactId=l.contactId,this.errand=l.errand,this.entrance=l.entrance,this.agentUsername=l.agentUsername;const u={contactId:this.contactId,errand:this.errand,entrance:this.entrance,agentUsername:this.agentUsername};this.save({survey:u}),this.setQueueStatus(null),this.agent.name=l.agentAlias,this.component.application.storage.set("agentInfo",{name:this.agent.name}),l.videoEnded&&this.removeVideo()},this.onPrepareVideo=()=>{this.showVideoConfirmDialog()},this.onVideoPrepared=l=>{this.showVideoIFrame(l.userUrl)},this.onChatButtonClicked=l=>{this.showChatOverVideo(l.guestId)},this.onEndVideoButtonClicked=l=>{this.guestId&&(l==null?void 0:l.guestId)===this.guestId&&this.removeVideo()},this.onPenStatusChange=l=>{l.penStatus==="on"?this.setTypingState(!0):this.setTypingState(!1)},this.onChatEnded=async l=>{var p,d;this.shouldUseAuth&&this.endAuthenticatedSession(),this.setToastMessage(null),this.setTypingState(!1),this.videoConfirmDialogEntry&&this.videoConfirmDialogEntry.remove(),this.component.disableInput(),l.showForm&&this.showConversationEndedForm();const u=this.component.application.settings;(p=u==null?void 0:u.survey)!=null&&p.shouldUseSurvey&&((d=u==null?void 0:u.survey)!=null&&d.surveyBaseUrl)&&this.showSurvey(),this.isThirdPartyParticipant?this.removeHeaderOptions():this.setStartNewChatOption(),this.complete()},this.properties=t.properties,this.shouldUseAuth=(o=(r=this.component.application.settings)==null?void 0:r.auth)==null?void 0:o.shouldUseAuth,this.idHubEidType=(c=(a=this.component.application.settings)==null?void 0:a.auth)==null?void 0:c.idHubEidType.toLowerCase()}connect(e={}){super.connect(),this.setupAuthenticationListeners(),this._conversationOptions=e;const t={...this.properties.chat??{},...e},i=!!this.sessionId;if(!i){const r=Ki();this.setSessionId(r)}this.save({chatSessionId:this.sessionId}),this.engine=new Gd(t,this.sessionId),this.engine.messages().subscribe(r=>{switch(r.source){case"agent":this.printAgent(r.text);break;case"customer":this.clearPendingMessages(),this.isThirdPartyParticipant?r.source==="customer"&&r.invitationNo==="0"?this.printAgent(r.text,r.alias):this.printUser(r.text):r.source==="customer"&&Number(r.invitationNo)>0?this.printAgent(r.text,r.alias):this.printUser(r.text);break;case"system":this.printSystem(r.text);break}}),this.engine.actions().pipe(H(this.disconnected$),W(Ud)).subscribe(this.onQueueStatusReceived),this.engine.actions().pipe(H(this.disconnected$),W(Dd)).subscribe(this.onEstablished),this.engine.actions().pipe(H(this.disconnected$),W(zd)).subscribe(this.onPrepareVideo),this.engine.actions().pipe(H(this.disconnected$),W(jd)).subscribe(this.onVideoPrepared),this.engine.actions().pipe(H(this.disconnected$),W(Fd)).subscribe(this.onChatButtonClicked),this.engine.actions().pipe(H(this.disconnected$),W(Bd)).subscribe(this.onEndVideoButtonClicked),this.engine.actions().pipe(H(this.disconnected$),W(Hd)).subscribe(this.onPenStatusChange),this.engine.actions().pipe(H(this.disconnected$),W(qd)).subscribe(this.onChatEnded),this.setHeaderOption();const s=this.component.application.trigger;s&&s.widgetActive$.pipe(H(s.componentIsDestroyed$)).subscribe(r=>{r&&(this.conversationOption=null,this.setHeaderOption())}),this.component.userTyping$.pipe(H(this.disconnected$)).subscribe(r=>{var o;(o=this.engine)==null||o.sendPenStatusOn(r)}),i?this.engine.rehydrate().then(r=>{var o;r?(o=this.engine)==null||o.reconnect().pipe(H(this.disconnected$)).subscribe({error:a=>{console.error("Failed to reconnect to the engine:",a)}}):this.initializeChat(t).catch(a=>{console.error("Failed to initialize chat during rehydration:",a)})}):this.initializeChat(t).catch(r=>{console.error("Failed to initialize chat:",r)})}disconnected(){super.disconnected(),this.disconnected$.next()}onUserSubmit(e){const t=this.printUser(e.text);t.setStatus("pending"),this.pendingMessages.push(t),(async()=>{var i;try{await((i=this.engine)==null?void 0:i.chatWrite(e.text))}catch(s){s instanceof Fn?t.setStatus("failed"):(t.setStatus("failed"),console.warn("Unhandled error:",s))}})()}save(e){this.component.stateMachine.session().pipe(Oe(t=>(t==null?void 0:t.data$)||tt),me(1)).subscribe(t=>{this.saveToCurrentSession$.next({...t,...e})})}async rehydrate(e){if(e.chatSessionId&&this.setSessionId(e.chatSessionId),e.survey&&(this.contactId=e.survey.contactId,this.errand=e.survey.errand,this.entrance=e.survey.entrance,this.agentUsername=e.survey.agentUsername),this.shouldUseAuth){const t=this.component.application.storage.get("auth");t!=null&&t.authenticated?this.component.setAuthenticationBannerStatus(Z.Authenticated):this.component.setAuthenticationBannerStatus(Z.NonAuthenticated)}}static getInstance(e,t){return t.providerInstance??(t.providerInstance=new As(e,t)),t.providerInstance}async initializeChat(e){this.shouldUseAuth&&this.idHubEidType?(this.component.setAuthenticationBannerStatus(Z.NonAuthenticated),this.setupIDHubAuth(),this.idHubClient&&await this.startAuthenticationFlow()):this.handleWelcomeForm(e)}setupAuthenticationListeners(){var e;this.shouldUseAuth&&this.headerComponent&&this.headerComponent.actions$&&((e=this.headerComponent)==null||e.actions$.pipe(W(t=>t.key==="start-auth"),H(this.disconnected$)).subscribe(t=>{t.key==="start-auth"&&this.handleAuthentication()}))}setupIDHubAuth(){var e;this.idHubClient=new Bt({...(e=this.component.application.settings)==null?void 0:e.auth,idHubUrl:this.idHubUrl})}async startAuthenticationFlow(e=!1){if(this.component.disableInput(),e||(this.resetAuthState(Z.NonAuthenticated),this.authResult=await this.getAuthResult()),!!this.authResult)switch(this.idHubEidType){case Te.Tunnistus:if(!this.authResult.tunnistusURL){this.printSystem(this.texts.getOrFallback("auth.setup.tunnistus.url-error-message","Unable to retrieve the Tunnistus authentication URL.")),this.headerComponent.showAuthOptions=!1;return}this.headerComponent.authUrl=this.authResult.tunnistusURL,this.headerComponent.authState=Z.NonAuthenticated,e?this.handleAuthentication():(this.authenticationCardEntry=this.showTunnistusAuthCard(Ze.Initial,this.authResult.tunnistusURL),this.authenticationCardEntry.actions$.pipe(W(t=>t.key==="start-auth"),me(1)).subscribe(()=>{this.handleAuthentication()}));break;case Te.BankId:break}}async getAuthResult(){const e=await this.idHubClient.auth();if(e.status===z.Error){this.printSystem(this.texts.getOrFallback("auth.setup.error-message","An error occurred while setting up authentication.")),this.headerComponent.showAuthOptions=!1;return}return e}async handleWelcomeForm(e,t){let i=!0;if(e.webApiUrl)try{i=await this.isEntranceOpen(e.webApiUrl,e.entrance)}catch(s){console.error("Error checking entrance status:",s),i=!1}i?this.customerName?(this.user.name=this.customerName,this.startChat({customerName:this.customerName,customData:{}},t)):this.showWelcomeForm(t):this.showEntranceClosedDialog()}startChat(e,t){if(!this.engine)return;const i=e.customData.errand??this.engine.config.defaultErrand;if(!i)throw new Error("Errand is required but was not configured");this.isThirdPartyParticipant?(this.component.application.root.style.visibility="visible",this.engine.chatJoin({invitationUid:this.invitationUid,customerName:this.customerName??e.customerName}).pipe(H(this.disconnected$)).subscribe()):this.engine.chatRequest({customerName:e.customerName,customerEmailAddress:e.customerEmailAddress??"",visitorQuestion:e.visitorQuestion??"",customData:e.customData,errand:i,...t&&{authToken:t}}).pipe(H(this.disconnected$)).subscribe(),this.component.enableInput(),this.component.enableSkipToLatestMessage(),this.setEndConversationOption()}restartNewChat(){this.engine&&(this.setSessionId(null),this.component.clearMessages(),this.removeHeaderOptions(),this.connect(this._conversationOptions))}setQueueStatus(e){this.setToastMessage(e)}async endConversation(){var e;this.shouldUseAuth&&this.resetAuthState(Z.ChatEnded),await((e=this.engine)==null?void 0:e.chatQuit())}async sendConversationEmail(e){var t;try{await((t=this.engine)==null?void 0:t.chatEmailSession(e)),this.printSystem(this.texts.getOrFallback("email-form.email-sent-label","An email with the conversation was sent."))}catch(i){this.printSystem(this.texts.getOrFallback("email-form.error-message","Unable to send email with the conversation.")),i instanceof Fn||console.warn("Unhandled error:",i)}}clearPendingMessages(){this.pendingMessages.forEach(e=>{e.remove()})}setSessionId(e){this.sessionId=e}async isEntranceOpen(e,t){var s;let i=!1;try{const r=await fetch(`${e}/1/entrances/${t}/is-open`),o=await r.json();r.ok?i=(s=o==null?void 0:o.resultData)==null?void 0:s.isOpen:console.log(`Problem when fetching open status for entrance ${t}:`,o==null?void 0:o.resultMessage)}catch(r){console.log(`Failed to fetch open status for ${t}:`,r)}return i}resetAuthState(e){this.headerComponent.authState=e,this.headerComponent.userName="",this.headerComponent.authUrl="",e===Z.ChatEnded&&(this.authResult=void 0),this.component.application.storage.removeItem("auth")}unescapeHtml(e){const t=document.createElement("textarea");return t.innerHTML=e,t.value}async handleAuthentication(){var t,i,s,r;this.headerComponent.userName=this.texts.getOrFallback("widget-header.authenticating","Authenticating..."),this.headerComponent.authState=Z.Authenticating;const e=await this.idHubClient.collect();switch(this.authenticationCardEntry&&this.authenticationCardEntry.remove(),this.idHubEidType){case Te.Tunnistus:if(e.status===z.Error){if(this.authResult=await this.getAuthResult(),!this.authResult)return;this.headerComponent.userName=this.texts.getOrFallback("widget-header.not-authenticated","Not authenticated"),this.headerComponent.authState=Z.NonAuthenticated,this.headerComponent.authUrl=this.authResult.tunnistusURL,this.authenticationCardEntry=this.showTunnistusAuthCard(Ze.Error,this.authResult.tunnistusURL),this.authenticationCardEntry.actions$.pipe(W(o=>o.key==="start-auth"),me(1)).subscribe(async()=>{this.startAuthenticationFlow(!0)});return}else if(e.status===z.Authenticated){const o=Wd(((t=e==null?void 0:e.idhubEIDToken)==null?void 0:t.split(".")[1])??""),a=JSON.parse(o),c=((s=(i=a==null?void 0:a.completionData)==null?void 0:i.user)==null?void 0:s.name)??"";this.headerComponent.userName=c,this.headerComponent.authState=Z.Authenticated,this.component.application.storage.set("auth",{name:c,authenticated:!0}),this.component.setAuthenticationBannerStatus(Z.Authenticated),(r=this.authenticationCardEntry)==null||r.remove(),this.handleWelcomeForm(this.engine.config,e.idhubEIDToken)}break;case Te.BankId:break}}printAgent(e,t=""){const i=t.length>0?this.agent.print(e,"markdown",t):this.agent.print(e,"markdown");return this.setTypingState(!1),i}printUser(e){const t=this.unescapeHtml(e),i=Ni(Tr(t));return this.user.print(i)}printSystem(e){const t=Ni(Tr(e));return this.system.print(t)}showSurvey(){const e=new ie(q.System,{name:""},[{items:[["ace-survey",{content:""},{agentUsername:this.agentUsername??"",entrance:this.entrance??this.engine.config.entrance,errand:this.errand??this.engine.config.defaultErrand,contactId:this.contactId??""}]]}]);this.printEntry(e)}showTunnistusAuthCard(e,t,i){const s=new ie(q.System,{name:""},[{items:[["ace-tunnistus-auth-card",{content:""},{state:e,tunnistusURL:t??"",errorMessage:i??""}]]}]);return this.printEntry(s),s}showWelcomeForm(e){this.component.disableInput(),this.component.disableSkipToLatestMessage();let t;this.isThirdPartyParticipant?t=new ie(q.System,{name:""},[{items:[["ace-welcome-form-third-party",{content:""}]]}]):t=new ie(q.System,{name:""},[{items:[["ace-welcome-form",{content:""}]]}]),this.printEntry(t),t.actions$.pipe(W(i=>i.key==="submitted"),me(1)).subscribe(i=>{t.remove(),this.user.name=i.data.name,this.component.application.storage.set("userInfo",{name:this.user.name}),this.startChat({customerName:i.data.name,customerEmailAddress:i.data.email,visitorQuestion:i.data.question,customData:i.data.customData},e)})}showEntranceClosedDialog(){this.component.disableInput();const e=new ie(q.System,{name:""},[{items:[["ace-entrance-closed-dialog",{content:""}]]}]);this.printEntry(e)}showQuitConfirmDialog(){var e;(e=this.quitConfirmDialogEntry)==null||e.remove(),this.quitConfirmDialogEntry=new ie(q.System,{name:""},[{items:[["ace-quit-confirm-dialog",{content:""}]]}]),this.printEntry(this.quitConfirmDialogEntry),this.quitConfirmDialogEntry.actions$.pipe(W(t=>t.key==="quit-chat"),me(1)).subscribe(t=>{var i,s,r,o;((i=t.data)==null?void 0:i.result)==="quit"?(this.endConversation(),(s=this.quitConfirmDialogEntry)==null||s.remove()):((r=t.data)==null?void 0:r.result)==="cancel"&&((o=this.quitConfirmDialogEntry)==null||o.remove())})}showConversationEndedForm(){const e=new ie(q.System,{name:""},[{items:[["ace-conversation-ended-form",{content:""}]]}]);this.printEntry(e),e.actions$.pipe(W(t=>t.key==="submitted"),me(1)).subscribe(t=>{e.remove(),t.data.email&&this.sendConversationEmail(t.data.email)})}showVideoConfirmDialog(){this.videoConfirmDialogEntry=new ie(q.System,{name:""},[{items:[["ace-video-confirm-dialog",{content:""}]]}]),this.printEntry(this.videoConfirmDialogEntry),this.videoConfirmDialogEntry.actions$.pipe(W(e=>e.key==="video-confirm"),me(1)).subscribe(e=>{var t;this.videoConfirmDialogEntry&&this.videoConfirmDialogEntry.remove(),e.data.result==="declined"&&(this.guestId=null),(t=this.engine)==null||t.videoPrepared(e.data.result),this.printSystem(e.data.text)})}showVideoIFrame(e){var i;this.guestId=Ki(),this.videoIFrameElement=new en(e,this.guestId);const t=this.component.application.root;(i=t==null?void 0:t.shadowRoot)==null||i.prepend(this.videoIFrameElement),this.inVideoCall=!0,this.setHeaderOption()}showChatOverVideo(e){this.guestId&&e===this.guestId&&(this.chatOverlayActive=!0,this.showChatOverlay$.next(this.chatOverlayActive))}async endAuthenticatedSession(){this.component.setAuthenticationBannerStatus(Z.NonAuthenticated),await this.engine.getChatStatus()==="noSession"?(this.resetAuthState(Z.NonAuthenticated),this.setSessionId(null),this.component.clearMessages(),this.shouldUseAuth&&this.startAuthenticationFlow()):this.endConversation()}removeVideo(){var e;(e=this.videoIFrameElement)==null||e.remove(),this.guestId=null,this.chatOverlayActive&&(this.chatOverlayActive=!1,this.showChatOverlay$.next(this.chatOverlayActive)),this.inVideoCall=!1,this.setHeaderOption()}addHeaderOptions(e,t,i,s,r=!0){const o=this.component.application.getComponent("widget-header");if(o)return this.conversationOption?(this.conversationOption.label=e,this.conversationOption.key=t,this.conversationOption.icon=i,this.conversationOption.onClick=s,this.conversationOption.enabled=r,o.requestUpdate(),this.conversationOption):o.addOption({label:e,icon:i,closeOnClick:!0,key:t,onClick:s,enabled:r})}removeHeaderOptions(){const e=this.component.application.getComponent("widget-header");e&&e.removeOption(this.conversationOption)}setStartNewChatOption(){this.conversationOption=this.addHeaderOptions(this.texts.getOrFallback("widget-header.start-new-chat","Start new chat"),"start-new-chat-button",sa.svg,()=>{this.restartNewChat()})}setEndConversationOption(){this.conversationOption=this.addHeaderOptions(this.texts.getOrFallback("widget-header.end-conversation","End conversation"),"end-conversation-button",ia.svg,()=>{this.showQuitConfirmDialog()},!this.inVideoCall)}async setHeaderOption(){switch(await this.engine.getChatStatus()){case"finished":this.isThirdPartyParticipant?this.removeHeaderOptions():this.setStartNewChatOption();break;case"active":this.setEndConversationOption();break;case"noSession":this.conversationOption=null}}}const dp=async n=>{(await rs.getInstance(n.container)).registerProvider("ace-chat",t=>As.getInstance("ace-chat",t))};exports.ChatProviderPlugin=dp;
|
|
2247
|
+
`];let en=Qs;hp([de({context:ae}),k({attribute:!1})],en.prototype,"application");window.customElements.get("ace-video-iframe")||window.customElements.define("ace-video-iframe",en);class As extends wc{constructor(e,t){var i,s,r,o,a,c;super(e,t),this.pendingMessages=[],this.texts=this.component.application.texts,this.headerComponent=this.component.application.getComponent("widget-header"),this.isThirdPartyParticipant=this.component.properties.chat.isThirdPartyWidget,this.agent=this.createAgent(((i=this.component.application.storage.get("agentName"))==null?void 0:i.name)||""),this.user=this.createUser(((s=this.component.application.storage.get("userName"))==null?void 0:s.name)||""),this.params=new URLSearchParams(document.location.search),this.invitationUid=this.params.get("invitationUid"),this.customerName=this.params.get("customerName")||void 0,this.idHubUrl="https://idhub.dev-se.telia-ck8s.com/idhub-gateway/public",this.disconnected$=new P,this.agentUsername=null,this.conversationOption=null,this._conversationOptions={},this.sessionId=null,this.contactId=null,this.errand=null,this.entrance=null,this.guestId=null,this.chatOverlayActive=!1,this.inVideoCall=!1,this.onQueueStatusReceived=l=>{this.setQueueStatus(l.text||null)},this.onEstablished=l=>{this.contactId=l.contactId,this.errand=l.errand,this.entrance=l.entrance,this.agentUsername=l.agentUsername;const u={contactId:this.contactId,errand:this.errand,entrance:this.entrance,agentUsername:this.agentUsername};this.save({survey:u}),this.setQueueStatus(null),this.agent.name=l.agentAlias,this.component.application.storage.set("agentName",{name:this.agent.name}),l.videoEnded&&this.removeVideo()},this.onPrepareVideo=()=>{this.showVideoConfirmDialog()},this.onVideoPrepared=l=>{this.showVideoIFrame(l.userUrl)},this.onChatButtonClicked=l=>{this.showChatOverVideo(l.guestId)},this.onEndVideoButtonClicked=l=>{this.guestId&&(l==null?void 0:l.guestId)===this.guestId&&this.removeVideo()},this.onPenStatusChange=l=>{l.penStatus==="on"?this.setTypingState(!0):this.setTypingState(!1)},this.onChatEnded=async l=>{var p,d;this.shouldUseAuth&&this.endAuthenticatedSession(),this.setToastMessage(null),this.setTypingState(!1),this.videoConfirmDialogEntry&&this.videoConfirmDialogEntry.remove(),this.component.disableInput(),l.showForm&&this.showConversationEndedForm();const u=this.component.application.settings;(p=u==null?void 0:u.survey)!=null&&p.shouldUseSurvey&&((d=u==null?void 0:u.survey)!=null&&d.surveyBaseUrl)&&this.showSurvey(),this.isThirdPartyParticipant?this.removeHeaderOptions():this.setStartNewChatOption(),this.complete()},this.properties=t.properties,this.shouldUseAuth=(o=(r=this.component.application.settings)==null?void 0:r.auth)==null?void 0:o.shouldUseAuth,this.idHubEidType=(c=(a=this.component.application.settings)==null?void 0:a.auth)==null?void 0:c.idHubEidType.toLowerCase()}connect(e={}){super.connect(),this.setupAuthenticationListeners(),this._conversationOptions=e;const t={...this.properties.chat??{},...e},i=!!this.sessionId;if(!i){const r=Ki();this.setSessionId(r)}this.save({chatSessionId:this.sessionId}),this.engine=new Gd(t,this.sessionId),this.engine.messages().subscribe(r=>{switch(r.source){case"agent":this.printAgent(r.text);break;case"customer":this.clearPendingMessages(),this.isThirdPartyParticipant?r.source==="customer"&&r.invitationNo==="0"?this.printAgent(r.text,r.alias):this.printUser(r.text):r.source==="customer"&&Number(r.invitationNo)>0?this.printAgent(r.text,r.alias):this.printUser(r.text);break;case"system":this.printSystem(r.text);break}}),this.engine.actions().pipe(H(this.disconnected$),W(Ud)).subscribe(this.onQueueStatusReceived),this.engine.actions().pipe(H(this.disconnected$),W(Dd)).subscribe(this.onEstablished),this.engine.actions().pipe(H(this.disconnected$),W(zd)).subscribe(this.onPrepareVideo),this.engine.actions().pipe(H(this.disconnected$),W(jd)).subscribe(this.onVideoPrepared),this.engine.actions().pipe(H(this.disconnected$),W(Fd)).subscribe(this.onChatButtonClicked),this.engine.actions().pipe(H(this.disconnected$),W(Bd)).subscribe(this.onEndVideoButtonClicked),this.engine.actions().pipe(H(this.disconnected$),W(Hd)).subscribe(this.onPenStatusChange),this.engine.actions().pipe(H(this.disconnected$),W(qd)).subscribe(this.onChatEnded),this.setHeaderOption();const s=this.component.application.trigger;s&&s.widgetActive$.pipe(H(s.componentIsDestroyed$)).subscribe(r=>{r&&(this.conversationOption=null,this.setHeaderOption())}),this.component.userTyping$.pipe(H(this.disconnected$)).subscribe(r=>{var o;(o=this.engine)==null||o.sendPenStatusOn(r)}),i?this.engine.rehydrate().then(r=>{var o;r?(o=this.engine)==null||o.reconnect().pipe(H(this.disconnected$)).subscribe({error:a=>{console.error("Failed to reconnect to the engine:",a)}}):this.initializeChat(t).catch(a=>{console.error("Failed to initialize chat during rehydration:",a)})}):this.initializeChat(t).catch(r=>{console.error("Failed to initialize chat:",r)})}disconnected(){super.disconnected(),this.disconnected$.next()}onUserSubmit(e){const t=this.printUser(e.text);t.setStatus("pending"),this.pendingMessages.push(t),(async()=>{var i;try{await((i=this.engine)==null?void 0:i.chatWrite(e.text))}catch(s){s instanceof Fn?t.setStatus("failed"):(t.setStatus("failed"),console.warn("Unhandled error:",s))}})()}save(e){this.component.stateMachine.session().pipe(Oe(t=>(t==null?void 0:t.data$)||tt),me(1)).subscribe(t=>{this.saveToCurrentSession$.next({...t,...e})})}async rehydrate(e){if(e.chatSessionId&&this.setSessionId(e.chatSessionId),e.survey&&(this.contactId=e.survey.contactId,this.errand=e.survey.errand,this.entrance=e.survey.entrance,this.agentUsername=e.survey.agentUsername),this.shouldUseAuth){const t=this.component.application.storage.get("auth");t!=null&&t.authenticated?this.component.setAuthenticationBannerStatus(Z.Authenticated):this.component.setAuthenticationBannerStatus(Z.NonAuthenticated)}}static getInstance(e,t){return t.providerInstance??(t.providerInstance=new As(e,t)),t.providerInstance}async initializeChat(e){const t=await this.isEntranceOpen(e.webApiUrl,e.entrance);t||(this.headerComponent.showAuthOptions=!1),t&&this.shouldUseAuth&&this.idHubEidType?(this.component.setAuthenticationBannerStatus(Z.NonAuthenticated),this.setupIDHubAuth(),this.idHubClient&&await this.startAuthenticationFlow()):this.handleWelcomeForm(e,void 0,t)}setupAuthenticationListeners(){var e;this.shouldUseAuth&&this.headerComponent&&this.headerComponent.actions$&&((e=this.headerComponent)==null||e.actions$.pipe(W(t=>t.key==="start-auth"),H(this.disconnected$)).subscribe(t=>{t.key==="start-auth"&&this.handleAuthentication()}))}setupIDHubAuth(){var e;this.idHubClient=new Bt({...(e=this.component.application.settings)==null?void 0:e.auth,idHubUrl:this.idHubUrl})}async startAuthenticationFlow(e=!1){if(this.component.disableInput(),e||(this.resetAuthState(Z.NonAuthenticated),this.authResult=await this.getAuthResult()),!!this.authResult)switch(this.idHubEidType){case Te.Tunnistus:if(!this.authResult.tunnistusURL){this.printSystem(this.texts.getOrFallback("auth.setup.tunnistus.url-error-message","Unable to retrieve the Tunnistus authentication URL.")),this.headerComponent.showAuthOptions=!1;return}this.headerComponent.authUrl=this.authResult.tunnistusURL,this.headerComponent.authState=Z.NonAuthenticated,e?this.handleAuthentication():(this.authenticationCardEntry=this.showTunnistusAuthCard(Ze.Initial,this.authResult.tunnistusURL),this.authenticationCardEntry.actions$.pipe(W(t=>t.key==="start-auth"),me(1)).subscribe(()=>{this.handleAuthentication()}));break;case Te.BankId:break}}async getAuthResult(){const e=await this.idHubClient.auth();if(e.status===z.Error){this.printSystem(this.texts.getOrFallback("auth.setup.error-message","An error occurred while setting up authentication.")),this.headerComponent.showAuthOptions=!1;return}return e}async handleWelcomeForm(e,t,i=!0){if(e.webApiUrl)try{i=await this.isEntranceOpen(e.webApiUrl,e.entrance)}catch(s){console.error("Error checking entrance status:",s),i=!1}i?this.customerName?(this.user.name=this.customerName,this.startChat({customerName:this.customerName,customData:{}},t)):this.showWelcomeForm(t):this.showEntranceClosedDialog()}startChat(e,t){if(!this.engine)return;const i=e.customData.errand??this.engine.config.defaultErrand;if(!i)throw new Error("Errand is required but was not configured");this.isThirdPartyParticipant?(this.component.application.root.style.visibility="visible",this.engine.chatJoin({invitationUid:this.invitationUid,customerName:this.customerName??e.customerName}).pipe(H(this.disconnected$)).subscribe()):this.engine.chatRequest({customerName:e.customerName,customerEmailAddress:e.customerEmailAddress??"",visitorQuestion:e.visitorQuestion??"",customData:e.customData,errand:i,...t&&{authToken:t}}).pipe(H(this.disconnected$)).subscribe(),this.component.enableInput(),this.component.enableSkipToLatestMessage(),this.setEndConversationOption()}restartNewChat(){this.engine&&(this.setSessionId(null),this.component.clearMessages(),this.removeHeaderOptions(),this.connect(this._conversationOptions))}setQueueStatus(e){this.setToastMessage(e)}async endConversation(){var e;this.shouldUseAuth&&this.resetAuthState(Z.ChatEnded),await((e=this.engine)==null?void 0:e.chatQuit())}async sendConversationEmail(e){var t;try{await((t=this.engine)==null?void 0:t.chatEmailSession(e)),this.printSystem(this.texts.getOrFallback("email-form.email-sent-label","An email with the conversation was sent."))}catch(i){this.printSystem(this.texts.getOrFallback("email-form.error-message","Unable to send email with the conversation.")),i instanceof Fn||console.warn("Unhandled error:",i)}}clearPendingMessages(){this.pendingMessages.forEach(e=>{e.remove()})}setSessionId(e){this.sessionId=e}async isEntranceOpen(e,t){var s;let i=!1;try{const r=await fetch(`${e}/1/entrances/${t}/is-open`),o=await r.json();r.ok?i=(s=o==null?void 0:o.resultData)==null?void 0:s.isOpen:console.log(`Problem when fetching open status for entrance ${t}:`,o==null?void 0:o.resultMessage)}catch(r){console.log(`Failed to fetch open status for ${t}:`,r)}return i}resetAuthState(e){this.headerComponent.authState=e,this.headerComponent.userName="",this.headerComponent.authUrl="",e===Z.ChatEnded&&(this.authResult=void 0),this.component.application.storage.removeItem("auth")}unescapeHtml(e){const t=document.createElement("textarea");return t.innerHTML=e,t.value}async handleAuthentication(){var t,i,s,r;this.headerComponent.userName=this.texts.getOrFallback("widget-header.authenticating","Authenticating..."),this.headerComponent.authState=Z.Authenticating;const e=await this.idHubClient.collect();switch(this.authenticationCardEntry&&this.authenticationCardEntry.remove(),this.idHubEidType){case Te.Tunnistus:if(e.status===z.Error){if(this.authResult=await this.getAuthResult(),!this.authResult)return;this.headerComponent.userName=this.texts.getOrFallback("widget-header.not-authenticated","Not authenticated"),this.headerComponent.authState=Z.NonAuthenticated,this.headerComponent.authUrl=this.authResult.tunnistusURL,this.authenticationCardEntry=this.showTunnistusAuthCard(Ze.Error,this.authResult.tunnistusURL),this.authenticationCardEntry.actions$.pipe(W(o=>o.key==="start-auth"),me(1)).subscribe(async()=>{this.startAuthenticationFlow(!0)});return}else if(e.status===z.Authenticated){const o=Wd(((t=e==null?void 0:e.idhubEIDToken)==null?void 0:t.split(".")[1])??""),a=JSON.parse(o),c=((s=(i=a==null?void 0:a.completionData)==null?void 0:i.user)==null?void 0:s.name)??"";this.headerComponent.userName=c,this.headerComponent.authState=Z.Authenticated,this.component.application.storage.set("auth",{name:c,authenticated:!0}),this.component.setAuthenticationBannerStatus(Z.Authenticated),(r=this.authenticationCardEntry)==null||r.remove(),this.handleWelcomeForm(this.engine.config,e.idhubEIDToken)}break;case Te.BankId:break}}printAgent(e,t=""){const i=t.length>0?this.agent.print(e,"markdown",t):this.agent.print(e,"markdown");return this.setTypingState(!1),i}printUser(e){const t=this.unescapeHtml(e),i=Ni(Tr(t));return this.user.print(i)}printSystem(e){const t=Ni(Tr(e));return this.system.print(t)}showSurvey(){const e=new ie(q.System,{name:""},[{items:[["ace-survey",{content:""},{agentUsername:this.agentUsername??"",entrance:this.entrance??this.engine.config.entrance,errand:this.errand??this.engine.config.defaultErrand,contactId:this.contactId??""}]]}]);this.printEntry(e)}showTunnistusAuthCard(e,t,i){const s=new ie(q.System,{name:""},[{items:[["ace-tunnistus-auth-card",{content:""},{state:e,tunnistusURL:t??"",errorMessage:i??""}]]}]);return this.printEntry(s),s}showWelcomeForm(e){this.component.disableInput(),this.component.disableSkipToLatestMessage();let t;this.isThirdPartyParticipant?t=new ie(q.System,{name:""},[{items:[["ace-welcome-form-third-party",{content:""}]]}]):t=new ie(q.System,{name:""},[{items:[["ace-welcome-form",{content:""}]]}]),this.printEntry(t),t.actions$.pipe(W(i=>i.key==="submitted"),me(1)).subscribe(i=>{t.remove(),this.user.name=i.data.name,this.component.application.storage.set("userName",{name:this.user.name}),this.startChat({customerName:i.data.name,customerEmailAddress:i.data.email,visitorQuestion:i.data.question,customData:i.data.customData},e)})}showEntranceClosedDialog(){this.component.disableInput();const e=new ie(q.System,{name:""},[{items:[["ace-entrance-closed-dialog",{content:""}]]}]);this.printEntry(e)}showQuitConfirmDialog(){var e;(e=this.quitConfirmDialogEntry)==null||e.remove(),this.quitConfirmDialogEntry=new ie(q.System,{name:""},[{items:[["ace-quit-confirm-dialog",{content:""}]]}]),this.printEntry(this.quitConfirmDialogEntry),this.quitConfirmDialogEntry.actions$.pipe(W(t=>t.key==="quit-chat"),me(1)).subscribe(t=>{var i,s,r,o;((i=t.data)==null?void 0:i.result)==="quit"?(this.endConversation(),(s=this.quitConfirmDialogEntry)==null||s.remove()):((r=t.data)==null?void 0:r.result)==="cancel"&&((o=this.quitConfirmDialogEntry)==null||o.remove())})}showConversationEndedForm(){const e=new ie(q.System,{name:""},[{items:[["ace-conversation-ended-form",{content:""}]]}]);this.printEntry(e),e.actions$.pipe(W(t=>t.key==="submitted"),me(1)).subscribe(t=>{e.remove(),t.data.email&&this.sendConversationEmail(t.data.email)})}showVideoConfirmDialog(){this.videoConfirmDialogEntry=new ie(q.System,{name:""},[{items:[["ace-video-confirm-dialog",{content:""}]]}]),this.printEntry(this.videoConfirmDialogEntry),this.videoConfirmDialogEntry.actions$.pipe(W(e=>e.key==="video-confirm"),me(1)).subscribe(e=>{var t;this.videoConfirmDialogEntry&&this.videoConfirmDialogEntry.remove(),e.data.result==="declined"&&(this.guestId=null),(t=this.engine)==null||t.videoPrepared(e.data.result),this.printSystem(e.data.text)})}showVideoIFrame(e){var i;this.guestId=Ki(),this.videoIFrameElement=new en(e,this.guestId);const t=this.component.application.root;(i=t==null?void 0:t.shadowRoot)==null||i.prepend(this.videoIFrameElement),this.inVideoCall=!0,this.setHeaderOption()}showChatOverVideo(e){this.guestId&&e===this.guestId&&(this.chatOverlayActive=!0,this.showChatOverlay$.next(this.chatOverlayActive))}async endAuthenticatedSession(){this.component.setAuthenticationBannerStatus(Z.NonAuthenticated),await this.engine.getChatStatus()==="noSession"?(this.resetAuthState(Z.NonAuthenticated),this.setSessionId(null),this.component.clearMessages(),this.shouldUseAuth&&this.startAuthenticationFlow()):this.endConversation()}removeVideo(){var e;(e=this.videoIFrameElement)==null||e.remove(),this.guestId=null,this.chatOverlayActive&&(this.chatOverlayActive=!1,this.showChatOverlay$.next(this.chatOverlayActive)),this.inVideoCall=!1,this.setHeaderOption()}addHeaderOptions(e,t,i,s,r=!0){const o=this.component.application.getComponent("widget-header");if(o)return this.conversationOption?(this.conversationOption.label=e,this.conversationOption.key=t,this.conversationOption.icon=i,this.conversationOption.onClick=s,this.conversationOption.enabled=r,o.requestUpdate(),this.conversationOption):o.addOption({label:e,icon:i,closeOnClick:!0,key:t,onClick:s,enabled:r})}removeHeaderOptions(){const e=this.component.application.getComponent("widget-header");e&&e.removeOption(this.conversationOption)}setStartNewChatOption(){this.conversationOption=this.addHeaderOptions(this.texts.getOrFallback("widget-header.start-new-chat","Start new chat"),"start-new-chat-button",sa.svg,()=>{this.restartNewChat()})}setEndConversationOption(){this.conversationOption=this.addHeaderOptions(this.texts.getOrFallback("widget-header.end-conversation","End conversation"),"end-conversation-button",ia.svg,()=>{this.showQuitConfirmDialog()},!this.inVideoCall)}async setHeaderOption(){switch(await this.engine.getChatStatus()){case"finished":this.isThirdPartyParticipant?this.removeHeaderOptions():this.setStartNewChatOption();break;case"active":this.setEndConversationOption();break;case"noSession":this.conversationOption=null}}}const dp=async n=>{(await rs.getInstance(n.container)).registerProvider("ace-chat",t=>As.getInstance("ace-chat",t))};exports.ChatProviderPlugin=dp;
|
package/index.mjs
CHANGED
|
@@ -9821,9 +9821,9 @@ class As extends wc {
|
|
|
9821
9821
|
constructor(e, t) {
|
|
9822
9822
|
var i, s, r, o, a, c;
|
|
9823
9823
|
super(e, t), this.pendingMessages = [], this.texts = this.component.application.texts, this.headerComponent = this.component.application.getComponent("widget-header"), this.isThirdPartyParticipant = this.component.properties.chat.isThirdPartyWidget, this.agent = this.createAgent(
|
|
9824
|
-
((i = this.component.application.storage.get("
|
|
9824
|
+
((i = this.component.application.storage.get("agentName")) == null ? void 0 : i.name) || ""
|
|
9825
9825
|
), this.user = this.createUser(
|
|
9826
|
-
((s = this.component.application.storage.get("
|
|
9826
|
+
((s = this.component.application.storage.get("userName")) == null ? void 0 : s.name) || ""
|
|
9827
9827
|
), this.params = new URLSearchParams(document.location.search), this.invitationUid = this.params.get("invitationUid"), this.customerName = this.params.get("customerName") || void 0, this.idHubUrl = "https://idhub.dev-se.telia-ck8s.com/idhub-gateway/public", this.disconnected$ = new P(), this.agentUsername = null, this.conversationOption = null, this._conversationOptions = {}, this.sessionId = null, this.contactId = null, this.errand = null, this.entrance = null, this.guestId = null, this.chatOverlayActive = !1, this.inVideoCall = !1, this.onQueueStatusReceived = (l) => {
|
|
9828
9828
|
this.setQueueStatus(l.text || null);
|
|
9829
9829
|
}, this.onEstablished = (l) => {
|
|
@@ -9836,7 +9836,7 @@ class As extends wc {
|
|
|
9836
9836
|
};
|
|
9837
9837
|
this.save({
|
|
9838
9838
|
survey: u
|
|
9839
|
-
}), this.setQueueStatus(null), this.agent.name = l.agentAlias, this.component.application.storage.set("
|
|
9839
|
+
}), this.setQueueStatus(null), this.agent.name = l.agentAlias, this.component.application.storage.set("agentName", {
|
|
9840
9840
|
name: this.agent.name
|
|
9841
9841
|
}), l.videoEnded && this.removeVideo();
|
|
9842
9842
|
}, this.onPrepareVideo = () => {
|
|
@@ -9951,7 +9951,11 @@ class As extends wc {
|
|
|
9951
9951
|
// INTERNAL UTILITY METHODS
|
|
9952
9952
|
// ========================
|
|
9953
9953
|
async initializeChat(e) {
|
|
9954
|
-
|
|
9954
|
+
const t = await this.isEntranceOpen(
|
|
9955
|
+
e.webApiUrl,
|
|
9956
|
+
e.entrance
|
|
9957
|
+
);
|
|
9958
|
+
t || (this.headerComponent.showAuthOptions = !1), t && this.shouldUseAuth && this.idHubEidType ? (this.component.setAuthenticationBannerStatus(Z.NonAuthenticated), this.setupIDHubAuth(), this.idHubClient && await this.startAuthenticationFlow()) : this.handleWelcomeForm(e, void 0, t);
|
|
9955
9959
|
}
|
|
9956
9960
|
setupAuthenticationListeners() {
|
|
9957
9961
|
var e;
|
|
@@ -10015,8 +10019,7 @@ class As extends wc {
|
|
|
10015
10019
|
}
|
|
10016
10020
|
return e;
|
|
10017
10021
|
}
|
|
10018
|
-
async handleWelcomeForm(e, t) {
|
|
10019
|
-
let i = !0;
|
|
10022
|
+
async handleWelcomeForm(e, t, i = !0) {
|
|
10020
10023
|
if (e.webApiUrl)
|
|
10021
10024
|
try {
|
|
10022
10025
|
i = await this.isEntranceOpen(
|
|
@@ -10246,7 +10249,7 @@ class As extends wc {
|
|
|
10246
10249
|
W((i) => i.key === "submitted"),
|
|
10247
10250
|
me(1)
|
|
10248
10251
|
).subscribe((i) => {
|
|
10249
|
-
t.remove(), this.user.name = i.data.name, this.component.application.storage.set("
|
|
10252
|
+
t.remove(), this.user.name = i.data.name, this.component.application.storage.set("userName", {
|
|
10250
10253
|
name: this.user.name
|
|
10251
10254
|
}), this.startChat(
|
|
10252
10255
|
{
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/ace-chat-flamingo",
|
|
3
|
-
"version": "1.1.123-rc.
|
|
3
|
+
"version": "1.1.123-rc.29",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@telia-ace/widget-core-flamingo": "1.1.123-rc.
|
|
6
|
-
"@telia-ace/widget-conversation-flamingo": "1.1.123-rc.
|
|
5
|
+
"@telia-ace/widget-core-flamingo": "1.1.123-rc.29",
|
|
6
|
+
"@telia-ace/widget-conversation-flamingo": "1.1.123-rc.29",
|
|
7
7
|
"rxjs": "^7.8.2",
|
|
8
8
|
"lit": "^3.0.2",
|
|
9
9
|
"@teliads/icons": "^8.4.0",
|
package/types.d.ts
CHANGED
|
@@ -126,11 +126,11 @@ export declare enum AuthCardState {
|
|
|
126
126
|
Error = "error",
|
|
127
127
|
Retry = "retry"
|
|
128
128
|
}
|
|
129
|
-
export type
|
|
129
|
+
export type UserName = {
|
|
130
130
|
name?: string;
|
|
131
131
|
[key: string]: any;
|
|
132
132
|
};
|
|
133
|
-
export type
|
|
133
|
+
export type AgentName = {
|
|
134
134
|
name?: string;
|
|
135
135
|
[key: string]: any;
|
|
136
136
|
};
|