@telia-ace/ace-chat-flamingo 1.1.120-rc.4 → 1.1.120-rc.5
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 +2 -2
- package/index.mjs +31 -32
- package/package.json +3 -3
- package/provider.d.ts +0 -1
package/index.js
CHANGED
|
@@ -2189,8 +2189,8 @@ Please report this to https://github.com/markedjs/marked.`,e){const i="<p>An err
|
|
|
2189
2189
|
"agentId": "ACEWIDGET",
|
|
2190
2190
|
"userName": "ACEWIDGET"
|
|
2191
2191
|
}
|
|
2192
|
-
}`,method:"POST"})).json();return console.log("\x1B[31mID-Hub \x1B[32m - Initializing result",t),this.tunnistusUrl=t.tunnistusURL,this.orderRef=t.orderRef,this.tunnistusUrl}catch{return}}async collectPolling(){let e=this.maxRetries,t;do await new Promise(n=>setTimeout(n,
|
|
2192
|
+
}`,method:"POST"})).json();return console.log("\x1B[31mID-Hub \x1B[32m - Initializing result",t),this.tunnistusUrl=t.tunnistusURL,this.orderRef=t.orderRef,this.tunnistusUrl}catch{return}}async collectPolling(){let e=this.maxRetries,t;do await new Promise(n=>setTimeout(n,1e3)),t=await this.collect(),e--;while(t.status=="pending"&&e>0);return t}async collect(){if(this.orderRef==="")throw new Error("OrderRef is missing");const t=await(await fetch(this.url+"/collect",{headers:{accept:"application/json","accept-language":"sv-SE,sv;q=0.9,en-US;q=0.8,en;q=0.7","content-type":"application/json"},body:`{
|
|
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){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;
|
|
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,i;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._onQueueStatusReceived=r=>{this._setQueueStatus(r.text||null)},this._onEstablished=r=>{this.contactId=r.contactId,this.errand=r.errand,this.entrance=r.entrance,this.agentUsername=r.agentUsername;const o={contactId:this.contactId,errand:this.errand,entrance:this.entrance,agentUsername:this.agentUsername};this.save({survey:o}),this._setQueueStatus(null),this.agent.name=r.agent,r.videoEnded&&this.removeVideo()},this._onPrepareVideo=()=>{this.prepareVideo()},this._onVideoPrepared=r=>{this.showVideo(r.userUrl)},this._onChatButtonClicked=r=>{this.showChatOverVideo(r.guestId)},this._onEndVideoButtonClicked=r=>{this.handleEndVideoConference(r.guestId)},this._onPenStatusChange=r=>{r.penStatus==="on"?this.setTypingState(!0):this.setTypingState(!1)},this._onChatEnded=async r=>{var a,l;this.setToastMessage(null),this.setTypingState(!1),this.videoConfirmDialogEntry&&this.videoConfirmDialogEntry.remove(),this.component.disableInput(),r.showForm&&this.showConversationEndedForm();const o=this.component.application.settings;(a=o==null?void 0:o.survey)!=null&&a.shouldUseSurvey&&((l=o==null?void 0:o.survey)!=null&&l.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,(n=this.component.application.settings)!=null&&n.auth&&(this.idHubClient=new $h((i=this.component.application.settings)==null?void 0:i.auth))}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,this.headerComponent.authState="non-authenticated",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,n;(n=(t=this.component.application.settings)==null?void 0:t.auth)!=null&&n.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;this.logoutConfirmDialogEntry&&this.logoutConfirmDialogEntry.remove(),((n=t.data)==null?void 0:n.result)==="logout"&&(await this.engine.getChatStatus()==="noSession"?(this.headerComponent._logout(),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,t,n;(t=(e=this.component.application.settings)==null?void 0:e.auth)!=null&&t.shouldUseAuth&&this.headerComponent._logout("chat-ended"),await((n=this.engine)==null?void 0:n.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
|
@@ -9113,7 +9113,7 @@ class $h {
|
|
|
9113
9113
|
async collectPolling() {
|
|
9114
9114
|
let e = this.maxRetries, t;
|
|
9115
9115
|
do
|
|
9116
|
-
await new Promise((n) => setTimeout(n,
|
|
9116
|
+
await new Promise((n) => setTimeout(n, 1e3)), t = await this.collect(), e--;
|
|
9117
9117
|
while (t.status == "pending" && e > 0);
|
|
9118
9118
|
return t;
|
|
9119
9119
|
}
|
|
@@ -9145,36 +9145,38 @@ function xh(s) {
|
|
|
9145
9145
|
}
|
|
9146
9146
|
class es extends Qo {
|
|
9147
9147
|
constructor(e, t) {
|
|
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.
|
|
9150
|
-
this._setQueueStatus(
|
|
9151
|
-
}, this._onEstablished = (
|
|
9152
|
-
this.contactId =
|
|
9153
|
-
const
|
|
9148
|
+
var n, i;
|
|
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._onQueueStatusReceived = (r) => {
|
|
9150
|
+
this._setQueueStatus(r.text || null);
|
|
9151
|
+
}, this._onEstablished = (r) => {
|
|
9152
|
+
this.contactId = r.contactId, this.errand = r.errand, this.entrance = r.entrance, this.agentUsername = r.agentUsername;
|
|
9153
|
+
const o = {
|
|
9154
9154
|
contactId: this.contactId,
|
|
9155
9155
|
errand: this.errand,
|
|
9156
9156
|
entrance: this.entrance,
|
|
9157
9157
|
agentUsername: this.agentUsername
|
|
9158
9158
|
};
|
|
9159
9159
|
this.save({
|
|
9160
|
-
survey:
|
|
9161
|
-
}), this._setQueueStatus(null), this.agent.name =
|
|
9160
|
+
survey: o
|
|
9161
|
+
}), this._setQueueStatus(null), this.agent.name = r.agent, r.videoEnded && this.removeVideo();
|
|
9162
9162
|
}, this._onPrepareVideo = () => {
|
|
9163
9163
|
this.prepareVideo();
|
|
9164
|
-
}, this._onVideoPrepared = (
|
|
9165
|
-
this.showVideo(
|
|
9166
|
-
}, this._onChatButtonClicked = (
|
|
9167
|
-
this.showChatOverVideo(
|
|
9168
|
-
}, this._onEndVideoButtonClicked = (
|
|
9169
|
-
this.handleEndVideoConference(
|
|
9170
|
-
}, this._onPenStatusChange = (
|
|
9171
|
-
|
|
9172
|
-
}, this._onChatEnded = async (
|
|
9173
|
-
var
|
|
9174
|
-
this.setToastMessage(null), this.setTypingState(!1), this.videoConfirmDialogEntry && this.videoConfirmDialogEntry.remove(), this.component.disableInput(),
|
|
9175
|
-
const
|
|
9176
|
-
(
|
|
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.
|
|
9164
|
+
}, this._onVideoPrepared = (r) => {
|
|
9165
|
+
this.showVideo(r.userUrl);
|
|
9166
|
+
}, this._onChatButtonClicked = (r) => {
|
|
9167
|
+
this.showChatOverVideo(r.guestId);
|
|
9168
|
+
}, this._onEndVideoButtonClicked = (r) => {
|
|
9169
|
+
this.handleEndVideoConference(r.guestId);
|
|
9170
|
+
}, this._onPenStatusChange = (r) => {
|
|
9171
|
+
r.penStatus === "on" ? this.setTypingState(!0) : this.setTypingState(!1);
|
|
9172
|
+
}, this._onChatEnded = async (r) => {
|
|
9173
|
+
var a, l;
|
|
9174
|
+
this.setToastMessage(null), this.setTypingState(!1), this.videoConfirmDialogEntry && this.videoConfirmDialogEntry.remove(), this.component.disableInput(), r.showForm && this.showConversationEndedForm();
|
|
9175
|
+
const o = this.component.application.settings;
|
|
9176
|
+
(a = o == null ? void 0 : o.survey) != null && a.shouldUseSurvey && ((l = o == null ? void 0 : o.survey) != null && l.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, (n = this.component.application.settings) != null && n.auth && (this.idHubClient = new $h(
|
|
9178
|
+
(i = this.component.application.settings) == null ? void 0 : i.auth
|
|
9179
|
+
));
|
|
9178
9180
|
}
|
|
9179
9181
|
static getInstance(e, t) {
|
|
9180
9182
|
return t.providerInstance ?? (t.providerInstance = new es(e, t)), t.providerInstance;
|
|
@@ -9319,7 +9321,7 @@ class es extends Qo {
|
|
|
9319
9321
|
var n;
|
|
9320
9322
|
const e = await ((n = this.idHubClient) == null ? void 0 : n.auth());
|
|
9321
9323
|
let t;
|
|
9322
|
-
e && (this.headerComponent.authUrl = e, this.headerComponent.provider = this, t = this.showTunnistusLinkButton(e), this.headerComponent.idref = t, t.actions$.pipe(
|
|
9324
|
+
e && (this.headerComponent.authUrl = e, this.headerComponent.provider = this, this.headerComponent.authState = "non-authenticated", t = this.showTunnistusLinkButton(e), this.headerComponent.idref = t, t.actions$.pipe(
|
|
9323
9325
|
I((i) => i.key === "start-auth"),
|
|
9324
9326
|
V(1)
|
|
9325
9327
|
).subscribe(() => {
|
|
@@ -9351,8 +9353,8 @@ class es extends Qo {
|
|
|
9351
9353
|
}) : this.showWelcomeForm() : this.showEntranceClosedDialog();
|
|
9352
9354
|
}
|
|
9353
9355
|
async initializeChat(e) {
|
|
9354
|
-
var t;
|
|
9355
|
-
(t = this.
|
|
9356
|
+
var t, n;
|
|
9357
|
+
(n = (t = this.component.application.settings) == null ? void 0 : t.auth) != null && n.shouldUseAuth ? await this.startAuthenticationFlow() : this.handleWelcomeForm(e);
|
|
9356
9358
|
}
|
|
9357
9359
|
showTunnistusLinkButton(e) {
|
|
9358
9360
|
const t = new U(
|
|
@@ -9446,10 +9448,7 @@ class es extends Qo {
|
|
|
9446
9448
|
V(1)
|
|
9447
9449
|
).subscribe(async (t) => {
|
|
9448
9450
|
var n;
|
|
9449
|
-
|
|
9450
|
-
const i = await this.engine.getChatStatus();
|
|
9451
|
-
this.headerComponent._logout(), i === "noSession" ? (this._setSessionId(null), this.component.clearMessages(), this.startAuthenticationFlow()) : this.endConversation();
|
|
9452
|
-
}
|
|
9451
|
+
this.logoutConfirmDialogEntry && this.logoutConfirmDialogEntry.remove(), ((n = t.data) == null ? void 0 : n.result) === "logout" && (await this.engine.getChatStatus() === "noSession" ? (this.headerComponent._logout(), this._setSessionId(null), this.component.clearMessages(), this.startAuthenticationFlow()) : this.endConversation());
|
|
9453
9452
|
});
|
|
9454
9453
|
}
|
|
9455
9454
|
showQuitConfirmDialog() {
|
|
@@ -9567,8 +9566,8 @@ class es extends Qo {
|
|
|
9567
9566
|
(e = this.videoIFrameElement) == null || e.remove(), this.guestId = null, this.chatOverlayActive && (this.chatOverlayActive = !1, this.showChatOverlay$.next(this.chatOverlayActive)), this.inVideoCall = !1, this.setHeaderOption();
|
|
9568
9567
|
}
|
|
9569
9568
|
async endConversation() {
|
|
9570
|
-
var e;
|
|
9571
|
-
await ((
|
|
9569
|
+
var e, t, n;
|
|
9570
|
+
(t = (e = this.component.application.settings) == null ? void 0 : e.auth) != null && t.shouldUseAuth && this.headerComponent._logout("chat-ended"), await ((n = this.engine) == null ? void 0 : n.chatQuit());
|
|
9572
9571
|
}
|
|
9573
9572
|
async sendConversationEmail(e) {
|
|
9574
9573
|
var t;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/ace-chat-flamingo",
|
|
3
|
-
"version": "1.1.120-rc.
|
|
3
|
+
"version": "1.1.120-rc.5",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@telia-ace/widget-core-flamingo": "1.1.120-rc.
|
|
6
|
-
"@telia-ace/widget-conversation-flamingo": "1.1.120-rc.
|
|
5
|
+
"@telia-ace/widget-core-flamingo": "1.1.120-rc.5",
|
|
6
|
+
"@telia-ace/widget-conversation-flamingo": "1.1.120-rc.5",
|
|
7
7
|
"rxjs": "^7.8.2",
|
|
8
8
|
"lit": "^3.0.2",
|
|
9
9
|
"@teliads/icons": "^8.4.0",
|
package/provider.d.ts
CHANGED
|
@@ -24,7 +24,6 @@ export declare class ChatProvider extends ConversationProvider {
|
|
|
24
24
|
private guestId;
|
|
25
25
|
private chatOverlayActive;
|
|
26
26
|
private inVideoCall;
|
|
27
|
-
private authSettings;
|
|
28
27
|
constructor(name: string, component: any);
|
|
29
28
|
static getInstance(key: string, component: any): ChatProvider;
|
|
30
29
|
connect(conversationOptions?: Record<string, any>): void;
|