@telia-ace/ace-chat-flamingo 1.1.120-rc.2 → 1.1.120-rc.4

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.
Files changed (3) hide show
  1. package/index.js +1 -1
  2. package/index.mjs +24 -22
  3. package/package.json +3 -3
package/index.js CHANGED
@@ -2193,4 +2193,4 @@ Please report this to https://github.com/markedjs/marked.`,e){const i="<p>An err
2193
2193
  "clientName": "idhub-web-1.0.0",
2194
2194
  "orderRef": "${this.orderRef}",
2195
2195
  "method": "auth"
2196
- }`,method:"POST"})).json();return console.log("\x1B[31mID-Hub \x1B[32m - Collect result",t),t}}function xh(s){return decodeURIComponent(atob(s).split("").map(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)}).join(""))}class es extends Qo{constructor(e,t){super(e,t),this.agent=this.createAgent(""),this.user=this.createUser(""),this.pendingMessages=[],this.texts=this.component.application.texts,this.isThirdPartyParticipant=this.component.properties.chat.isThirdPartyWidget,this.disconnected$=new _,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.authSettings=this.component.application.settings.auth,this._onQueueStatusReceived=n=>{this._setQueueStatus(n.text||null)},this._onEstablished=n=>{this.contactId=n.contactId,this.errand=n.errand,this.entrance=n.entrance,this.agentUsername=n.agentUsername;const i={contactId:this.contactId,errand:this.errand,entrance:this.entrance,agentUsername:this.agentUsername};this.save({survey:i}),this._setQueueStatus(null),this.agent.name=n.agent,n.videoEnded&&this.removeVideo()},this._onPrepareVideo=()=>{this.prepareVideo()},this._onVideoPrepared=n=>{this.showVideo(n.userUrl)},this._onChatButtonClicked=n=>{this.showChatOverVideo(n.guestId)},this._onEndVideoButtonClicked=n=>{this.handleEndVideoConference(n.guestId)},this._onPenStatusChange=n=>{n.penStatus==="on"?this.setTypingState(!0):this.setTypingState(!1)},this._onChatEnded=async n=>{var r,o;this.setToastMessage(null),this.setTypingState(!1),this.videoConfirmDialogEntry&&this.videoConfirmDialogEntry.remove(),this.component.disableInput(),n.showForm&&this.showConversationEndedForm();const i=this.component.application.settings;(r=i==null?void 0:i.survey)!=null&&r.shouldUseSurvey&&((o=i==null?void 0:i.survey)!=null&&o.surveyBaseUrl)&&this.showSurvey(),this.isThirdPartyParticipant?this._removeHeaderOptions():this._setStartNewChatOption(),this.complete()},this.headerComponent=this.component.application.getComponent("widget-header"),this.params=new URLSearchParams(document.location.search),this.invitationUid=this.params.get("invitationUid"),this.customerName=this.params.get("customerName")||void 0,this.properties=t.properties,console.log("### Chat provider",this.component),this.idHubClient=new $h(this.authSettings)}static getInstance(e,t){return t.providerInstance??(t.providerInstance=new es(e,t)),t.providerInstance}connect(e={}){super.connect(),this._conversationOptions=e;const t={...this.properties.chat??{},...e},n=!!this.sessionId;if(!n){const r=kn();this._setSessionId(r)}this.save({chatSessionId:this.sessionId}),this.engine=new eh(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(O(this.disconnected$),I(Vc)).subscribe(this._onQueueStatusReceived),this.engine.actions().pipe(O(this.disconnected$),I(Zc)).subscribe(this._onEstablished),this.engine.actions().pipe(O(this.disconnected$),I(Gc)).subscribe(this._onPrepareVideo),this.engine.actions().pipe(O(this.disconnected$),I(Qc)).subscribe(this._onVideoPrepared),this.engine.actions().pipe(O(this.disconnected$),I(Kc)).subscribe(this._onChatButtonClicked),this.engine.actions().pipe(O(this.disconnected$),I(Jc)).subscribe(this._onEndVideoButtonClicked),this.engine.actions().pipe(O(this.disconnected$),I(Wc)).subscribe(this._onPenStatusChange),this.engine.actions().pipe(O(this.disconnected$),I(Yc)).subscribe(this._onChatEnded),this.setHeaderOption();const i=this.component.application.trigger;i&&i.widgetActive$.pipe(O(i.componentIsDestroyed$)).subscribe(r=>{r&&(this.conversationOption=null,this.setHeaderOption())}),this.component.userTyping$.pipe(O(this.disconnected$)).subscribe(r=>{var o;(o=this.engine)==null||o.sendPenStatusOn(r)}),n?this.engine.rehydrate().then(r=>{var o;r?(o=this.engine)==null||o.reconnect().pipe(O(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)})}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}}disconnected(){super.disconnected(),this.disconnected$.next()}_removeHeaderOptions(){const e=this.component.application.getComponent("widget-header");e&&e.removeOption(this.conversationOption)}_addHeaderOptions(e,t,n,i,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=n,this.conversationOption.onClick=i,this.conversationOption.enabled=r,o.requestUpdate(),this.conversationOption):o.addOption({label:e,icon:n,closeOnClick:!0,key:t,onClick:i,enabled:r})}_startChat(e){var n,i;if(!this.engine)return;const t=e.customData.errand??this.engine.config.defaultErrand;if(!t)throw new Error("Errand is required but was not configured");if(this.isThirdPartyParticipant)this.component.application.root.style.visibility="visible",this.engine.chatJoin({invitationUid:this.invitationUid,customerName:this.customerName??e.customerName}).pipe(O(this.disconnected$)).subscribe();else{const r=(i=(n=this.component.application)==null?void 0:n.userData)==null?void 0:i.idhubEIDToken;this.engine.chatRequest({customerName:e.customerName,customerEmailAddress:e.customerEmailAddress??"",visitorQuestion:e.visitorQuestion??"",customData:e.customData,errand:t,...r&&{authToken:r}}).pipe(O(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))}showSurvey(){const e=new U(A.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)}async startAuthenticationFlow(){var n;const e=await((n=this.idHubClient)==null?void 0:n.auth());let t;e&&(this.headerComponent.authUrl=e,this.headerComponent.provider=this,t=this.showTunnistusLinkButton(e),this.headerComponent.idref=t,t.actions$.pipe(I(i=>i.key==="start-auth"),V(1)).subscribe(()=>{this.handleAuthentication(t)}))}async handleAuthentication(e){var n,i,r,o;this.headerComponent.UserName="Authenticating...",this.headerComponent.authState="authenticating",this.headerComponent.requestUpdate();const t=await((n=this.idHubClient)==null?void 0:n.collectPolling());if(this.component.application.userData=t,(t==null?void 0:t.status)==="authenticated"){const a=xh(((i=t==null?void 0:t.idhubEIDToken)==null?void 0:i.split(".")[1])||""),l=JSON.parse(a),c=((o=(r=l==null?void 0:l.completionData)==null?void 0:r.user)==null?void 0:o.name)||"";this.headerComponent.UserName=c,this.headerComponent.authState="authenticated",this.component.application.storage.set("auth",{name:c,authenticated:!0}),e==null||e.remove(),this.handleWelcomeForm(this.engine.config)}}async handleWelcomeForm(e){let t=!0;e.webApiUrl&&(t=await this.isEntranceOpen(e.webApiUrl,e.entrance)),t?this.customerName?this._startChat({customerName:this.customerName,customData:{}}):this.showWelcomeForm():this.showEntranceClosedDialog()}async initializeChat(e){this.authSettings.shouldUseAuth?await this.startAuthenticationFlow():this.handleWelcomeForm(e)}showTunnistusLinkButton(e){const t=new U(A.System,{name:""},[{items:[["tunnistus-link-button",{content:""},{tunnistusURL:e}]]}]);return this.printEntry(t),t}showWelcomeForm(){this.component.disableInput(),this.component.disableSkipToLatestMessage();let e;this.isThirdPartyParticipant?e=new U(A.System,{name:""},[{items:[["ace-welcome-form-third-party",{content:""}]]}]):e=new U(A.System,{name:""},[{items:[["ace-welcome-form",{content:""}]]}]),this.printEntry(e),e.actions$.pipe(I(t=>t.key==="submitted"),V(1)).subscribe(t=>{e.remove(),this._startChat({customerName:t.data.name,customerEmailAddress:t.data.email,visitorQuestion:t.data.question,customData:t.data.customData})})}showEntranceClosedDialog(){this.component.disableInput();const e=new U(A.System,{name:""},[{items:[["ace-entrance-closed-dialog",{content:""}]]}]);this.printEntry(e)}_setQueueStatus(e){this.setToastMessage(e)}showLogoutConfirmDialog(){var e;(e=this.logoutConfirmDialogEntry)==null||e.remove(),this.logoutConfirmDialogEntry=new U(A.System,{name:""},[{items:[["ace-logout-confirm-dialog",{content:""}]]}]),this.printEntry(this.logoutConfirmDialogEntry),this.logoutConfirmDialogEntry.actions$.pipe(I(t=>t.key==="logout-chat"),V(1)).subscribe(async t=>{var n;if(this.logoutConfirmDialogEntry&&this.logoutConfirmDialogEntry.remove(),((n=t.data)==null?void 0:n.result)==="logout"){const i=await this.engine.getChatStatus();this.headerComponent._logout(),i==="noSession"?(this._setSessionId(null),this.component.clearMessages(),this.startAuthenticationFlow()):this.endConversation()}})}showQuitConfirmDialog(){var e;(e=this.quitConfirmDialogEntry)==null||e.remove(),this.quitConfirmDialogEntry=new U(A.System,{name:""},[{items:[["ace-quit-confirm-dialog",{content:""}]]}]),this.printEntry(this.quitConfirmDialogEntry),this.quitConfirmDialogEntry.actions$.pipe(I(t=>t.key==="quit-chat"),V(1)).subscribe(t=>{var n;this.quitConfirmDialogEntry&&this.quitConfirmDialogEntry.remove(),((n=t.data)==null?void 0:n.result)==="quit"&&this.endConversation()})}showConversationEndedForm(){const e=new U(A.System,{name:""},[{items:[["ace-conversation-ended-form",{content:""}]]}]);this.printEntry(e),e.actions$.pipe(I(t=>t.key==="submitted"),V(1)).subscribe(t=>{e.remove(),t.data.email&&this.sendConversationEmail(t.data.email)})}prepareVideo(){this.videoConfirmDialogEntry=new U(A.System,{name:""},[{items:[["ace-video-confirm-dialog",{content:""}]]}]),this.printEntry(this.videoConfirmDialogEntry),this.videoConfirmDialogEntry.actions$.pipe(I(e=>e.key==="video-confirm"),V(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)})}showVideo(e){var n;this.guestId=kn(),this.videoIFrameElement=new st(e,this.guestId);const t=this.component.application.root;(n=t==null?void 0:t.shadowRoot)==null||n.prepend(this.videoIFrameElement),this.inVideoCall=!0,this.setHeaderOption()}showChatOverVideo(e){this.guestId&&e===this.guestId&&(this.chatOverlayActive=!0,this.showChatOverlay$.next(this.chatOverlayActive))}handleEndVideoConference(e){this.guestId&&e===this.guestId&&this.removeVideo()}printAgent(e,t=""){const n=t.length>0?this.agent.print(e,"markdown",t):this.agent.print(e,"markdown");return this.setTypingState(!1),n}printUser(e){const t=dn(Is(e));return this.user.print(t)}printSystem(e){const t=dn(Is(e));return this.system.print(t)}_setEndConversationOption(){this.conversationOption=this._addHeaderOptions(this.texts.getOrFallback("widget-header.end-conversation","End conversation"),"end-conversation-button",Mn.svg,()=>{this.showQuitConfirmDialog()},!this.inVideoCall)}_setStartNewChatOption(){this.conversationOption=this._addHeaderOptions(this.texts.getOrFallback("widget-header.start-new-chat","Start new chat"),"start-new-chat-button",Xi.svg,()=>{this._restartNewChat()})}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()}async endConversation(){var e;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(n){this.printSystem(this.texts.getOrFallback("email-form.error-message","Unable to send email with the conversation.")),n instanceof It||console.warn("Unhandled error:",n)}}_clearPendingMessages(){this.pendingMessages.forEach(e=>{e.remove()})}_setSessionId(e){this.sessionId=e}onUserSubmit(e){const t=this.printUser(e.text);t.setStatus("pending"),this.pendingMessages.push(t),(async()=>{var n;try{await((n=this.engine)==null?void 0:n.chatWrite(e.text))}catch(i){i instanceof It?t.setStatus("failed"):(t.setStatus("failed"),console.warn("Unhandled error:",i))}})()}async rehydrate(e){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)}save(e){this.component.stateMachine.session().pipe(Y(t=>(t==null?void 0:t.data$)||$e),V(1)).subscribe(t=>{this.saveToCurrentSession$.next({...t,...e})})}async isEntranceOpen(e,t){var i;let n=!1;try{const r=await fetch(`${e}/1/entrances/${t}/is-open`),o=await r.json();r.ok?n=(i=o==null?void 0:o.resultData)==null?void 0:i.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 n}}const wh=async s=>{(await _n.getInstance(s.container)).registerProvider("ace-chat",t=>es.getInstance("ace-chat",t))};exports.ChatProviderPlugin=wh;
2196
+ }`,method:"POST"})).json();return console.log("\x1B[31mID-Hub \x1B[32m - Collect result",t),t}}function xh(s){return decodeURIComponent(atob(s).split("").map(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)}).join(""))}class es extends Qo{constructor(e,t){var n;super(e,t),this.agent=this.createAgent(""),this.user=this.createUser(""),this.pendingMessages=[],this.texts=this.component.application.texts,this.isThirdPartyParticipant=this.component.properties.chat.isThirdPartyWidget,this.disconnected$=new _,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.authSettings=((n=this.component.application.settings)==null?void 0:n.auth)||void 0,this._onQueueStatusReceived=i=>{this._setQueueStatus(i.text||null)},this._onEstablished=i=>{this.contactId=i.contactId,this.errand=i.errand,this.entrance=i.entrance,this.agentUsername=i.agentUsername;const r={contactId:this.contactId,errand:this.errand,entrance:this.entrance,agentUsername:this.agentUsername};this.save({survey:r}),this._setQueueStatus(null),this.agent.name=i.agent,i.videoEnded&&this.removeVideo()},this._onPrepareVideo=()=>{this.prepareVideo()},this._onVideoPrepared=i=>{this.showVideo(i.userUrl)},this._onChatButtonClicked=i=>{this.showChatOverVideo(i.guestId)},this._onEndVideoButtonClicked=i=>{this.handleEndVideoConference(i.guestId)},this._onPenStatusChange=i=>{i.penStatus==="on"?this.setTypingState(!0):this.setTypingState(!1)},this._onChatEnded=async i=>{var o,a;this.setToastMessage(null),this.setTypingState(!1),this.videoConfirmDialogEntry&&this.videoConfirmDialogEntry.remove(),this.component.disableInput(),i.showForm&&this.showConversationEndedForm();const r=this.component.application.settings;(o=r==null?void 0:r.survey)!=null&&o.shouldUseSurvey&&((a=r==null?void 0:r.survey)!=null&&a.surveyBaseUrl)&&this.showSurvey(),this.isThirdPartyParticipant?this._removeHeaderOptions():this._setStartNewChatOption(),this.complete()},this.headerComponent=this.component.application.getComponent("widget-header"),this.params=new URLSearchParams(document.location.search),this.invitationUid=this.params.get("invitationUid"),this.customerName=this.params.get("customerName")||void 0,this.properties=t.properties,this.authSettings&&(this.idHubClient=new $h(this.authSettings))}static getInstance(e,t){return t.providerInstance??(t.providerInstance=new es(e,t)),t.providerInstance}connect(e={}){super.connect(),this._conversationOptions=e;const t={...this.properties.chat??{},...e},n=!!this.sessionId;if(!n){const r=kn();this._setSessionId(r)}this.save({chatSessionId:this.sessionId}),this.engine=new eh(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(O(this.disconnected$),I(Vc)).subscribe(this._onQueueStatusReceived),this.engine.actions().pipe(O(this.disconnected$),I(Zc)).subscribe(this._onEstablished),this.engine.actions().pipe(O(this.disconnected$),I(Gc)).subscribe(this._onPrepareVideo),this.engine.actions().pipe(O(this.disconnected$),I(Qc)).subscribe(this._onVideoPrepared),this.engine.actions().pipe(O(this.disconnected$),I(Kc)).subscribe(this._onChatButtonClicked),this.engine.actions().pipe(O(this.disconnected$),I(Jc)).subscribe(this._onEndVideoButtonClicked),this.engine.actions().pipe(O(this.disconnected$),I(Wc)).subscribe(this._onPenStatusChange),this.engine.actions().pipe(O(this.disconnected$),I(Yc)).subscribe(this._onChatEnded),this.setHeaderOption();const i=this.component.application.trigger;i&&i.widgetActive$.pipe(O(i.componentIsDestroyed$)).subscribe(r=>{r&&(this.conversationOption=null,this.setHeaderOption())}),this.component.userTyping$.pipe(O(this.disconnected$)).subscribe(r=>{var o;(o=this.engine)==null||o.sendPenStatusOn(r)}),n?this.engine.rehydrate().then(r=>{var o;r?(o=this.engine)==null||o.reconnect().pipe(O(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)})}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}}disconnected(){super.disconnected(),this.disconnected$.next()}_removeHeaderOptions(){const e=this.component.application.getComponent("widget-header");e&&e.removeOption(this.conversationOption)}_addHeaderOptions(e,t,n,i,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=n,this.conversationOption.onClick=i,this.conversationOption.enabled=r,o.requestUpdate(),this.conversationOption):o.addOption({label:e,icon:n,closeOnClick:!0,key:t,onClick:i,enabled:r})}_startChat(e){var n,i;if(!this.engine)return;const t=e.customData.errand??this.engine.config.defaultErrand;if(!t)throw new Error("Errand is required but was not configured");if(this.isThirdPartyParticipant)this.component.application.root.style.visibility="visible",this.engine.chatJoin({invitationUid:this.invitationUid,customerName:this.customerName??e.customerName}).pipe(O(this.disconnected$)).subscribe();else{const r=(i=(n=this.component.application)==null?void 0:n.userData)==null?void 0:i.idhubEIDToken;this.engine.chatRequest({customerName:e.customerName,customerEmailAddress:e.customerEmailAddress??"",visitorQuestion:e.visitorQuestion??"",customData:e.customData,errand:t,...r&&{authToken:r}}).pipe(O(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))}showSurvey(){const e=new U(A.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)}async startAuthenticationFlow(){var n;const e=await((n=this.idHubClient)==null?void 0:n.auth());let t;e&&(this.headerComponent.authUrl=e,this.headerComponent.provider=this,t=this.showTunnistusLinkButton(e),this.headerComponent.idref=t,t.actions$.pipe(I(i=>i.key==="start-auth"),V(1)).subscribe(()=>{this.handleAuthentication(t)}))}async handleAuthentication(e){var n,i,r,o;this.headerComponent.UserName="Authenticating...",this.headerComponent.authState="authenticating",this.headerComponent.requestUpdate();const t=await((n=this.idHubClient)==null?void 0:n.collectPolling());if(this.component.application.userData=t,(t==null?void 0:t.status)==="authenticated"){const a=xh(((i=t==null?void 0:t.idhubEIDToken)==null?void 0:i.split(".")[1])||""),l=JSON.parse(a),c=((o=(r=l==null?void 0:l.completionData)==null?void 0:r.user)==null?void 0:o.name)||"";this.headerComponent.UserName=c,this.headerComponent.authState="authenticated",this.component.application.storage.set("auth",{name:c,authenticated:!0}),e==null||e.remove(),this.handleWelcomeForm(this.engine.config)}}async handleWelcomeForm(e){let t=!0;e.webApiUrl&&(t=await this.isEntranceOpen(e.webApiUrl,e.entrance)),t?this.customerName?this._startChat({customerName:this.customerName,customData:{}}):this.showWelcomeForm():this.showEntranceClosedDialog()}async initializeChat(e){var t;(t=this.authSettings)!=null&&t.shouldUseAuth?await this.startAuthenticationFlow():this.handleWelcomeForm(e)}showTunnistusLinkButton(e){const t=new U(A.System,{name:""},[{items:[["tunnistus-link-button",{content:""},{tunnistusURL:e}]]}]);return this.printEntry(t),t}showWelcomeForm(){this.component.disableInput(),this.component.disableSkipToLatestMessage();let e;this.isThirdPartyParticipant?e=new U(A.System,{name:""},[{items:[["ace-welcome-form-third-party",{content:""}]]}]):e=new U(A.System,{name:""},[{items:[["ace-welcome-form",{content:""}]]}]),this.printEntry(e),e.actions$.pipe(I(t=>t.key==="submitted"),V(1)).subscribe(t=>{e.remove(),this._startChat({customerName:t.data.name,customerEmailAddress:t.data.email,visitorQuestion:t.data.question,customData:t.data.customData})})}showEntranceClosedDialog(){this.component.disableInput();const e=new U(A.System,{name:""},[{items:[["ace-entrance-closed-dialog",{content:""}]]}]);this.printEntry(e)}_setQueueStatus(e){this.setToastMessage(e)}showLogoutConfirmDialog(){var e;(e=this.logoutConfirmDialogEntry)==null||e.remove(),this.logoutConfirmDialogEntry=new U(A.System,{name:""},[{items:[["ace-logout-confirm-dialog",{content:""}]]}]),this.printEntry(this.logoutConfirmDialogEntry),this.logoutConfirmDialogEntry.actions$.pipe(I(t=>t.key==="logout-chat"),V(1)).subscribe(async t=>{var n;if(this.logoutConfirmDialogEntry&&this.logoutConfirmDialogEntry.remove(),((n=t.data)==null?void 0:n.result)==="logout"){const i=await this.engine.getChatStatus();this.headerComponent._logout(),i==="noSession"?(this._setSessionId(null),this.component.clearMessages(),this.startAuthenticationFlow()):this.endConversation()}})}showQuitConfirmDialog(){var e;(e=this.quitConfirmDialogEntry)==null||e.remove(),this.quitConfirmDialogEntry=new U(A.System,{name:""},[{items:[["ace-quit-confirm-dialog",{content:""}]]}]),this.printEntry(this.quitConfirmDialogEntry),this.quitConfirmDialogEntry.actions$.pipe(I(t=>t.key==="quit-chat"),V(1)).subscribe(t=>{var n;this.quitConfirmDialogEntry&&this.quitConfirmDialogEntry.remove(),((n=t.data)==null?void 0:n.result)==="quit"&&this.endConversation()})}showConversationEndedForm(){const e=new U(A.System,{name:""},[{items:[["ace-conversation-ended-form",{content:""}]]}]);this.printEntry(e),e.actions$.pipe(I(t=>t.key==="submitted"),V(1)).subscribe(t=>{e.remove(),t.data.email&&this.sendConversationEmail(t.data.email)})}prepareVideo(){this.videoConfirmDialogEntry=new U(A.System,{name:""},[{items:[["ace-video-confirm-dialog",{content:""}]]}]),this.printEntry(this.videoConfirmDialogEntry),this.videoConfirmDialogEntry.actions$.pipe(I(e=>e.key==="video-confirm"),V(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)})}showVideo(e){var n;this.guestId=kn(),this.videoIFrameElement=new st(e,this.guestId);const t=this.component.application.root;(n=t==null?void 0:t.shadowRoot)==null||n.prepend(this.videoIFrameElement),this.inVideoCall=!0,this.setHeaderOption()}showChatOverVideo(e){this.guestId&&e===this.guestId&&(this.chatOverlayActive=!0,this.showChatOverlay$.next(this.chatOverlayActive))}handleEndVideoConference(e){this.guestId&&e===this.guestId&&this.removeVideo()}printAgent(e,t=""){const n=t.length>0?this.agent.print(e,"markdown",t):this.agent.print(e,"markdown");return this.setTypingState(!1),n}printUser(e){const t=dn(Is(e));return this.user.print(t)}printSystem(e){const t=dn(Is(e));return this.system.print(t)}_setEndConversationOption(){this.conversationOption=this._addHeaderOptions(this.texts.getOrFallback("widget-header.end-conversation","End conversation"),"end-conversation-button",Mn.svg,()=>{this.showQuitConfirmDialog()},!this.inVideoCall)}_setStartNewChatOption(){this.conversationOption=this._addHeaderOptions(this.texts.getOrFallback("widget-header.start-new-chat","Start new chat"),"start-new-chat-button",Xi.svg,()=>{this._restartNewChat()})}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()}async endConversation(){var e;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(n){this.printSystem(this.texts.getOrFallback("email-form.error-message","Unable to send email with the conversation.")),n instanceof It||console.warn("Unhandled error:",n)}}_clearPendingMessages(){this.pendingMessages.forEach(e=>{e.remove()})}_setSessionId(e){this.sessionId=e}onUserSubmit(e){const t=this.printUser(e.text);t.setStatus("pending"),this.pendingMessages.push(t),(async()=>{var n;try{await((n=this.engine)==null?void 0:n.chatWrite(e.text))}catch(i){i instanceof It?t.setStatus("failed"):(t.setStatus("failed"),console.warn("Unhandled error:",i))}})()}async rehydrate(e){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)}save(e){this.component.stateMachine.session().pipe(Y(t=>(t==null?void 0:t.data$)||$e),V(1)).subscribe(t=>{this.saveToCurrentSession$.next({...t,...e})})}async isEntranceOpen(e,t){var i;let n=!1;try{const r=await fetch(`${e}/1/entrances/${t}/is-open`),o=await r.json();r.ok?n=(i=o==null?void 0:o.resultData)==null?void 0:i.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 n}}const wh=async s=>{(await _n.getInstance(s.container)).registerProvider("ace-chat",t=>es.getInstance("ace-chat",t))};exports.ChatProviderPlugin=wh;
package/index.mjs CHANGED
@@ -9145,35 +9145,36 @@ function xh(s) {
9145
9145
  }
9146
9146
  class es extends Qo {
9147
9147
  constructor(e, t) {
9148
- super(e, t), this.agent = this.createAgent(""), this.user = this.createUser(""), this.pendingMessages = [], this.texts = this.component.application.texts, this.isThirdPartyParticipant = this.component.properties.chat.isThirdPartyWidget, this.disconnected$ = new _(), 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.authSettings = this.component.application.settings.auth, this._onQueueStatusReceived = (n) => {
9149
- this._setQueueStatus(n.text || null);
9150
- }, this._onEstablished = (n) => {
9151
- this.contactId = n.contactId, this.errand = n.errand, this.entrance = n.entrance, this.agentUsername = n.agentUsername;
9152
- const i = {
9148
+ var n;
9149
+ super(e, t), this.agent = this.createAgent(""), this.user = this.createUser(""), this.pendingMessages = [], this.texts = this.component.application.texts, this.isThirdPartyParticipant = this.component.properties.chat.isThirdPartyWidget, this.disconnected$ = new _(), 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.authSettings = ((n = this.component.application.settings) == null ? void 0 : n.auth) || void 0, this._onQueueStatusReceived = (i) => {
9150
+ this._setQueueStatus(i.text || null);
9151
+ }, this._onEstablished = (i) => {
9152
+ this.contactId = i.contactId, this.errand = i.errand, this.entrance = i.entrance, this.agentUsername = i.agentUsername;
9153
+ const r = {
9153
9154
  contactId: this.contactId,
9154
9155
  errand: this.errand,
9155
9156
  entrance: this.entrance,
9156
9157
  agentUsername: this.agentUsername
9157
9158
  };
9158
9159
  this.save({
9159
- survey: i
9160
- }), this._setQueueStatus(null), this.agent.name = n.agent, n.videoEnded && this.removeVideo();
9160
+ survey: r
9161
+ }), this._setQueueStatus(null), this.agent.name = i.agent, i.videoEnded && this.removeVideo();
9161
9162
  }, this._onPrepareVideo = () => {
9162
9163
  this.prepareVideo();
9163
- }, this._onVideoPrepared = (n) => {
9164
- this.showVideo(n.userUrl);
9165
- }, this._onChatButtonClicked = (n) => {
9166
- this.showChatOverVideo(n.guestId);
9167
- }, this._onEndVideoButtonClicked = (n) => {
9168
- this.handleEndVideoConference(n.guestId);
9169
- }, this._onPenStatusChange = (n) => {
9170
- n.penStatus === "on" ? this.setTypingState(!0) : this.setTypingState(!1);
9171
- }, this._onChatEnded = async (n) => {
9172
- var r, o;
9173
- this.setToastMessage(null), this.setTypingState(!1), this.videoConfirmDialogEntry && this.videoConfirmDialogEntry.remove(), this.component.disableInput(), n.showForm && this.showConversationEndedForm();
9174
- const i = this.component.application.settings;
9175
- (r = i == null ? void 0 : i.survey) != null && r.shouldUseSurvey && ((o = i == null ? void 0 : i.survey) != null && o.surveyBaseUrl) && this.showSurvey(), this.isThirdPartyParticipant ? this._removeHeaderOptions() : this._setStartNewChatOption(), this.complete();
9176
- }, this.headerComponent = this.component.application.getComponent("widget-header"), this.params = new URLSearchParams(document.location.search), this.invitationUid = this.params.get("invitationUid"), this.customerName = this.params.get("customerName") || void 0, this.properties = t.properties, console.log("### Chat provider", this.component), this.idHubClient = new $h(this.authSettings);
9164
+ }, this._onVideoPrepared = (i) => {
9165
+ this.showVideo(i.userUrl);
9166
+ }, this._onChatButtonClicked = (i) => {
9167
+ this.showChatOverVideo(i.guestId);
9168
+ }, this._onEndVideoButtonClicked = (i) => {
9169
+ this.handleEndVideoConference(i.guestId);
9170
+ }, this._onPenStatusChange = (i) => {
9171
+ i.penStatus === "on" ? this.setTypingState(!0) : this.setTypingState(!1);
9172
+ }, this._onChatEnded = async (i) => {
9173
+ var o, a;
9174
+ this.setToastMessage(null), this.setTypingState(!1), this.videoConfirmDialogEntry && this.videoConfirmDialogEntry.remove(), this.component.disableInput(), i.showForm && this.showConversationEndedForm();
9175
+ const r = this.component.application.settings;
9176
+ (o = r == null ? void 0 : r.survey) != null && o.shouldUseSurvey && ((a = r == null ? void 0 : r.survey) != null && a.surveyBaseUrl) && this.showSurvey(), this.isThirdPartyParticipant ? this._removeHeaderOptions() : this._setStartNewChatOption(), this.complete();
9177
+ }, this.headerComponent = this.component.application.getComponent("widget-header"), this.params = new URLSearchParams(document.location.search), this.invitationUid = this.params.get("invitationUid"), this.customerName = this.params.get("customerName") || void 0, this.properties = t.properties, this.authSettings && (this.idHubClient = new $h(this.authSettings));
9177
9178
  }
9178
9179
  static getInstance(e, t) {
9179
9180
  return t.providerInstance ?? (t.providerInstance = new es(e, t)), t.providerInstance;
@@ -9350,7 +9351,8 @@ class es extends Qo {
9350
9351
  }) : this.showWelcomeForm() : this.showEntranceClosedDialog();
9351
9352
  }
9352
9353
  async initializeChat(e) {
9353
- this.authSettings.shouldUseAuth ? await this.startAuthenticationFlow() : this.handleWelcomeForm(e);
9354
+ var t;
9355
+ (t = this.authSettings) != null && t.shouldUseAuth ? await this.startAuthenticationFlow() : this.handleWelcomeForm(e);
9354
9356
  }
9355
9357
  showTunnistusLinkButton(e) {
9356
9358
  const t = new U(
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@telia-ace/ace-chat-flamingo",
3
- "version": "1.1.120-rc.2",
3
+ "version": "1.1.120-rc.4",
4
4
  "dependencies": {
5
- "@telia-ace/widget-core-flamingo": "1.1.120-rc.2",
6
- "@telia-ace/widget-conversation-flamingo": "1.1.120-rc.2",
5
+ "@telia-ace/widget-core-flamingo": "1.1.120-rc.4",
6
+ "@telia-ace/widget-conversation-flamingo": "1.1.120-rc.4",
7
7
  "rxjs": "^7.8.2",
8
8
  "lit": "^3.0.2",
9
9
  "@teliads/icons": "^8.4.0",