@telia-ace/widget-conversation 1.1.7-rc.2 → 1.1.7-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.
- package/agent.d.ts +0 -3
- package/conversation-controller.d.ts +1 -2
- package/index.js +3 -3
- package/index.mjs +240 -243
- package/package.json +8 -8
- package/user.d.ts +0 -3
package/agent.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Symbol } from '@telia-ace/widget-ui';
|
|
2
|
-
import { Container, Widget } from '@webprovisions/platform';
|
|
3
2
|
import { ConversationEntry } from './conversation-controller';
|
|
4
3
|
import { ConversationProvider } from './conversation-provider';
|
|
5
4
|
import { ConversationMessageSettings, ConverstationMessageItem } from './types';
|
|
@@ -13,8 +12,6 @@ export declare class Agent {
|
|
|
13
12
|
id: string;
|
|
14
13
|
name?: string;
|
|
15
14
|
avatar?: string | Symbol;
|
|
16
|
-
container?: Container;
|
|
17
|
-
widget?: Widget;
|
|
18
15
|
constructor(provider: ConversationProvider, settings: AgentSettings);
|
|
19
16
|
print: (settings: string | ConversationMessageSettings | ConverstationMessageItem<any> | ConverstationMessageItem<any>[], options?: {
|
|
20
17
|
key?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Container, EventListener, EventManager
|
|
1
|
+
import { Container, EventListener, EventManager } from '@webprovisions/platform';
|
|
2
2
|
import { AgentSettings } from './agent';
|
|
3
3
|
import { ConversationProvider } from './conversation-provider';
|
|
4
4
|
import { ConversationMessageContent, ConversationMessageSender, ConversationMessageSettings, ConversationMessageUpdateSettings, ConverstationMessageItem, NormalizedMessageSettings } from './types';
|
|
@@ -56,7 +56,6 @@ export declare class ConversationController {
|
|
|
56
56
|
* Represents the current end user.
|
|
57
57
|
*/
|
|
58
58
|
user: User;
|
|
59
|
-
widget: Widget;
|
|
60
59
|
events: EventManager;
|
|
61
60
|
providers: string[];
|
|
62
61
|
active: boolean;
|
package/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var _=Object.defineProperty;var q=(o,e,t)=>e in o?_(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var
|
|
2
|
-
`):void 0,source:this.createMessageSource(t),alias:this.createAlias(t,s),timestamp:r}}createMessageSource(e){return e}createAlias(e,t){return e===y.System?"system":(t==null?void 0:t.name)||"Me"}handleContactMethod(e){if(!this.cache.has(e))return;const t=this.cache.get(e);let s="";return s=this.appendText(s,`${t.clientName}:`),s=this.appendText(s,t.title),t.description&&(s=this.appendText(s,t.title)),s}getDetails(e,t=!0){if(!e)return"";const{header:s,title:r,label:
|
|
3
|
-
${t}`:e.length?`${e} ${t}`:t}dispose(){this.subscriptions.forEach(e=>{e()})}}class P{constructor(e,t){c(this,"id");c(this,"name");c(this,"avatar");c(this,"container");c(this,"widget");c(this,"print",(e,t,s=null)=>{const r={name:this.name,avatar:this.avatar,id:this.id},i=k(e,t);s=s??i.timestamp;const{events:a}=this.widget;return a==null||a.dispatch("tracking:conversation-message",{sender:"agent"}),this.provider.createEntry(i.key,i.content,y.Agent,r,s)});c(this,"typing",()=>this.provider.setTypingState({name:this.name,avatar:this.avatar}));var s,r;this.provider=e,this.id=t.id||E.uuid(),this.name=t.name,this.avatar=t.avatar,this.container=(s=e.controller)==null?void 0:s.container,this.widget=(r=this.container)==null?void 0:r.get("$widget")}update(e){var r;const{name:t,avatar:s}=e;s===null?this.avatar=void 0:s&&(this.avatar=s),t===null?this.name=void 0:t&&(this.name=t),(r=this.provider.controller)==null||r.events.dispatch("conversation:agent-updated",{agent:this})}}class A{constructor(e,t,s){c(this,"subscriptions",[]);c(this,"options");c(this,"user");this.name=e,this.container=t,this.controller=s,this.user=s==null?void 0:s.user,this.options={silent:!1}}static create(e,t,s){return new A(e,t,s)}createAgent(e={}){var t;if(this.controller){const s=this.controller.getAgentById(e.id),r=s?new P(this,{...s,...e}):new P(this,e);return s||(t=this.controller)==null||t.events.dispatch("conversation:agent-created",{agent:r}),r}}print(e){var t;return(t=this.controller)==null?void 0:t.print(e)}setTypingState(e,t){var s;return(s=this.controller)==null?void 0:s.setTypingState(e,t)}loading(){return this.controller?this.controller.loader():()=>()=>{}}createEntry(e,t,s,r,i){var a;return(a=this.controller)==null?void 0:a.createEntry(e,t,s,r,i)}dispose(){var e;process.env.NODE_ENV!=="production"&&console.log(`conversation-provider: dispose (${this.name})`),(e=this.controller)==null||e.disposeProvider(this),this.controller=null,this.subscriptions.forEach(t=>t())}isRehydrated(){var e;return((e=this.controller)==null?void 0:e.isRehydrated())||Promise.resolve(!1)}getHistory(){var e;return((e=this.controller)==null?void 0:e.getHistory())||[]}complete(){var e;(e=this.controller)==null||e.onCompleteProvider()}setOptions(e={silent:!1}){this.options=e}onUnreadMessage(e){var t;if(this.controller){const s=(t=this.controller)==null?void 0:t.onUnreadMessage(e);return this.subscriptions.push(s),()=>{s()}}}onMounted(e){var t;if(this.controller){const s=(t=this.controller)==null?void 0:t.events.subscribe("conversation:component-mount-changed",e);return this.subscriptions.push(s),e({},this.controller.getComponentMountedState()),()=>{s()}}}}const O=o=>`conversation-${o}`;class K{constructor(){c(this,"_locking",Promise.resolve());c(this,"_locks",0)}isLocked(){return this._locks>0}lock(){this._locks+=1;let e;const t=new Promise(r=>e=()=>{this._locks-=1,r()}),s=this._locking.then(()=>e);return this._locking=this._locking.then(()=>t),s}}class Q{constructor(e,t,s){c(this,"sessionStorageKey");c(this,"locker",new K);c(this,"initialStoredAgents",[]);this.container=e,this.conversation=t,this.enabled=s,this.sessionStorageKey=O(t.id),t.onStarted(async()=>{if(t.messages.length>0)return;const{agents:r}=await this.read(),i=[];r&&r.forEach(n=>{const d=t.providerIndex(n.providerName),h=d>-1?t.registeredProviders[d]:t.createProvider(n.providerName),u=new P(h,{name:n.name,avatar:n.avatar,id:n.id});i.push(u)});const{messages:a}=await this.read();a.forEach(n=>{switch(n.type){case"agent":{const d=i.find(h=>{var u;return h.id===((u=n.sender)==null?void 0:u.id)});d&&d.print(n.content.items||n.content,{key:n.key},n.timestamp);return}case"user":{t.user.print(n.content.items||n.content,{key:n.key},n.timestamp);return}case"system":default:t.print(n.content.items||n.content,n.timestamp)}})}),t.onMessageCreated(async(r,i)=>{this.write(i.message,"messages")}),t.events.subscribe("conversation:agent-created",async(r,i)=>{const a={id:i.agent.id,name:i.agent.name,avatar:i.agent.avatar,providerName:i.agent.provider.name};await this.write(a,"agents")}),t.events.subscribe("conversation:agent-updated",async(r,i)=>{const{agents:a}=await this.read();await this.write([...a.map(n=>n.id===i.agent.id?{...n,name:i.agent.name,avatar:i.agent.avatar}:n)],"agents","update")})}setInitialData(e){this.initialStoredAgents=e.agents}async isRehydrated(){const{messages:e}=await this.read();return e.length>0}getStoredAgent(e){if(this.enabled)return this.initialStoredAgents.find(t=>t.id===e)}async write(e,t,s="add"){if(!this.enabled)return;const r=await this.locker.lock();return p.createStorageWriter(this.container,this.sessionStorageKey,p.StorageCategory.Necessary).then(async i=>{if(s==="add"){const a=await this.read();if(t==="messages"&&a.messages.findIndex(d=>d.key===e.key)>-1){r();return}const n={...a};return t==="messages"?n.messages=[...n.messages,e]:t==="agents"&&(n.agents=[...n.agents,e]),i({...a,...n}).then(()=>{r()})}if(s==="update"&&t==="agents"){const a=await this.read();return i({...a,agents:e}).then(()=>{r()})}return i(e).then(()=>{r()})})}async read(){return p.readStorage(this.container,this.sessionStorageKey).then(e=>e||{messages:[],agents:[]})}}class j{constructor(e){c(this,"container");c(this,"widget");c(this,"print",(e,t,s=null)=>{const r=k(e,t);s=s??r.timestamp;const{events:i}=this.widget;return i==null||i.dispatch("tracking:conversation-message",{sender:"user"}),this.controller.createEntry(r.key,r.content,y.User,void 0,s)});var t;this.controller=e,this.container=e==null?void 0:e.container,this.widget=(t=this.container)==null?void 0:t.get("$widget")}}const x=async(o,e,t)=>{const s=await o.getAsync("conversation"),r=await o.getAsync("components"),i=s.controllers.find(a=>a.conversation.id===e);if(i){const a=[...i.conversation.providers];a.forEach(d=>{i.conversation.setProviderOptions(d,{silent:!0})}),i.conversation.queueProviders(a),i.conversation.setProviders([t]);const n=r.components().ofType("conversation");r.write({key:"setConversationProvider",attributes:{properties:{providers:[t]}},target:n,provider:"localStorage"})}};class ${constructor(e){this.writer=e}update(e){const t=this.getNormalizedSettings(e);this.writer(t)}remove(){this.writer(null)}getNormalizedSettings(e){return typeof e=="string"?{body:e}:e.length>-1&&typeof e=="object"?{items:e}:e}}var y=(o=>(o.User="user",o.Agent="agent",o.System="system",o))(y||{});const k=(o,e)=>{let t,s=(e==null?void 0:e.key)||E.uuid(),r=Date.now();if(Array.isArray(o)&&o.length>-1)typeof o[0]=="string"?t={items:[o]}:t={items:o};else if(typeof o=="string")t={body:o};else if(o=o||{},o.type)t={...o};else{if(t={body:o.body,actions:o.actions,title:o.title},o.key&&(s=o.key),o.timestamp&&(r=o.timestamp),typeof o.form=="function"){const i=L.FormBuilder.create(s);o.form(i);const a=i.get();t.form=a}o.timestamp===null&&(r=null)}return{content:t,key:s,timestamp:r}},W=(o,e)=>{if(!e)return;const t=JSON.stringify(e),s=o.findIndex(r=>t===JSON.stringify(r));if(s>-1)return o.splice(s,1)};class H{constructor(e,t,s){c(this,"formHandlers",{});c(this,"user",new j(this));c(this,"widget");c(this,"events");c(this,"providers",[]);c(this,"active",!1);c(this,"queuedProviders",[]);c(this,"registeredProviders",[]);c(this,"loaders",0);c(this,"componentMounted",!1);c(this,"store");c(this,"messages",[]);c(this,"typingActors",[]);c(this,"conversationHistory");c(this,"print",(e,t=null)=>{const s=k(e);t=t??s.timestamp;const{events:r}=this.widget;return r.dispatch("tracking:conversation-message",{sender:"system"}),this.createEntry(s.key,s.content,"system",void 0,t)});this.container=e,this.id=t,this.widget=e.get("$widget"),this.events=this.widget.events.createChild(this),this.store=new Q(e,this,s.rehydrate),this.conversationHistory=new U(this)}setInitialStorage(e){this.store.setInitialData(e)}setProviders(e){const t=[],s=[];this.providers.reduce((r,i)=>(e.indexOf(i)===-1&&r.push(i),r),[]).forEach(r=>{const i=this.providers.indexOf(r);i>-1&&(t.push(r),this.providers.splice(i,1))}),e.forEach(r=>{this.providers.indexOf(r)===-1&&(s.push(r),this.providers.push(r))}),(s.length||t.length)&&this.events.dispatch("conversation:providers-changed",{added:s,removed:t})}createProvider(e){const t=this.providerIndex(e);if(t>-1)return this.registeredProviders[t];const s=A.create(e,this.container,this);return this.registeredProviders.push(s),s}providerIndex(e){return this.registeredProviders.findIndex(t=>t.name===e)}getAgentById(e){if(e)return this.store.getStoredAgent(e)}dispose(){this.conversationHistory.dispose(),this.registeredProviders.forEach(e=>e.dispose()),this.messages=[],this.events.dispatch("conversation:controller-disposed",this),this.active=!1}onDispose(e){return this.events.subscribe("conversation:controller-disposed",e)}onStarted(e){return this.events.subscribe("conversation:started",e)}onMessageCreated(e){return this.events.subscribe("conversation:message-created",e)}isRehydrated(){return this.store.isRehydrated()}disposeProvider(e){const t=this.providerIndex(e.name);t>-1&&this.registeredProviders.splice(t,1),this.events.dispatch("conversation:providers-changed",{removed:[e.name]}),this.registeredProviders.length||this.dispose()}onProvidersChange(e){return this.events.subscribe("conversation:providers-changed",e)}setComponentMountedState(e){this.componentMounted!==e&&(this.componentMounted=e,e&&(this.events.dispatch("conversation:unread-message",!1),this.events.dispatch("conversation:started",!0),this.active=!0),this.events.dispatch("conversation:component-mount-changed",e))}setProviderOptions(e,t){const s=this.providerIndex(e);s>-1&&this.registeredProviders[s].setOptions(t)}changeProvider(e){this.registeredProviders.find(s=>s.name===e)&&x(this.container,this.id,e)}queueProviders(e){this.queuedProviders=e}onCompleteProvider(){const e=this.queuedProviders.pop();e&&x(this.container,this.id,e)}getComponentMountedState(){return this.componentMounted}onUnreadMessage(e){return this.events.subscribe("conversation:unread-message",e)}createEntry(e,t,s,r,i){const a={key:e,content:t,type:s,sender:r||null,timestamp:i||i===null?i:Date.now()};this.messages.push(a),a.type==="agent"&&W(this.typingActors,r);const n=new $(d=>{if(d!==null){const{timestamp:h=void 0,...u}=d;a.content=u,h&&(a.timestamp=h)}else{const h=this.messages.indexOf(a);a.content=null,h>-1&&this.messages.splice(h,1)}this.events.dispatch("conversation:message-updated",{message:a}),this.update()});return this.events.dispatch("conversation:message-created",{message:a}),this.update(),this.componentMounted||this.events.dispatch("conversation:unread-message",!0),n}update(){this.events.dispatch("conversation:updated",{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors})}getMessageStream(){return{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors}}setTypingState(e,t){return this.typingActors.indexOf(e)===-1&&(this.typingActors.push(e),this.update()),()=>{W(this.typingActors,e),this.update()}}loader(){this.loaders=this.loaders+1;let e=!1;return this.loaders===1&&this.update(),()=>{e||(e=!0,this.loaders=this.loaders-1,this.loaders===0&&this.update())}}submitForm(e,t){this.formHandlers[e]={...this.formHandlers[e],submit:t}}validateForm(e,t){this.formHandlers[e]={...this.formHandlers[e],validate:t}}getHistory(){return this.conversationHistory.getConversationLogs()}}const F=(o,e)=>{const t=o.split("_contact");return e.widgets.get(t[0])},I=o=>{const e=o.get("$widget"),{name:t,implementation:s}=o.get("$widget"),r=t.indexOf("_contact")>-1?F(t,s):e,{data:i}=o.get("$settings"),{trigger:a}=r.container.get("$settings"),n=`${t.replace("_contact-method","").replace("_contact","")}_contact-method`,d=s.widgets.get(n);return d&&!a?{chatWidget:d,mainWidget:r,data:i}:{mainWidget:r,data:i}},G=o=>{const{chatWidget:e}=I(o);return!!e},R=(o,e,t)=>{const{mainWidget:s,data:r,chatWidget:i}=I(o);return i?i.state==="activated"?i.invoke("open").then(()=>{i.container.getAsync("conversation").then(a=>{a.navigateToConversationIfActive(e.id).then(()=>M.closeAllModals(o))})}):i.activate().then(()=>{const{trigger:a}=i.container.get("$settings");return a.action="hide",i.invoke("setSettings",()=>({data:r,trigger:a,activate:!0})).then(()=>i.container.getAsync("components").then(n=>{const d=n.components().ofType("contact-method");n.write({key:"setContactMethodId",attributes:{properties:{id:e.id,guideId:e.guideId}},target:d,provider:"localStorage"});const h=n.components().ofType("conversation");n.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:h,provider:"localStorage"})}))}).then(()=>i.invoke("attach",{key:"contact-method",triggerDOMElement:t,withRenderState:"open"})).then(()=>(p.createStorageWriter(i.container,"activeStickyWidget",p.StorageCategory.Necessary,{medium:p.StorageMedium.Local,scope:p.StorageScope.Implementation}).then(a=>a(i.name)),i.container.getAsync("conversation").then(a=>{a.setConversationEndedBehavior(S.Deactivate)}).then(()=>M.closeAllModals(o)).then(()=>!1))):(s.container.getAsync("conversation").then(a=>a.navigateToConversationIfActive(e.id).then(()=>a.setConversationEndedBehavior(S.Navigate))),!i)},J=(o,e,t="conversation")=>{const{mainWidget:s,chatWidget:r}=I(o);return r?r.container.getAsync("router").then(i=>{i.navigate(t,{id:e.id})}):s.container.getAsync("conversation").then(i=>{var a;(a=i.setConversationEndedBehavior(S.Navigate))==null||a.then(()=>{s.container.getAsync("router").then(n=>{s.container.getAsync("components").then(d=>{const h=d.components().ofType("conversation");d.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:h,provider:"localStorage"})}).then(()=>{n.navigate(t,{id:e.id})})})})})},b="conversations";var S=(o=>(o.Deactivate="deactivate",o.Navigate="navigate",o.None="none",o))(S||{});class w{constructor(e,t){c(this,"events");c(this,"controllers",[]);c(this,"providers",[]);c(this,"disposeProviders",{});c(this,"subscriptions",[]);c(this,"storageWriter",null);c(this,"router",null);c(this,"buttonQuery",null);c(this,"sessionInfo",null);this.container=e,this.components=t;const s=e.get("$widget");this.events=s.events.createChild(this)}initialize(){p.createStorageWriter(this.container,b,p.StorageCategory.Necessary,{medium:p.StorageMedium.Local}).then(e=>this.storageWriter=e),p.readStorage(this.container,b,p.StorageMedium.Local).then(e=>{this.buttonQuery=this.components.components().ofType("conversation-return-button"),e&&(this.sessionInfo=e,e.id&&e.route&&this.writeToComponents({active:!0,alert:{show:!1}}))}),this.container.getAsync("router").then(e=>this.router=e),this.events.subscribe("conversation:ended",(e,t)=>{var s,r,i;switch((s=this.sessionInfo)==null?void 0:s.conversationEndedBehavior){case"deactivate":this.container.get("$widget").deactivate();break;case"navigate":const n=(r=this.router)==null?void 0:r.getInitialRoute();n&&((i=this.router)==null||i.navigate(n.name));break}this.writeToComponents({active:!1}),this.sessionInfo=null,this.storageWriter&&this.storageWriter()})}addSubscription(e){this.subscriptions.push(e)}static getInstance(e,t="conversation"){return E.lock(e)(()=>e.getAsync(t).then(s=>{let r=s;return r||D.ComponentPlatform.getInstance(e).then(i=>(r=new w(e,i),r.initialize(),e.registerAsync(t,()=>r),r))}))}navigateToConversationIfActive(e){return p.readStorage(this.container,b,p.StorageMedium.Local).then(t=>{var s;if(t&&t.id===e&&t.route){const{name:r,params:i}=t.route;(s=this.router)==null||s.navigate(r,i)}})}setConversationEndedBehavior(e){return p.readStorage(this.container,b,p.StorageMedium.Local).then(t=>{let s=t;return s?s.conversationEndedBehavior=e:s={conversationEndedBehavior:e},this.sessionInfo=s,this.storageWriter&&this.storageWriter(this.sessionInfo)||Promise.resolve()})}async createController(e,t){const s=O(e),{agents:r}=await p.readStorage(this.container,s)||{agents:[]},i=this.controllers.findIndex(n=>n.conversation.id===e);let a;return i>-1?a=this.controllers[i].conversation:a=new H(this.container,e,t),a.setInitialStorage({agents:r||[]}),a}registerProvider(e,t){const s={name:e,handler:t};this.providers.push(s),this.controllers.filter(r=>r.conversation.providers.indexOf(e)>-1).forEach(r=>{this.invokeHandler(s,r)})}registerController(e,t){const s=this.controllers.findIndex(i=>i.conversation.id===e.id);let r;if(s<0){r={conversation:e,component:t},this.controllers.push(r);const i=a=>{a&&this.providers.filter(n=>a.indexOf(n.name)>-1).forEach(n=>{this.invokeHandler(n,r)})};return this.subscriptions.push(e.onDispose((a,n)=>{const d=this.controllers.findIndex(h=>h.conversation===n);d>-1&&this.controllers.splice(d,1),this.components.components().ofType("conversation-return-button").select().writeProperties({active:!1}),this.events.dispatch("conversation:ended",{},{bubbles:!0})})),this.subscriptions.push(e.onProvidersChange((a,n)=>{const{added:d,removed:h=[]}=n;h.forEach(u=>{(this.disposeProviders[u]||[]).forEach(l=>{l()})}),i(d)})),this.subscriptions.push(e.onStarted((a,n)=>{var h,u;const d={id:e.id,route:(h=this.router)==null?void 0:h.getRouteData(),conversationEndedBehavior:(u=this.sessionInfo)==null?void 0:u.conversationEndedBehavior};this.sessionInfo=d,this.storageWriter&&this.storageWriter(d),this.writeToComponents({active:n})})),this.subscriptions.push(e.onUnreadMessage((a,n)=>{this.events.dispatch("conversation:unread-message",n),this.writeToComponents({alert:{show:n}})})),i(e.providers),!0}return r=this.controllers[s],!1}writeToComponents(e,t="conversationReturnButtonState"){this.buttonQuery&&this.components.write({key:"conversationReturnButtonState",attributes:{properties:e},target:this.buttonQuery,provider:"localStorage"})}invokeHandler(e,t){const s=e.handler(t.conversation.createProvider(e.name),t.component);s&&(this.disposeProviders[e.name]||(this.disposeProviders[e.name]=[]),this.disposeProviders[e.name].push(s))}getComponentRoute(){return p.readStorage(this.container,b,p.StorageMedium.Local).then(e=>e==null?void 0:e.route)}dispose(){Object.keys(this.disposeProviders).forEach(e=>{this.disposeProviders[e].forEach(t=>{t()})}),this.subscriptions.forEach(e=>{e()}),this.controllers=[],this.providers=[]}static async handleContactMethodClick(e,t,s,r){if(G(t)){e.preventDefault();let i=document.getElementById("humany-dynamic-anchor");i||(i=document.createElement("a"),i.setAttribute("href","#"),i.id="humany-dynamic-anchor",document.body.appendChild(i)),R(t,s,i)}R(t,s)}static async handleContactMethodSubmit(e,t){var s,r;return(r=(s=t==null?void 0:t.body.form.meta)==null?void 0:s.conversation)!=null&&r.id?x(e,t.body.form.meta.conversation.id,t.clientName):J(e,t)}}const V=(o,e)=>o.reduce((t,s,r)=>{var a,n;const i={...s,content:[{...s.content,key:s.key}]};if(t.length>0&&s.type!==y.System){const d=t[t.length-1];if((!e&&e!==0||Math.abs(d.timestamp-s.timestamp)<e)&&((a=d.sender)==null?void 0:a.name)===((n=s.sender)==null?void 0:n.name)&&d.type===s.type)return d.timestamp=s.timestamp,d.content.push({...s.content,key:s.key}),t}return t.push(i),t},[]),Y=o=>Promise.all([w.getInstance(o),o.getAsync("router")]).then(([e,t])=>N.createReactComponent(o,"conversation",Promise.resolve().then(()=>require("./conversation-eaa1e841.js")),async s=>{const{rehydrate:r=!1}=s.properties(),a=t.getRouteData().params.id||s.node.name||"component",n=await e.createController(a,{rehydrate:r}),d=e.registerController(n,s),h=3*60*1e3,u=v=>{const{providers:g=[]}=v;if(g){const f=Array.isArray(g)?g:[g];return n.setProviders(f),f}};u(s.properties(u)),n.setComponentMountedState(!0);const l=v=>{const{loading:g,typingActors:f,messages:C}=v;s.writeProperties({loading:g,typingActors:f,messages:V(C,h)})};l(n.getMessageStream()),d&&(s.writeProperties({conversationControllerId:n.id}),s.actions.create("user-submit",(v,g)=>{if(g){const{preventDefault:f,validationPromise:C}=g;if(f){C&&C().then(T=>{T&&n.user.print(T)});return}}n.user.print(v.text)}),s.actions.create("user-typing",(v,g)=>{}),s.actions.create("form",(v,g)=>{}),s.actions.create("action",(v,g)=>{}),s.actions.create("overlay-mounted",(v,g)=>{}),s.actions.create("show-overlay",(v,g)=>{s.writeProperties({overlay:{conversation:!1,secondary:!1}})}),s.actions.create("hide-overlay",(v,g)=>{s.writeProperties({overlay:null})}),s.actions.create("show-overlay-conversation",(v,g)=>{s.writeProperties({overlay:{conversation:!0,secondary:!1}})}),s.actions.create("hide-overlay-conversation",(v,g)=>{s.writeProperties({overlay:{conversation:!1,secondary:!1}})}));const m=n.events.subscribe("conversation:updated",(v,g)=>{l(g)});return()=>{n.setComponentMountedState(!1),m(),n.active||l({messages:[],typingActors:[],loading:!1})}},{reuseController:!0})),X=o=>Promise.all([D.ComponentPlatform.getInstance(o),w.getInstance(o),o.getAsync("router")]).then(([e,t,s])=>N.createReactComponent(o,"conversation-return-button",Promise.resolve().then(()=>require("./return-button-f1f43984.js")),r=>{r.actions.create("toggle",(i={})=>{var a;(a=t.getComponentRoute())==null||a.then(n=>{n&&s.navigate(n.name,n.params)})})}));var B=(o=>(o.LinkList="link-list",o.Separator="separator",o.ButtonList="button-list",o.ItemList="item-list",o.Text="text",o.HTML="html",o.VideoRequest="video-request",o))(B||{});const Z=(o,e,t)=>o.getAsync("componentResolver").then(async s=>{(await w.getInstance(o)).addSubscription(s.registerComponent(e,z.lazy(()=>t)))});exports.Agent=P;exports.ConversationComponent=Y;exports.ConversationController=H;exports.ConversationEndedBehavior=S;exports.ConversationEntry=$;exports.ConversationMessageListItemType=B;exports.ConversationMessageType=y;exports.ConversationPlatform=w;exports.ConversationProvider=A;exports.ConversationReturnButtonComponent=X;exports.registerCustomMessageComponent=Z;
|
|
1
|
+
"use strict";var _=Object.defineProperty;var q=(o,e,t)=>e in o?_(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var h=(o,e,t)=>(q(o,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("@telia-ace/widget-core"),p=require("@telia-ace/widget-services"),E=require("@telia-ace/widget-utilities"),L=require("@telia-ace/widget-forms"),M=require("@telia-ace/widget-plugins"),N=require("@telia-ace/widget-ui"),z=require("react");class U{constructor(e){h(this,"cache",new Map);h(this,"subscriptions",[]);this.controller=e;const{events:t}=e.container.get("$widget"),s=t.subscribe("data-client:fetched",(r,n)=>{n.type==="contact-method"&&this.cache.set(n.response.id,n.response)});this.subscriptions.push(s)}getConversationLogs(){return this.controller.messages.reduce((t,s)=>{const r=k(s),{key:n,content:a,type:i,sender:c,timestamp:d}=r.content,u=this.parseEntry(a,i,c,d);return u&&t.push(u),t},[])}parseEntry(e,t,s,r){const n=d=>{let u=[],l=[],m;if(Array.isArray(d)){const[g,f]=d;m=f}else m=d;return this.createMessageContent(m).length&&(l=[...l,this.createMessageContent(m)]),u=[...u,...this.createMessageOptions(m)],{messagesAsList:l,options:u}};let a=[],i=[];if(Array.isArray(e.items)){const{items:d}=e;d.forEach(u=>{const l=n(u);a=[...a,...l.options],i=[...i,...l.messagesAsList]})}else{const d=n(e);a=[...a,...d.options],i=[...i,...d.messagesAsList]}return{options:a,message:i.length?i.join(`
|
|
2
|
+
`):void 0,source:this.createMessageSource(t),alias:this.createAlias(t,s),timestamp:r}}createMessageSource(e){return e}createAlias(e,t){return e===y.System?"system":(t==null?void 0:t.name)||"Me"}handleContactMethod(e){if(!this.cache.has(e))return;const t=this.cache.get(e);let s="";return s=this.appendText(s,`${t.clientName}:`),s=this.appendText(s,t.title),t.description&&(s=this.appendText(s,t.title)),s}getDetails(e,t=!0){if(!e)return"";const{header:s,title:r,label:n,description:a,text:i,html:c,body:d,contactMethodId:u}=e;let l="";if(u){const m=this.handleContactMethod(u.toString());m&&(l=this.appendText(l,m,t))}return s&&(l=this.appendText(l,s,t)),r&&(l=this.appendText(l,r,t)),a&&(l=this.appendText(l,a,t)),i&&(l=this.appendText(l,i,t)),n&&(l=this.appendText(l,n,t)),c&&(l=this.appendText(l,c,t)),d&&typeof d=="string"&&(l=this.appendText(l,d,t)),l}createMessageContent(e){let t="";return t=this.getDetails(e),t}createMessageOptions(e){let t=[],s=[];return Array.isArray(e==null?void 0:e.actions)?s=e.actions:typeof(e==null?void 0:e.actions)=="object"&&(s=Object.entries(e.actions).map(([r,n])=>({actionKey:r,label:n}))),s.length&&(t=s.map(r=>this.getDetails(r,!1))),t}appendText(e,t,s=!0){return s&&e.length?`${e}
|
|
3
|
+
${t}`:e.length?`${e} ${t}`:t}dispose(){this.subscriptions.forEach(e=>{e()})}}class P{constructor(e,t){h(this,"id");h(this,"name");h(this,"avatar");h(this,"print",(e,t,s=null)=>{var i,c,d;const r={name:this.name,avatar:this.avatar,id:this.id},n=k(e,t);s=s??n.timestamp;const a=(c=(i=this.provider)==null?void 0:i.controller)==null?void 0:c.container.get("$widget");return(d=a==null?void 0:a.events)==null||d.dispatch("tracking:conversation-message",{sender:"agent"}),this.provider.createEntry(n.key,n.content,y.Agent,r,s)});h(this,"typing",()=>this.provider.setTypingState({name:this.name,avatar:this.avatar}));this.provider=e,this.id=t.id||E.uuid(),this.name=t.name,this.avatar=t.avatar}update(e){var r;const{name:t,avatar:s}=e;s===null?this.avatar=void 0:s&&(this.avatar=s),t===null?this.name=void 0:t&&(this.name=t),(r=this.provider.controller)==null||r.events.dispatch("conversation:agent-updated",{agent:this})}}class A{constructor(e,t,s){h(this,"subscriptions",[]);h(this,"options");h(this,"user");this.name=e,this.container=t,this.controller=s,this.user=s==null?void 0:s.user,this.options={silent:!1}}static create(e,t,s){return new A(e,t,s)}createAgent(e={}){var t;if(this.controller){const s=this.controller.getAgentById(e.id),r=s?new P(this,{...s,...e}):new P(this,e);return s||(t=this.controller)==null||t.events.dispatch("conversation:agent-created",{agent:r}),r}}print(e){var t;return(t=this.controller)==null?void 0:t.print(e)}setTypingState(e,t){var s;return(s=this.controller)==null?void 0:s.setTypingState(e,t)}loading(){return this.controller?this.controller.loader():()=>()=>{}}createEntry(e,t,s,r,n){var a;return(a=this.controller)==null?void 0:a.createEntry(e,t,s,r,n)}dispose(){var e;process.env.NODE_ENV!=="production"&&console.log(`conversation-provider: dispose (${this.name})`),(e=this.controller)==null||e.disposeProvider(this),this.controller=null,this.subscriptions.forEach(t=>t())}isRehydrated(){var e;return((e=this.controller)==null?void 0:e.isRehydrated())||Promise.resolve(!1)}getHistory(){var e;return((e=this.controller)==null?void 0:e.getHistory())||[]}complete(){var e;(e=this.controller)==null||e.onCompleteProvider()}setOptions(e={silent:!1}){this.options=e}onUnreadMessage(e){var t;if(this.controller){const s=(t=this.controller)==null?void 0:t.onUnreadMessage(e);return this.subscriptions.push(s),()=>{s()}}}onMounted(e){var t;if(this.controller){const s=(t=this.controller)==null?void 0:t.events.subscribe("conversation:component-mount-changed",e);return this.subscriptions.push(s),e({},this.controller.getComponentMountedState()),()=>{s()}}}}const O=o=>`conversation-${o}`;class K{constructor(){h(this,"_locking",Promise.resolve());h(this,"_locks",0)}isLocked(){return this._locks>0}lock(){this._locks+=1;let e;const t=new Promise(r=>e=()=>{this._locks-=1,r()}),s=this._locking.then(()=>e);return this._locking=this._locking.then(()=>t),s}}class Q{constructor(e,t,s){h(this,"sessionStorageKey");h(this,"locker",new K);h(this,"initialStoredAgents",[]);this.container=e,this.conversation=t,this.enabled=s,this.sessionStorageKey=O(t.id),t.onStarted(async()=>{if(t.messages.length>0)return;const{agents:r}=await this.read(),n=[];r&&r.forEach(i=>{const c=t.providerIndex(i.providerName),d=c>-1?t.registeredProviders[c]:t.createProvider(i.providerName),u=new P(d,{name:i.name,avatar:i.avatar,id:i.id});n.push(u)});const{messages:a}=await this.read();a.forEach(i=>{switch(i.type){case"agent":{const c=n.find(d=>{var u;return d.id===((u=i.sender)==null?void 0:u.id)});c&&c.print(i.content.items||i.content,{key:i.key},i.timestamp);return}case"user":{t.user.print(i.content.items||i.content,{key:i.key},i.timestamp);return}case"system":default:t.print(i.content.items||i.content,i.timestamp)}})}),t.onMessageCreated(async(r,n)=>{this.write(n.message,"messages")}),t.events.subscribe("conversation:agent-created",async(r,n)=>{const a={id:n.agent.id,name:n.agent.name,avatar:n.agent.avatar,providerName:n.agent.provider.name};await this.write(a,"agents")}),t.events.subscribe("conversation:agent-updated",async(r,n)=>{const{agents:a}=await this.read();await this.write([...a.map(i=>i.id===n.agent.id?{...i,name:n.agent.name,avatar:n.agent.avatar}:i)],"agents","update")})}setInitialData(e){this.initialStoredAgents=e.agents}async isRehydrated(){const{messages:e}=await this.read();return e.length>0}getStoredAgent(e){if(this.enabled)return this.initialStoredAgents.find(t=>t.id===e)}async write(e,t,s="add"){if(!this.enabled)return;const r=await this.locker.lock();return p.createStorageWriter(this.container,this.sessionStorageKey,p.StorageCategory.Necessary).then(async n=>{if(s==="add"){const a=await this.read();if(t==="messages"&&a.messages.findIndex(c=>c.key===e.key)>-1){r();return}const i={...a};return t==="messages"?i.messages=[...i.messages,e]:t==="agents"&&(i.agents=[...i.agents,e]),n({...a,...i}).then(()=>{r()})}if(s==="update"&&t==="agents"){const a=await this.read();return n({...a,agents:e}).then(()=>{r()})}return n(e).then(()=>{r()})})}async read(){return p.readStorage(this.container,this.sessionStorageKey).then(e=>e||{messages:[],agents:[]})}}class j{constructor(e){h(this,"print",(e,t,s=null)=>{var a,i;const r=k(e,t);return s=s??r.timestamp,(i=((a=this.controller)==null?void 0:a.container.get("$widget")).events)==null||i.dispatch("tracking:conversation-message",{sender:"user"}),this.controller.createEntry(r.key,r.content,y.User,void 0,s)});this.controller=e}}const x=async(o,e,t)=>{const s=await o.getAsync("conversation"),r=await o.getAsync("components"),n=s.controllers.find(a=>a.conversation.id===e);if(n){const a=[...n.conversation.providers];a.forEach(c=>{n.conversation.setProviderOptions(c,{silent:!0})}),n.conversation.queueProviders(a),n.conversation.setProviders([t]);const i=r.components().ofType("conversation");r.write({key:"setConversationProvider",attributes:{properties:{providers:[t]}},target:i,provider:"localStorage"})}};class ${constructor(e){this.writer=e}update(e){const t=this.getNormalizedSettings(e);this.writer(t)}remove(){this.writer(null)}getNormalizedSettings(e){return typeof e=="string"?{body:e}:e.length>-1&&typeof e=="object"?{items:e}:e}}var y=(o=>(o.User="user",o.Agent="agent",o.System="system",o))(y||{});const k=(o,e)=>{let t,s=(e==null?void 0:e.key)||E.uuid(),r=Date.now();if(Array.isArray(o)&&o.length>-1)typeof o[0]=="string"?t={items:[o]}:t={items:o};else if(typeof o=="string")t={body:o};else if(o=o||{},o.type)t={...o};else{if(t={body:o.body,actions:o.actions,title:o.title},o.key&&(s=o.key),o.timestamp&&(r=o.timestamp),typeof o.form=="function"){const n=L.FormBuilder.create(s);o.form(n);const a=n.get();t.form=a}o.timestamp===null&&(r=null)}return{content:t,key:s,timestamp:r}},W=(o,e)=>{if(!e)return;const t=JSON.stringify(e),s=o.findIndex(r=>t===JSON.stringify(r));if(s>-1)return o.splice(s,1)};class H{constructor(e,t,s){h(this,"formHandlers",{});h(this,"user",new j(this));h(this,"events");h(this,"providers",[]);h(this,"active",!1);h(this,"queuedProviders",[]);h(this,"registeredProviders",[]);h(this,"loaders",0);h(this,"componentMounted",!1);h(this,"store");h(this,"messages",[]);h(this,"typingActors",[]);h(this,"conversationHistory");h(this,"print",(e,t=null)=>{const s=k(e);t=t??s.timestamp;const r=this.container.get("$widget");return r==null||r.events.dispatch("tracking:conversation-message",{sender:"system"}),this.createEntry(s.key,s.content,"system",void 0,t)});this.container=e,this.id=t;const r=e.get("$widget");this.events=r.events.createChild(this),this.store=new Q(e,this,s.rehydrate),this.conversationHistory=new U(this)}setInitialStorage(e){this.store.setInitialData(e)}setProviders(e){const t=[],s=[];this.providers.reduce((r,n)=>(e.indexOf(n)===-1&&r.push(n),r),[]).forEach(r=>{const n=this.providers.indexOf(r);n>-1&&(t.push(r),this.providers.splice(n,1))}),e.forEach(r=>{this.providers.indexOf(r)===-1&&(s.push(r),this.providers.push(r))}),(s.length||t.length)&&this.events.dispatch("conversation:providers-changed",{added:s,removed:t})}createProvider(e){const t=this.providerIndex(e);if(t>-1)return this.registeredProviders[t];const s=A.create(e,this.container,this);return this.registeredProviders.push(s),s}providerIndex(e){return this.registeredProviders.findIndex(t=>t.name===e)}getAgentById(e){if(e)return this.store.getStoredAgent(e)}dispose(){this.conversationHistory.dispose(),this.registeredProviders.forEach(e=>e.dispose()),this.messages=[],this.events.dispatch("conversation:controller-disposed",this),this.active=!1}onDispose(e){return this.events.subscribe("conversation:controller-disposed",e)}onStarted(e){return this.events.subscribe("conversation:started",e)}onMessageCreated(e){return this.events.subscribe("conversation:message-created",e)}isRehydrated(){return this.store.isRehydrated()}disposeProvider(e){const t=this.providerIndex(e.name);t>-1&&this.registeredProviders.splice(t,1),this.events.dispatch("conversation:providers-changed",{removed:[e.name]}),this.registeredProviders.length||this.dispose()}onProvidersChange(e){return this.events.subscribe("conversation:providers-changed",e)}setComponentMountedState(e){this.componentMounted!==e&&(this.componentMounted=e,e&&(this.events.dispatch("conversation:unread-message",!1),this.events.dispatch("conversation:started",!0),this.active=!0),this.events.dispatch("conversation:component-mount-changed",e))}setProviderOptions(e,t){const s=this.providerIndex(e);s>-1&&this.registeredProviders[s].setOptions(t)}changeProvider(e){this.registeredProviders.find(s=>s.name===e)&&x(this.container,this.id,e)}queueProviders(e){this.queuedProviders=e}onCompleteProvider(){const e=this.queuedProviders.pop();e&&x(this.container,this.id,e)}getComponentMountedState(){return this.componentMounted}onUnreadMessage(e){return this.events.subscribe("conversation:unread-message",e)}createEntry(e,t,s,r,n){const a={key:e,content:t,type:s,sender:r||null,timestamp:n||n===null?n:Date.now()};this.messages.push(a),a.type==="agent"&&W(this.typingActors,r);const i=new $(c=>{if(c!==null){const{timestamp:d=void 0,...u}=c;a.content=u,d&&(a.timestamp=d)}else{const d=this.messages.indexOf(a);a.content=null,d>-1&&this.messages.splice(d,1)}this.events.dispatch("conversation:message-updated",{message:a}),this.update()});return this.events.dispatch("conversation:message-created",{message:a}),this.update(),this.componentMounted||this.events.dispatch("conversation:unread-message",!0),i}update(){this.events.dispatch("conversation:updated",{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors})}getMessageStream(){return{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors}}setTypingState(e,t){return this.typingActors.indexOf(e)===-1&&(this.typingActors.push(e),this.update()),()=>{W(this.typingActors,e),this.update()}}loader(){this.loaders=this.loaders+1;let e=!1;return this.loaders===1&&this.update(),()=>{e||(e=!0,this.loaders=this.loaders-1,this.loaders===0&&this.update())}}submitForm(e,t){this.formHandlers[e]={...this.formHandlers[e],submit:t}}validateForm(e,t){this.formHandlers[e]={...this.formHandlers[e],validate:t}}getHistory(){return this.conversationHistory.getConversationLogs()}}const F=(o,e)=>{const t=o.split("_contact");return e.widgets.get(t[0])},I=o=>{const e=o.get("$widget"),{name:t,implementation:s}=o.get("$widget"),r=t.indexOf("_contact")>-1?F(t,s):e,{data:n}=o.get("$settings"),{trigger:a}=r.container.get("$settings"),i=`${t.replace("_contact-method","").replace("_contact","")}_contact-method`,c=s.widgets.get(i);return c&&!a?{chatWidget:c,mainWidget:r,data:n}:{mainWidget:r,data:n}},G=o=>{const{chatWidget:e}=I(o);return!!e},R=(o,e,t)=>{const{mainWidget:s,data:r,chatWidget:n}=I(o);return n?n.state==="activated"?n.invoke("open").then(()=>{n.container.getAsync("conversation").then(a=>{a.navigateToConversationIfActive(e.id).then(()=>M.closeAllModals(o))})}):n.activate().then(()=>{const{trigger:a}=n.container.get("$settings");return a.action="hide",n.invoke("setSettings",()=>({data:r,trigger:a,activate:!0})).then(()=>n.container.getAsync("components").then(i=>{const c=i.components().ofType("contact-method");i.write({key:"setContactMethodId",attributes:{properties:{id:e.id,guideId:e.guideId}},target:c,provider:"localStorage"});const d=i.components().ofType("conversation");i.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:d,provider:"localStorage"})}))}).then(()=>n.invoke("attach",{key:"contact-method",triggerDOMElement:t,withRenderState:"open"})).then(()=>(p.createStorageWriter(n.container,"activeStickyWidget",p.StorageCategory.Necessary,{medium:p.StorageMedium.Local,scope:p.StorageScope.Implementation}).then(a=>a(n.name)),n.container.getAsync("conversation").then(a=>{a.setConversationEndedBehavior(S.Deactivate)}).then(()=>M.closeAllModals(o)).then(()=>!1))):(s.container.getAsync("conversation").then(a=>a.navigateToConversationIfActive(e.id).then(()=>a.setConversationEndedBehavior(S.Navigate))),!n)},J=(o,e,t="conversation")=>{const{mainWidget:s,chatWidget:r}=I(o);return r?r.container.getAsync("router").then(n=>{n.navigate(t,{id:e.id})}):s.container.getAsync("conversation").then(n=>{var a;(a=n.setConversationEndedBehavior(S.Navigate))==null||a.then(()=>{s.container.getAsync("router").then(i=>{s.container.getAsync("components").then(c=>{const d=c.components().ofType("conversation");c.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:d,provider:"localStorage"})}).then(()=>{i.navigate(t,{id:e.id})})})})})},b="conversations";var S=(o=>(o.Deactivate="deactivate",o.Navigate="navigate",o.None="none",o))(S||{});class w{constructor(e,t){h(this,"events");h(this,"controllers",[]);h(this,"providers",[]);h(this,"disposeProviders",{});h(this,"subscriptions",[]);h(this,"storageWriter",null);h(this,"router",null);h(this,"buttonQuery",null);h(this,"sessionInfo",null);this.container=e,this.components=t;const s=e.get("$widget");this.events=s.events.createChild(this)}initialize(){p.createStorageWriter(this.container,b,p.StorageCategory.Necessary,{medium:p.StorageMedium.Local}).then(e=>this.storageWriter=e),p.readStorage(this.container,b,p.StorageMedium.Local).then(e=>{this.buttonQuery=this.components.components().ofType("conversation-return-button"),e&&(this.sessionInfo=e,e.id&&e.route&&this.writeToComponents({active:!0,alert:{show:!1}}))}),this.container.getAsync("router").then(e=>this.router=e),this.events.subscribe("conversation:ended",(e,t)=>{var s,r,n;switch((s=this.sessionInfo)==null?void 0:s.conversationEndedBehavior){case"deactivate":this.container.get("$widget").deactivate();break;case"navigate":const i=(r=this.router)==null?void 0:r.getInitialRoute();i&&((n=this.router)==null||n.navigate(i.name));break}this.writeToComponents({active:!1}),this.sessionInfo=null,this.storageWriter&&this.storageWriter()})}addSubscription(e){this.subscriptions.push(e)}static getInstance(e,t="conversation"){return E.lock(e)(()=>e.getAsync(t).then(s=>{let r=s;return r||D.ComponentPlatform.getInstance(e).then(n=>(r=new w(e,n),r.initialize(),e.registerAsync(t,()=>r),r))}))}navigateToConversationIfActive(e){return p.readStorage(this.container,b,p.StorageMedium.Local).then(t=>{var s;if(t&&t.id===e&&t.route){const{name:r,params:n}=t.route;(s=this.router)==null||s.navigate(r,n)}})}setConversationEndedBehavior(e){return p.readStorage(this.container,b,p.StorageMedium.Local).then(t=>{let s=t;return s?s.conversationEndedBehavior=e:s={conversationEndedBehavior:e},this.sessionInfo=s,this.storageWriter&&this.storageWriter(this.sessionInfo)||Promise.resolve()})}async createController(e,t){const s=O(e),{agents:r}=await p.readStorage(this.container,s)||{agents:[]},n=this.controllers.findIndex(i=>i.conversation.id===e);let a;return n>-1?a=this.controllers[n].conversation:a=new H(this.container,e,t),a.setInitialStorage({agents:r||[]}),a}registerProvider(e,t){const s={name:e,handler:t};this.providers.push(s),this.controllers.filter(r=>r.conversation.providers.indexOf(e)>-1).forEach(r=>{this.invokeHandler(s,r)})}registerController(e,t){const s=this.controllers.findIndex(n=>n.conversation.id===e.id);let r;if(s<0){r={conversation:e,component:t},this.controllers.push(r);const n=a=>{a&&this.providers.filter(i=>a.indexOf(i.name)>-1).forEach(i=>{this.invokeHandler(i,r)})};return this.subscriptions.push(e.onDispose((a,i)=>{const c=this.controllers.findIndex(d=>d.conversation===i);c>-1&&this.controllers.splice(c,1),this.components.components().ofType("conversation-return-button").select().writeProperties({active:!1}),this.events.dispatch("conversation:ended",{},{bubbles:!0})})),this.subscriptions.push(e.onProvidersChange((a,i)=>{const{added:c,removed:d=[]}=i;d.forEach(u=>{(this.disposeProviders[u]||[]).forEach(l=>{l()})}),n(c)})),this.subscriptions.push(e.onStarted((a,i)=>{var d,u;const c={id:e.id,route:(d=this.router)==null?void 0:d.getRouteData(),conversationEndedBehavior:(u=this.sessionInfo)==null?void 0:u.conversationEndedBehavior};this.sessionInfo=c,this.storageWriter&&this.storageWriter(c),this.writeToComponents({active:i})})),this.subscriptions.push(e.onUnreadMessage((a,i)=>{this.events.dispatch("conversation:unread-message",i),this.writeToComponents({alert:{show:i}})})),n(e.providers),!0}return r=this.controllers[s],!1}writeToComponents(e,t="conversationReturnButtonState"){this.buttonQuery&&this.components.write({key:"conversationReturnButtonState",attributes:{properties:e},target:this.buttonQuery,provider:"localStorage"})}invokeHandler(e,t){const s=e.handler(t.conversation.createProvider(e.name),t.component);s&&(this.disposeProviders[e.name]||(this.disposeProviders[e.name]=[]),this.disposeProviders[e.name].push(s))}getComponentRoute(){return p.readStorage(this.container,b,p.StorageMedium.Local).then(e=>e==null?void 0:e.route)}dispose(){Object.keys(this.disposeProviders).forEach(e=>{this.disposeProviders[e].forEach(t=>{t()})}),this.subscriptions.forEach(e=>{e()}),this.controllers=[],this.providers=[]}static async handleContactMethodClick(e,t,s,r){if(G(t)){e.preventDefault();let n=document.getElementById("humany-dynamic-anchor");n||(n=document.createElement("a"),n.setAttribute("href","#"),n.id="humany-dynamic-anchor",document.body.appendChild(n)),R(t,s,n)}R(t,s)}static async handleContactMethodSubmit(e,t){var s,r;return(r=(s=t==null?void 0:t.body.form.meta)==null?void 0:s.conversation)!=null&&r.id?x(e,t.body.form.meta.conversation.id,t.clientName):J(e,t)}}const V=(o,e)=>o.reduce((t,s,r)=>{var a,i;const n={...s,content:[{...s.content,key:s.key}]};if(t.length>0&&s.type!==y.System){const c=t[t.length-1];if((!e&&e!==0||Math.abs(c.timestamp-s.timestamp)<e)&&((a=c.sender)==null?void 0:a.name)===((i=s.sender)==null?void 0:i.name)&&c.type===s.type)return c.timestamp=s.timestamp,c.content.push({...s.content,key:s.key}),t}return t.push(n),t},[]),Y=o=>Promise.all([w.getInstance(o),o.getAsync("router")]).then(([e,t])=>N.createReactComponent(o,"conversation",Promise.resolve().then(()=>require("./conversation-eaa1e841.js")),async s=>{const{rehydrate:r=!1}=s.properties(),a=t.getRouteData().params.id||s.node.name||"component",i=await e.createController(a,{rehydrate:r}),c=e.registerController(i,s),d=3*60*1e3,u=v=>{const{providers:g=[]}=v;if(g){const f=Array.isArray(g)?g:[g];return i.setProviders(f),f}};u(s.properties(u)),i.setComponentMountedState(!0);const l=v=>{const{loading:g,typingActors:f,messages:C}=v;s.writeProperties({loading:g,typingActors:f,messages:V(C,d)})};l(i.getMessageStream()),c&&(s.writeProperties({conversationControllerId:i.id}),s.actions.create("user-submit",(v,g)=>{if(g){const{preventDefault:f,validationPromise:C}=g;if(f){C&&C().then(T=>{T&&i.user.print(T)});return}}i.user.print(v.text)}),s.actions.create("user-typing",(v,g)=>{}),s.actions.create("form",(v,g)=>{}),s.actions.create("action",(v,g)=>{}),s.actions.create("overlay-mounted",(v,g)=>{}),s.actions.create("show-overlay",(v,g)=>{s.writeProperties({overlay:{conversation:!1,secondary:!1}})}),s.actions.create("hide-overlay",(v,g)=>{s.writeProperties({overlay:null})}),s.actions.create("show-overlay-conversation",(v,g)=>{s.writeProperties({overlay:{conversation:!0,secondary:!1}})}),s.actions.create("hide-overlay-conversation",(v,g)=>{s.writeProperties({overlay:{conversation:!1,secondary:!1}})}));const m=i.events.subscribe("conversation:updated",(v,g)=>{l(g)});return()=>{i.setComponentMountedState(!1),m(),i.active||l({messages:[],typingActors:[],loading:!1})}},{reuseController:!0})),X=o=>Promise.all([D.ComponentPlatform.getInstance(o),w.getInstance(o),o.getAsync("router")]).then(([e,t,s])=>N.createReactComponent(o,"conversation-return-button",Promise.resolve().then(()=>require("./return-button-f1f43984.js")),r=>{r.actions.create("toggle",(n={})=>{var a;(a=t.getComponentRoute())==null||a.then(i=>{i&&s.navigate(i.name,i.params)})})}));var B=(o=>(o.LinkList="link-list",o.Separator="separator",o.ButtonList="button-list",o.ItemList="item-list",o.Text="text",o.HTML="html",o.VideoRequest="video-request",o))(B||{});const Z=(o,e,t)=>o.getAsync("componentResolver").then(async s=>{(await w.getInstance(o)).addSubscription(s.registerComponent(e,z.lazy(()=>t)))});exports.Agent=P;exports.ConversationComponent=Y;exports.ConversationController=H;exports.ConversationEndedBehavior=S;exports.ConversationEntry=$;exports.ConversationMessageListItemType=B;exports.ConversationMessageType=y;exports.ConversationPlatform=w;exports.ConversationProvider=A;exports.ConversationReturnButtonComponent=X;exports.registerCustomMessageComponent=Z;
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var B = Object.defineProperty;
|
|
2
2
|
var L = (o, e, t) => e in o ? B(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
|
-
var
|
|
3
|
+
var h = (o, e, t) => (L(o, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
4
|
import { ComponentPlatform as R } from "@telia-ace/widget-core";
|
|
5
5
|
import { createStorageWriter as E, StorageCategory as I, readStorage as f, StorageMedium as y, StorageScope as z } from "@telia-ace/widget-services";
|
|
6
6
|
import { uuid as $, lock as K } from "@telia-ace/widget-utilities";
|
|
@@ -10,31 +10,31 @@ import { createReactComponent as H } from "@telia-ace/widget-ui";
|
|
|
10
10
|
import { lazy as U } from "react";
|
|
11
11
|
class q {
|
|
12
12
|
constructor(e) {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
h(this, "cache", /* @__PURE__ */ new Map());
|
|
14
|
+
h(this, "subscriptions", []);
|
|
15
15
|
this.controller = e;
|
|
16
|
-
const { events: t } = e.container.get("$widget"), s = t.subscribe("data-client:fetched", (r,
|
|
17
|
-
|
|
16
|
+
const { events: t } = e.container.get("$widget"), s = t.subscribe("data-client:fetched", (r, n) => {
|
|
17
|
+
n.type === "contact-method" && this.cache.set(n.response.id, n.response);
|
|
18
18
|
});
|
|
19
19
|
this.subscriptions.push(s);
|
|
20
20
|
}
|
|
21
21
|
getConversationLogs() {
|
|
22
22
|
return this.controller.messages.reduce(
|
|
23
23
|
(t, s) => {
|
|
24
|
-
const r = C(s), { key:
|
|
24
|
+
const r = C(s), { key: n, content: a, type: i, sender: c, timestamp: d } = r.content, u = this.parseEntry(a, i, c, d);
|
|
25
25
|
return u && t.push(u), t;
|
|
26
26
|
},
|
|
27
27
|
[]
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
30
|
parseEntry(e, t, s, r) {
|
|
31
|
-
const
|
|
31
|
+
const n = (d) => {
|
|
32
32
|
let u = [], l = [], v;
|
|
33
|
-
if (Array.isArray(
|
|
34
|
-
const [p, m] =
|
|
33
|
+
if (Array.isArray(d)) {
|
|
34
|
+
const [p, m] = d;
|
|
35
35
|
v = m;
|
|
36
36
|
} else
|
|
37
|
-
v =
|
|
37
|
+
v = d;
|
|
38
38
|
return this.createMessageContent(v).length && (l = [
|
|
39
39
|
...l,
|
|
40
40
|
this.createMessageContent(v)
|
|
@@ -43,20 +43,20 @@ class q {
|
|
|
43
43
|
options: u
|
|
44
44
|
};
|
|
45
45
|
};
|
|
46
|
-
let a = [],
|
|
46
|
+
let a = [], i = [];
|
|
47
47
|
if (Array.isArray(e.items)) {
|
|
48
|
-
const { items:
|
|
49
|
-
|
|
50
|
-
const l =
|
|
51
|
-
a = [...a, ...l.options],
|
|
48
|
+
const { items: d } = e;
|
|
49
|
+
d.forEach((u) => {
|
|
50
|
+
const l = n(u);
|
|
51
|
+
a = [...a, ...l.options], i = [...i, ...l.messagesAsList];
|
|
52
52
|
});
|
|
53
53
|
} else {
|
|
54
|
-
const
|
|
55
|
-
a = [...a, ...
|
|
54
|
+
const d = n(e);
|
|
55
|
+
a = [...a, ...d.options], i = [...i, ...d.messagesAsList];
|
|
56
56
|
}
|
|
57
57
|
return {
|
|
58
58
|
options: a,
|
|
59
|
-
message:
|
|
59
|
+
message: i.length ? i.join(`
|
|
60
60
|
`) : void 0,
|
|
61
61
|
source: this.createMessageSource(t),
|
|
62
62
|
alias: this.createAlias(t, s),
|
|
@@ -67,7 +67,7 @@ class q {
|
|
|
67
67
|
return e;
|
|
68
68
|
}
|
|
69
69
|
createAlias(e, t) {
|
|
70
|
-
return e ===
|
|
70
|
+
return e === w.System ? "system" : (t == null ? void 0 : t.name) || "Me";
|
|
71
71
|
}
|
|
72
72
|
handleContactMethod(e) {
|
|
73
73
|
if (!this.cache.has(e))
|
|
@@ -82,11 +82,11 @@ class q {
|
|
|
82
82
|
const {
|
|
83
83
|
header: s,
|
|
84
84
|
title: r,
|
|
85
|
-
label:
|
|
85
|
+
label: n,
|
|
86
86
|
description: a,
|
|
87
|
-
text:
|
|
88
|
-
html:
|
|
89
|
-
body:
|
|
87
|
+
text: i,
|
|
88
|
+
html: c,
|
|
89
|
+
body: d,
|
|
90
90
|
contactMethodId: u
|
|
91
91
|
} = e;
|
|
92
92
|
let l = "";
|
|
@@ -94,7 +94,7 @@ class q {
|
|
|
94
94
|
const v = this.handleContactMethod(u.toString());
|
|
95
95
|
v && (l = this.appendText(l, v, t));
|
|
96
96
|
}
|
|
97
|
-
return s && (l = this.appendText(l, s, t)), r && (l = this.appendText(l, r, t)), a && (l = this.appendText(l, a, t)),
|
|
97
|
+
return s && (l = this.appendText(l, s, t)), r && (l = this.appendText(l, r, t)), a && (l = this.appendText(l, a, t)), i && (l = this.appendText(l, i, t)), n && (l = this.appendText(l, n, t)), c && (l = this.appendText(l, c, t)), d && typeof d == "string" && (l = this.appendText(l, d, t)), l;
|
|
98
98
|
}
|
|
99
99
|
createMessageContent(e) {
|
|
100
100
|
let t = "";
|
|
@@ -102,9 +102,9 @@ class q {
|
|
|
102
102
|
}
|
|
103
103
|
createMessageOptions(e) {
|
|
104
104
|
let t = [], s = [];
|
|
105
|
-
return Array.isArray(e == null ? void 0 : e.actions) ? s = e.actions : typeof (e == null ? void 0 : e.actions) == "object" && (s = Object.entries(e.actions).map(([r,
|
|
105
|
+
return Array.isArray(e == null ? void 0 : e.actions) ? s = e.actions : typeof (e == null ? void 0 : e.actions) == "object" && (s = Object.entries(e.actions).map(([r, n]) => ({
|
|
106
106
|
actionKey: r,
|
|
107
|
-
label:
|
|
107
|
+
label: n
|
|
108
108
|
}))), s.length && (t = s.map((r) => this.getDetails(r, !1))), t;
|
|
109
109
|
}
|
|
110
110
|
appendText(e, t, s = !0) {
|
|
@@ -119,35 +119,35 @@ ${t}` : e.length ? `${e} ${t}` : t;
|
|
|
119
119
|
}
|
|
120
120
|
class k {
|
|
121
121
|
constructor(e, t) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
c(this, "print", (e, t, s = null) => {
|
|
122
|
+
h(this, "id");
|
|
123
|
+
h(this, "name");
|
|
124
|
+
h(this, "avatar");
|
|
125
|
+
h(this, "print", (e, t, s = null) => {
|
|
126
|
+
var i, c, d;
|
|
128
127
|
const r = {
|
|
129
128
|
name: this.name,
|
|
130
129
|
avatar: this.avatar,
|
|
131
130
|
id: this.id
|
|
132
|
-
},
|
|
133
|
-
s = s ??
|
|
134
|
-
const
|
|
135
|
-
|
|
131
|
+
}, n = C(e, t);
|
|
132
|
+
s = s ?? n.timestamp;
|
|
133
|
+
const a = (c = (i = this.provider) == null ? void 0 : i.controller) == null ? void 0 : c.container.get(
|
|
134
|
+
"$widget"
|
|
135
|
+
);
|
|
136
|
+
return (d = a == null ? void 0 : a.events) == null || d.dispatch("tracking:conversation-message", {
|
|
136
137
|
sender: "agent"
|
|
137
138
|
}), this.provider.createEntry(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
n.key,
|
|
140
|
+
n.content,
|
|
141
|
+
w.Agent,
|
|
141
142
|
r,
|
|
142
143
|
s
|
|
143
144
|
);
|
|
144
145
|
});
|
|
145
|
-
|
|
146
|
+
h(this, "typing", () => this.provider.setTypingState({
|
|
146
147
|
name: this.name,
|
|
147
148
|
avatar: this.avatar
|
|
148
149
|
}));
|
|
149
|
-
|
|
150
|
-
this.provider = e, this.id = t.id || $(), this.name = t.name, this.avatar = t.avatar, this.container = (s = e.controller) == null ? void 0 : s.container, this.widget = (r = this.container) == null ? void 0 : r.get("$widget");
|
|
150
|
+
this.provider = e, this.id = t.id || $(), this.name = t.name, this.avatar = t.avatar;
|
|
151
151
|
}
|
|
152
152
|
update(e) {
|
|
153
153
|
var r;
|
|
@@ -159,9 +159,9 @@ class k {
|
|
|
159
159
|
}
|
|
160
160
|
class T {
|
|
161
161
|
constructor(e, t, s) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
h(this, "subscriptions", []);
|
|
163
|
+
h(this, "options");
|
|
164
|
+
h(this, "user");
|
|
165
165
|
this.name = e, this.container = t, this.controller = s, this.user = s == null ? void 0 : s.user, this.options = {
|
|
166
166
|
silent: !1
|
|
167
167
|
};
|
|
@@ -190,9 +190,9 @@ class T {
|
|
|
190
190
|
return this.controller ? this.controller.loader() : () => () => {
|
|
191
191
|
};
|
|
192
192
|
}
|
|
193
|
-
createEntry(e, t, s, r,
|
|
193
|
+
createEntry(e, t, s, r, n) {
|
|
194
194
|
var a;
|
|
195
|
-
return (a = this.controller) == null ? void 0 : a.createEntry(e, t, s, r,
|
|
195
|
+
return (a = this.controller) == null ? void 0 : a.createEntry(e, t, s, r, n);
|
|
196
196
|
}
|
|
197
197
|
dispose() {
|
|
198
198
|
var e;
|
|
@@ -238,8 +238,8 @@ class T {
|
|
|
238
238
|
const _ = (o) => `conversation-${o}`;
|
|
239
239
|
class j {
|
|
240
240
|
constructor() {
|
|
241
|
-
|
|
242
|
-
|
|
241
|
+
h(this, "_locking", Promise.resolve());
|
|
242
|
+
h(this, "_locks", 0);
|
|
243
243
|
}
|
|
244
244
|
isLocked() {
|
|
245
245
|
return this._locks > 0;
|
|
@@ -257,80 +257,80 @@ class j {
|
|
|
257
257
|
}
|
|
258
258
|
class F {
|
|
259
259
|
constructor(e, t, s) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
260
|
+
h(this, "sessionStorageKey");
|
|
261
|
+
h(this, "locker", new j());
|
|
262
|
+
h(this, "initialStoredAgents", []);
|
|
263
263
|
this.container = e, this.conversation = t, this.enabled = s, this.sessionStorageKey = _(t.id), t.onStarted(async () => {
|
|
264
264
|
if (t.messages.length > 0)
|
|
265
265
|
return;
|
|
266
|
-
const { agents: r } = await this.read(),
|
|
267
|
-
r && r.forEach((
|
|
268
|
-
const
|
|
269
|
-
name:
|
|
270
|
-
avatar:
|
|
271
|
-
id:
|
|
266
|
+
const { agents: r } = await this.read(), n = [];
|
|
267
|
+
r && r.forEach((i) => {
|
|
268
|
+
const c = t.providerIndex(i.providerName), d = c > -1 ? t.registeredProviders[c] : t.createProvider(i.providerName), u = new k(d, {
|
|
269
|
+
name: i.name,
|
|
270
|
+
avatar: i.avatar,
|
|
271
|
+
id: i.id
|
|
272
272
|
});
|
|
273
|
-
|
|
273
|
+
n.push(u);
|
|
274
274
|
});
|
|
275
275
|
const { messages: a } = await this.read();
|
|
276
|
-
a.forEach((
|
|
277
|
-
switch (
|
|
276
|
+
a.forEach((i) => {
|
|
277
|
+
switch (i.type) {
|
|
278
278
|
case "agent": {
|
|
279
|
-
const
|
|
279
|
+
const c = n.find((d) => {
|
|
280
280
|
var u;
|
|
281
|
-
return
|
|
281
|
+
return d.id === ((u = i.sender) == null ? void 0 : u.id);
|
|
282
282
|
});
|
|
283
|
-
|
|
284
|
-
|
|
283
|
+
c && c.print(
|
|
284
|
+
i.content.items || i.content,
|
|
285
285
|
{
|
|
286
|
-
key:
|
|
286
|
+
key: i.key
|
|
287
287
|
},
|
|
288
|
-
|
|
288
|
+
i.timestamp
|
|
289
289
|
);
|
|
290
290
|
return;
|
|
291
291
|
}
|
|
292
292
|
case "user": {
|
|
293
293
|
t.user.print(
|
|
294
|
-
|
|
294
|
+
i.content.items || i.content,
|
|
295
295
|
{
|
|
296
|
-
key:
|
|
296
|
+
key: i.key
|
|
297
297
|
},
|
|
298
|
-
|
|
298
|
+
i.timestamp
|
|
299
299
|
);
|
|
300
300
|
return;
|
|
301
301
|
}
|
|
302
302
|
case "system":
|
|
303
303
|
default:
|
|
304
304
|
t.print(
|
|
305
|
-
|
|
306
|
-
|
|
305
|
+
i.content.items || i.content,
|
|
306
|
+
i.timestamp
|
|
307
307
|
);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
}), t.onMessageCreated(async (r,
|
|
311
|
-
this.write(
|
|
310
|
+
}), t.onMessageCreated(async (r, n) => {
|
|
311
|
+
this.write(n.message, "messages");
|
|
312
312
|
}), t.events.subscribe(
|
|
313
313
|
"conversation:agent-created",
|
|
314
|
-
async (r,
|
|
314
|
+
async (r, n) => {
|
|
315
315
|
const a = {
|
|
316
|
-
id:
|
|
317
|
-
name:
|
|
318
|
-
avatar:
|
|
319
|
-
providerName:
|
|
316
|
+
id: n.agent.id,
|
|
317
|
+
name: n.agent.name,
|
|
318
|
+
avatar: n.agent.avatar,
|
|
319
|
+
providerName: n.agent.provider.name
|
|
320
320
|
};
|
|
321
321
|
await this.write(a, "agents");
|
|
322
322
|
}
|
|
323
323
|
), t.events.subscribe(
|
|
324
324
|
"conversation:agent-updated",
|
|
325
|
-
async (r,
|
|
325
|
+
async (r, n) => {
|
|
326
326
|
const { agents: a } = await this.read();
|
|
327
327
|
await this.write(
|
|
328
328
|
[
|
|
329
|
-
...a.map((
|
|
330
|
-
...
|
|
331
|
-
name:
|
|
332
|
-
avatar:
|
|
333
|
-
} :
|
|
329
|
+
...a.map((i) => i.id === n.agent.id ? {
|
|
330
|
+
...i,
|
|
331
|
+
name: n.agent.name,
|
|
332
|
+
avatar: n.agent.avatar
|
|
333
|
+
} : i)
|
|
334
334
|
],
|
|
335
335
|
"agents",
|
|
336
336
|
"update"
|
|
@@ -357,33 +357,33 @@ class F {
|
|
|
357
357
|
this.container,
|
|
358
358
|
this.sessionStorageKey,
|
|
359
359
|
I.Necessary
|
|
360
|
-
).then(async (
|
|
360
|
+
).then(async (n) => {
|
|
361
361
|
if (s === "add") {
|
|
362
362
|
const a = await this.read();
|
|
363
|
-
if (t === "messages" && a.messages.findIndex((
|
|
363
|
+
if (t === "messages" && a.messages.findIndex((c) => c.key === e.key) > -1) {
|
|
364
364
|
r();
|
|
365
365
|
return;
|
|
366
366
|
}
|
|
367
|
-
const
|
|
367
|
+
const i = {
|
|
368
368
|
...a
|
|
369
369
|
};
|
|
370
|
-
return t === "messages" ?
|
|
370
|
+
return t === "messages" ? i.messages = [...i.messages, e] : t === "agents" && (i.agents = [...i.agents, e]), n({
|
|
371
371
|
...a,
|
|
372
|
-
...
|
|
372
|
+
...i
|
|
373
373
|
}).then(() => {
|
|
374
374
|
r();
|
|
375
375
|
});
|
|
376
376
|
}
|
|
377
377
|
if (s === "update" && t === "agents") {
|
|
378
378
|
const a = await this.read();
|
|
379
|
-
return
|
|
379
|
+
return n({
|
|
380
380
|
...a,
|
|
381
381
|
agents: e
|
|
382
382
|
}).then(() => {
|
|
383
383
|
r();
|
|
384
384
|
});
|
|
385
385
|
}
|
|
386
|
-
return
|
|
386
|
+
return n(e).then(() => {
|
|
387
387
|
r();
|
|
388
388
|
});
|
|
389
389
|
});
|
|
@@ -397,42 +397,38 @@ class F {
|
|
|
397
397
|
}
|
|
398
398
|
class G {
|
|
399
399
|
constructor(e) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
c(this, "print", (e, t, s = null) => {
|
|
400
|
+
h(this, "print", (e, t, s = null) => {
|
|
401
|
+
var a, i;
|
|
403
402
|
const r = C(e, t);
|
|
404
|
-
s = s ?? r.timestamp
|
|
405
|
-
const { events: i } = this.widget;
|
|
406
|
-
return i == null || i.dispatch("tracking:conversation-message", {
|
|
403
|
+
return s = s ?? r.timestamp, (i = ((a = this.controller) == null ? void 0 : a.container.get("$widget")).events) == null || i.dispatch("tracking:conversation-message", {
|
|
407
404
|
sender: "user"
|
|
408
405
|
}), this.controller.createEntry(
|
|
409
406
|
r.key,
|
|
410
407
|
r.content,
|
|
411
|
-
|
|
408
|
+
w.User,
|
|
412
409
|
void 0,
|
|
413
410
|
s
|
|
414
411
|
);
|
|
415
412
|
});
|
|
416
|
-
|
|
417
|
-
this.controller = e, this.container = e == null ? void 0 : e.container, this.widget = (t = this.container) == null ? void 0 : t.get("$widget");
|
|
413
|
+
this.controller = e;
|
|
418
414
|
}
|
|
419
415
|
}
|
|
420
416
|
const x = async (o, e, t) => {
|
|
421
417
|
const s = await o.getAsync(
|
|
422
418
|
"conversation"
|
|
423
|
-
), r = await o.getAsync("components"),
|
|
424
|
-
if (
|
|
425
|
-
const a = [...
|
|
426
|
-
a.forEach((
|
|
427
|
-
|
|
428
|
-
}),
|
|
429
|
-
const
|
|
419
|
+
), r = await o.getAsync("components"), n = s.controllers.find((a) => a.conversation.id === e);
|
|
420
|
+
if (n) {
|
|
421
|
+
const a = [...n.conversation.providers];
|
|
422
|
+
a.forEach((c) => {
|
|
423
|
+
n.conversation.setProviderOptions(c, { silent: !0 });
|
|
424
|
+
}), n.conversation.queueProviders(a), n.conversation.setProviders([t]);
|
|
425
|
+
const i = r.components().ofType("conversation");
|
|
430
426
|
r.write({
|
|
431
427
|
key: "setConversationProvider",
|
|
432
428
|
attributes: {
|
|
433
429
|
properties: { providers: [t] }
|
|
434
430
|
},
|
|
435
|
-
target:
|
|
431
|
+
target: i,
|
|
436
432
|
provider: "localStorage"
|
|
437
433
|
});
|
|
438
434
|
}
|
|
@@ -452,7 +448,7 @@ class J {
|
|
|
452
448
|
return typeof e == "string" ? { body: e } : e.length > -1 && typeof e == "object" ? { items: e } : e;
|
|
453
449
|
}
|
|
454
450
|
}
|
|
455
|
-
var
|
|
451
|
+
var w = /* @__PURE__ */ ((o) => (o.User = "user", o.Agent = "agent", o.System = "system", o))(w || {});
|
|
456
452
|
const C = (o, e) => {
|
|
457
453
|
let t, s = (e == null ? void 0 : e.key) || $(), r = Date.now();
|
|
458
454
|
if (Array.isArray(o) && o.length > -1)
|
|
@@ -469,9 +465,9 @@ const C = (o, e) => {
|
|
|
469
465
|
actions: o.actions,
|
|
470
466
|
title: o.title
|
|
471
467
|
}, o.key && (s = o.key), o.timestamp && (r = o.timestamp), typeof o.form == "function") {
|
|
472
|
-
const
|
|
473
|
-
o.form(
|
|
474
|
-
const a =
|
|
468
|
+
const n = Q.create(s);
|
|
469
|
+
o.form(n);
|
|
470
|
+
const a = n.get();
|
|
475
471
|
t.form = a;
|
|
476
472
|
}
|
|
477
473
|
o.timestamp === null && (r = null);
|
|
@@ -486,28 +482,27 @@ const C = (o, e) => {
|
|
|
486
482
|
};
|
|
487
483
|
class V {
|
|
488
484
|
constructor(e, t, s) {
|
|
489
|
-
|
|
485
|
+
h(this, "formHandlers", {});
|
|
490
486
|
/**
|
|
491
487
|
* Represents the current end user.
|
|
492
488
|
*/
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
c(this, "print", (e, t = null) => {
|
|
489
|
+
h(this, "user", new G(this));
|
|
490
|
+
h(this, "events");
|
|
491
|
+
h(this, "providers", []);
|
|
492
|
+
h(this, "active", !1);
|
|
493
|
+
h(this, "queuedProviders", []);
|
|
494
|
+
h(this, "registeredProviders", []);
|
|
495
|
+
h(this, "loaders", 0);
|
|
496
|
+
h(this, "componentMounted", !1);
|
|
497
|
+
h(this, "store");
|
|
498
|
+
h(this, "messages", []);
|
|
499
|
+
h(this, "typingActors", []);
|
|
500
|
+
h(this, "conversationHistory");
|
|
501
|
+
h(this, "print", (e, t = null) => {
|
|
507
502
|
const s = C(e);
|
|
508
503
|
t = t ?? s.timestamp;
|
|
509
|
-
const
|
|
510
|
-
return r.dispatch("tracking:conversation-message", {
|
|
504
|
+
const r = this.container.get("$widget");
|
|
505
|
+
return r == null || r.events.dispatch("tracking:conversation-message", {
|
|
511
506
|
sender: "system"
|
|
512
507
|
}), this.createEntry(
|
|
513
508
|
s.key,
|
|
@@ -517,16 +512,18 @@ class V {
|
|
|
517
512
|
t
|
|
518
513
|
);
|
|
519
514
|
});
|
|
520
|
-
this.container = e, this.id = t
|
|
515
|
+
this.container = e, this.id = t;
|
|
516
|
+
const r = e.get("$widget");
|
|
517
|
+
this.events = r.events.createChild(this), this.store = new F(e, this, s.rehydrate), this.conversationHistory = new q(this);
|
|
521
518
|
}
|
|
522
519
|
setInitialStorage(e) {
|
|
523
520
|
this.store.setInitialData(e);
|
|
524
521
|
}
|
|
525
522
|
setProviders(e) {
|
|
526
523
|
const t = [], s = [];
|
|
527
|
-
this.providers.reduce((r,
|
|
528
|
-
const
|
|
529
|
-
|
|
524
|
+
this.providers.reduce((r, n) => (e.indexOf(n) === -1 && r.push(n), r), []).forEach((r) => {
|
|
525
|
+
const n = this.providers.indexOf(r);
|
|
526
|
+
n > -1 && (t.push(r), this.providers.splice(n, 1));
|
|
530
527
|
}), e.forEach((r) => {
|
|
531
528
|
this.providers.indexOf(r) === -1 && (s.push(r), this.providers.push(r));
|
|
532
529
|
}), (s.length || t.length) && this.events.dispatch("conversation:providers-changed", {
|
|
@@ -597,26 +594,26 @@ class V {
|
|
|
597
594
|
onUnreadMessage(e) {
|
|
598
595
|
return this.events.subscribe("conversation:unread-message", e);
|
|
599
596
|
}
|
|
600
|
-
createEntry(e, t, s, r,
|
|
597
|
+
createEntry(e, t, s, r, n) {
|
|
601
598
|
const a = {
|
|
602
599
|
key: e,
|
|
603
600
|
content: t,
|
|
604
601
|
type: s,
|
|
605
602
|
sender: r || null,
|
|
606
|
-
timestamp:
|
|
603
|
+
timestamp: n || n === null ? n : Date.now()
|
|
607
604
|
};
|
|
608
605
|
this.messages.push(a), a.type === "agent" && N(this.typingActors, r);
|
|
609
|
-
const
|
|
610
|
-
if (
|
|
611
|
-
const { timestamp:
|
|
612
|
-
a.content = u,
|
|
606
|
+
const i = new J((c) => {
|
|
607
|
+
if (c !== null) {
|
|
608
|
+
const { timestamp: d = void 0, ...u } = c;
|
|
609
|
+
a.content = u, d && (a.timestamp = d);
|
|
613
610
|
} else {
|
|
614
|
-
const
|
|
615
|
-
a.content = null,
|
|
611
|
+
const d = this.messages.indexOf(a);
|
|
612
|
+
a.content = null, d > -1 && this.messages.splice(d, 1);
|
|
616
613
|
}
|
|
617
614
|
this.events.dispatch("conversation:message-updated", { message: a }), this.update();
|
|
618
615
|
});
|
|
619
|
-
return this.events.dispatch("conversation:message-created", { message: a }), this.update(), this.componentMounted || this.events.dispatch("conversation:unread-message", !0),
|
|
616
|
+
return this.events.dispatch("conversation:message-created", { message: a }), this.update(), this.componentMounted || this.events.dispatch("conversation:unread-message", !0), i;
|
|
620
617
|
}
|
|
621
618
|
update() {
|
|
622
619
|
this.events.dispatch("conversation:updated", {
|
|
@@ -661,26 +658,26 @@ const Y = (o, e) => {
|
|
|
661
658
|
const t = o.split("_contact");
|
|
662
659
|
return e.widgets.get(t[0]);
|
|
663
660
|
}, W = (o) => {
|
|
664
|
-
const e = o.get("$widget"), { name: t, implementation: s } = o.get("$widget"), r = t.indexOf("_contact") > -1 ? Y(t, s) : e, { data:
|
|
665
|
-
return
|
|
661
|
+
const e = o.get("$widget"), { name: t, implementation: s } = o.get("$widget"), r = t.indexOf("_contact") > -1 ? Y(t, s) : e, { data: n } = o.get("$settings"), { trigger: a } = r.container.get("$settings"), i = `${t.replace("_contact-method", "").replace("_contact", "")}_contact-method`, c = s.widgets.get(i);
|
|
662
|
+
return c && !a ? { chatWidget: c, mainWidget: r, data: n } : { mainWidget: r, data: n };
|
|
666
663
|
}, X = (o) => {
|
|
667
664
|
const { chatWidget: e } = W(o);
|
|
668
665
|
return !!e;
|
|
669
666
|
}, O = (o, e, t) => {
|
|
670
|
-
const { mainWidget: s, data: r, chatWidget:
|
|
671
|
-
return
|
|
672
|
-
|
|
667
|
+
const { mainWidget: s, data: r, chatWidget: n } = W(o);
|
|
668
|
+
return n ? n.state === "activated" ? n.invoke("open").then(() => {
|
|
669
|
+
n.container.getAsync("conversation").then((a) => {
|
|
673
670
|
a.navigateToConversationIfActive(e.id).then(() => M(o));
|
|
674
671
|
});
|
|
675
|
-
}) :
|
|
676
|
-
const { trigger: a } =
|
|
677
|
-
return a.action = "hide",
|
|
672
|
+
}) : n.activate().then(() => {
|
|
673
|
+
const { trigger: a } = n.container.get("$settings");
|
|
674
|
+
return a.action = "hide", n.invoke("setSettings", () => ({
|
|
678
675
|
data: r,
|
|
679
676
|
trigger: a,
|
|
680
677
|
activate: !0
|
|
681
|
-
})).then(() =>
|
|
682
|
-
const
|
|
683
|
-
|
|
678
|
+
})).then(() => n.container.getAsync("components").then((i) => {
|
|
679
|
+
const c = i.components().ofType("contact-method");
|
|
680
|
+
i.write({
|
|
684
681
|
key: "setContactMethodId",
|
|
685
682
|
attributes: {
|
|
686
683
|
properties: {
|
|
@@ -688,32 +685,32 @@ const Y = (o, e) => {
|
|
|
688
685
|
guideId: e.guideId
|
|
689
686
|
}
|
|
690
687
|
},
|
|
691
|
-
target:
|
|
688
|
+
target: c,
|
|
692
689
|
provider: "localStorage"
|
|
693
690
|
});
|
|
694
|
-
const
|
|
695
|
-
|
|
691
|
+
const d = i.components().ofType("conversation");
|
|
692
|
+
i.write({
|
|
696
693
|
key: "setConversationProvider",
|
|
697
694
|
attributes: {
|
|
698
695
|
properties: { providers: [e.clientName] }
|
|
699
696
|
},
|
|
700
|
-
target:
|
|
697
|
+
target: d,
|
|
701
698
|
provider: "localStorage"
|
|
702
699
|
});
|
|
703
700
|
}));
|
|
704
|
-
}).then(() =>
|
|
701
|
+
}).then(() => n.invoke("attach", {
|
|
705
702
|
key: "contact-method",
|
|
706
703
|
triggerDOMElement: t,
|
|
707
704
|
withRenderState: "open"
|
|
708
705
|
})).then(() => (E(
|
|
709
|
-
|
|
706
|
+
n.container,
|
|
710
707
|
"activeStickyWidget",
|
|
711
708
|
I.Necessary,
|
|
712
709
|
{
|
|
713
710
|
medium: y.Local,
|
|
714
711
|
scope: z.Implementation
|
|
715
712
|
}
|
|
716
|
-
).then((a) => a(
|
|
713
|
+
).then((a) => a(n.name)), n.container.getAsync("conversation").then((a) => {
|
|
717
714
|
a.setConversationEndedBehavior(
|
|
718
715
|
S.Deactivate
|
|
719
716
|
);
|
|
@@ -721,44 +718,44 @@ const Y = (o, e) => {
|
|
|
721
718
|
() => a.setConversationEndedBehavior(
|
|
722
719
|
S.Navigate
|
|
723
720
|
)
|
|
724
|
-
)), !
|
|
721
|
+
)), !n);
|
|
725
722
|
}, Z = (o, e, t = "conversation") => {
|
|
726
723
|
const { mainWidget: s, chatWidget: r } = W(o);
|
|
727
|
-
return r ? r.container.getAsync("router").then((
|
|
728
|
-
|
|
729
|
-
}) : s.container.getAsync("conversation").then((
|
|
724
|
+
return r ? r.container.getAsync("router").then((n) => {
|
|
725
|
+
n.navigate(t, { id: e.id });
|
|
726
|
+
}) : s.container.getAsync("conversation").then((n) => {
|
|
730
727
|
var a;
|
|
731
|
-
(a =
|
|
732
|
-
s.container.getAsync("router").then((
|
|
733
|
-
s.container.getAsync("components").then((
|
|
734
|
-
const
|
|
735
|
-
|
|
728
|
+
(a = n.setConversationEndedBehavior(S.Navigate)) == null || a.then(() => {
|
|
729
|
+
s.container.getAsync("router").then((i) => {
|
|
730
|
+
s.container.getAsync("components").then((c) => {
|
|
731
|
+
const d = c.components().ofType("conversation");
|
|
732
|
+
c.write({
|
|
736
733
|
key: "setConversationProvider",
|
|
737
734
|
attributes: {
|
|
738
735
|
properties: { providers: [e.clientName] }
|
|
739
736
|
},
|
|
740
|
-
target:
|
|
737
|
+
target: d,
|
|
741
738
|
provider: "localStorage"
|
|
742
739
|
});
|
|
743
740
|
}).then(() => {
|
|
744
|
-
|
|
741
|
+
i.navigate(t, { id: e.id });
|
|
745
742
|
});
|
|
746
743
|
});
|
|
747
744
|
});
|
|
748
745
|
});
|
|
749
|
-
},
|
|
746
|
+
}, b = "conversations";
|
|
750
747
|
var S = /* @__PURE__ */ ((o) => (o.Deactivate = "deactivate", o.Navigate = "navigate", o.None = "none", o))(S || {});
|
|
751
748
|
class A {
|
|
752
749
|
constructor(e, t) {
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
750
|
+
h(this, "events");
|
|
751
|
+
h(this, "controllers", []);
|
|
752
|
+
h(this, "providers", []);
|
|
753
|
+
h(this, "disposeProviders", {});
|
|
754
|
+
h(this, "subscriptions", []);
|
|
755
|
+
h(this, "storageWriter", null);
|
|
756
|
+
h(this, "router", null);
|
|
757
|
+
h(this, "buttonQuery", null);
|
|
758
|
+
h(this, "sessionInfo", null);
|
|
762
759
|
this.container = e, this.components = t;
|
|
763
760
|
const s = e.get("$widget");
|
|
764
761
|
this.events = s.events.createChild(this);
|
|
@@ -766,26 +763,26 @@ class A {
|
|
|
766
763
|
initialize() {
|
|
767
764
|
E(
|
|
768
765
|
this.container,
|
|
769
|
-
|
|
766
|
+
b,
|
|
770
767
|
I.Necessary,
|
|
771
768
|
{
|
|
772
769
|
medium: y.Local
|
|
773
770
|
}
|
|
774
771
|
).then((e) => this.storageWriter = e), f(
|
|
775
772
|
this.container,
|
|
776
|
-
|
|
773
|
+
b,
|
|
777
774
|
y.Local
|
|
778
775
|
).then((e) => {
|
|
779
776
|
this.buttonQuery = this.components.components().ofType("conversation-return-button"), e && (this.sessionInfo = e, e.id && e.route && this.writeToComponents({ active: !0, alert: { show: !1 } }));
|
|
780
777
|
}), this.container.getAsync("router").then((e) => this.router = e), this.events.subscribe("conversation:ended", (e, t) => {
|
|
781
|
-
var s, r,
|
|
778
|
+
var s, r, n;
|
|
782
779
|
switch ((s = this.sessionInfo) == null ? void 0 : s.conversationEndedBehavior) {
|
|
783
780
|
case "deactivate":
|
|
784
781
|
this.container.get("$widget").deactivate();
|
|
785
782
|
break;
|
|
786
783
|
case "navigate":
|
|
787
|
-
const
|
|
788
|
-
|
|
784
|
+
const i = (r = this.router) == null ? void 0 : r.getInitialRoute();
|
|
785
|
+
i && ((n = this.router) == null || n.navigate(i.name));
|
|
789
786
|
break;
|
|
790
787
|
}
|
|
791
788
|
this.writeToComponents({ active: !1 }), this.sessionInfo = null, this.storageWriter && this.storageWriter();
|
|
@@ -797,26 +794,26 @@ class A {
|
|
|
797
794
|
static getInstance(e, t = "conversation") {
|
|
798
795
|
return K(e)(() => e.getAsync(t).then((s) => {
|
|
799
796
|
let r = s;
|
|
800
|
-
return r || R.getInstance(e).then((
|
|
797
|
+
return r || R.getInstance(e).then((n) => (r = new A(e, n), r.initialize(), e.registerAsync(t, () => r), r));
|
|
801
798
|
}));
|
|
802
799
|
}
|
|
803
800
|
navigateToConversationIfActive(e) {
|
|
804
801
|
return f(
|
|
805
802
|
this.container,
|
|
806
|
-
|
|
803
|
+
b,
|
|
807
804
|
y.Local
|
|
808
805
|
).then((t) => {
|
|
809
806
|
var s;
|
|
810
807
|
if (t && t.id === e && t.route) {
|
|
811
|
-
const { name: r, params:
|
|
812
|
-
(s = this.router) == null || s.navigate(r,
|
|
808
|
+
const { name: r, params: n } = t.route;
|
|
809
|
+
(s = this.router) == null || s.navigate(r, n);
|
|
813
810
|
}
|
|
814
811
|
});
|
|
815
812
|
}
|
|
816
813
|
setConversationEndedBehavior(e) {
|
|
817
814
|
return f(
|
|
818
815
|
this.container,
|
|
819
|
-
|
|
816
|
+
b,
|
|
820
817
|
y.Local
|
|
821
818
|
).then((t) => {
|
|
822
819
|
let s = t;
|
|
@@ -824,9 +821,9 @@ class A {
|
|
|
824
821
|
});
|
|
825
822
|
}
|
|
826
823
|
async createController(e, t) {
|
|
827
|
-
const s = _(e), { agents: r } = await f(this.container, s) || { agents: [] },
|
|
824
|
+
const s = _(e), { agents: r } = await f(this.container, s) || { agents: [] }, n = this.controllers.findIndex((i) => i.conversation.id === e);
|
|
828
825
|
let a;
|
|
829
|
-
return
|
|
826
|
+
return n > -1 ? a = this.controllers[n].conversation : a = new V(this.container, e, t), a.setInitialStorage({ agents: r || [] }), a;
|
|
830
827
|
}
|
|
831
828
|
registerProvider(e, t) {
|
|
832
829
|
const s = {
|
|
@@ -841,52 +838,52 @@ class A {
|
|
|
841
838
|
}
|
|
842
839
|
registerController(e, t) {
|
|
843
840
|
const s = this.controllers.findIndex(
|
|
844
|
-
(
|
|
841
|
+
(n) => n.conversation.id === e.id
|
|
845
842
|
);
|
|
846
843
|
let r;
|
|
847
844
|
if (s < 0) {
|
|
848
845
|
r = { conversation: e, component: t }, this.controllers.push(r);
|
|
849
|
-
const
|
|
850
|
-
a && this.providers.filter((
|
|
851
|
-
this.invokeHandler(
|
|
846
|
+
const n = (a) => {
|
|
847
|
+
a && this.providers.filter((i) => a.indexOf(i.name) > -1).forEach((i) => {
|
|
848
|
+
this.invokeHandler(i, r);
|
|
852
849
|
});
|
|
853
850
|
};
|
|
854
851
|
return this.subscriptions.push(
|
|
855
|
-
e.onDispose((a,
|
|
856
|
-
const
|
|
857
|
-
(
|
|
852
|
+
e.onDispose((a, i) => {
|
|
853
|
+
const c = this.controllers.findIndex(
|
|
854
|
+
(d) => d.conversation === i
|
|
858
855
|
);
|
|
859
|
-
|
|
856
|
+
c > -1 && this.controllers.splice(c, 1), this.components.components().ofType("conversation-return-button").select().writeProperties({ active: !1 }), this.events.dispatch("conversation:ended", {}, { bubbles: !0 });
|
|
860
857
|
})
|
|
861
858
|
), this.subscriptions.push(
|
|
862
|
-
e.onProvidersChange((a,
|
|
859
|
+
e.onProvidersChange((a, i) => {
|
|
863
860
|
const {
|
|
864
|
-
added:
|
|
865
|
-
removed:
|
|
866
|
-
} =
|
|
867
|
-
|
|
861
|
+
added: c,
|
|
862
|
+
removed: d = []
|
|
863
|
+
} = i;
|
|
864
|
+
d.forEach((u) => {
|
|
868
865
|
(this.disposeProviders[u] || []).forEach(
|
|
869
866
|
(l) => {
|
|
870
867
|
l();
|
|
871
868
|
}
|
|
872
869
|
);
|
|
873
|
-
}),
|
|
870
|
+
}), n(c);
|
|
874
871
|
})
|
|
875
872
|
), this.subscriptions.push(
|
|
876
|
-
e.onStarted((a,
|
|
877
|
-
var
|
|
878
|
-
const
|
|
873
|
+
e.onStarted((a, i) => {
|
|
874
|
+
var d, u;
|
|
875
|
+
const c = {
|
|
879
876
|
id: e.id,
|
|
880
|
-
route: (
|
|
877
|
+
route: (d = this.router) == null ? void 0 : d.getRouteData(),
|
|
881
878
|
conversationEndedBehavior: (u = this.sessionInfo) == null ? void 0 : u.conversationEndedBehavior
|
|
882
879
|
};
|
|
883
|
-
this.sessionInfo =
|
|
880
|
+
this.sessionInfo = c, this.storageWriter && this.storageWriter(c), this.writeToComponents({ active: i });
|
|
884
881
|
})
|
|
885
882
|
), this.subscriptions.push(
|
|
886
|
-
e.onUnreadMessage((a,
|
|
887
|
-
this.events.dispatch("conversation:unread-message",
|
|
883
|
+
e.onUnreadMessage((a, i) => {
|
|
884
|
+
this.events.dispatch("conversation:unread-message", i), this.writeToComponents({ alert: { show: i } });
|
|
888
885
|
})
|
|
889
|
-
),
|
|
886
|
+
), n(e.providers), !0;
|
|
890
887
|
}
|
|
891
888
|
return r = this.controllers[s], !1;
|
|
892
889
|
}
|
|
@@ -908,7 +905,7 @@ class A {
|
|
|
908
905
|
getComponentRoute() {
|
|
909
906
|
return f(
|
|
910
907
|
this.container,
|
|
911
|
-
|
|
908
|
+
b,
|
|
912
909
|
y.Local
|
|
913
910
|
).then((e) => e == null ? void 0 : e.route);
|
|
914
911
|
}
|
|
@@ -924,8 +921,8 @@ class A {
|
|
|
924
921
|
static async handleContactMethodClick(e, t, s, r) {
|
|
925
922
|
if (X(t)) {
|
|
926
923
|
e.preventDefault();
|
|
927
|
-
let
|
|
928
|
-
|
|
924
|
+
let n = document.getElementById("humany-dynamic-anchor");
|
|
925
|
+
n || (n = document.createElement("a"), n.setAttribute("href", "#"), n.id = "humany-dynamic-anchor", document.body.appendChild(n)), O(t, s, n);
|
|
929
926
|
}
|
|
930
927
|
O(t, s);
|
|
931
928
|
}
|
|
@@ -939,17 +936,17 @@ class A {
|
|
|
939
936
|
}
|
|
940
937
|
}
|
|
941
938
|
const ee = (o, e) => o.reduce((t, s, r) => {
|
|
942
|
-
var a,
|
|
943
|
-
const
|
|
939
|
+
var a, i;
|
|
940
|
+
const n = {
|
|
944
941
|
...s,
|
|
945
942
|
content: [{ ...s.content, key: s.key }]
|
|
946
943
|
};
|
|
947
|
-
if (t.length > 0 && s.type !==
|
|
948
|
-
const
|
|
949
|
-
if ((!e && e !== 0 || Math.abs(
|
|
950
|
-
return
|
|
944
|
+
if (t.length > 0 && s.type !== w.System) {
|
|
945
|
+
const c = t[t.length - 1];
|
|
946
|
+
if ((!e && e !== 0 || Math.abs(c.timestamp - s.timestamp) < e) && ((a = c.sender) == null ? void 0 : a.name) === ((i = s.sender) == null ? void 0 : i.name) && c.type === s.type)
|
|
947
|
+
return c.timestamp = s.timestamp, c.content.push({ ...s.content, key: s.key }), t;
|
|
951
948
|
}
|
|
952
|
-
return t.push(
|
|
949
|
+
return t.push(n), t;
|
|
953
950
|
}, []), he = (o) => Promise.all([
|
|
954
951
|
A.getInstance(o),
|
|
955
952
|
o.getAsync("router")
|
|
@@ -958,42 +955,42 @@ const ee = (o, e) => o.reduce((t, s, r) => {
|
|
|
958
955
|
"conversation",
|
|
959
956
|
import("./conversation-78933b09.mjs"),
|
|
960
957
|
async (s) => {
|
|
961
|
-
const { rehydrate: r = !1 } = s.properties(), a = t.getRouteData().params.id || s.node.name || "component",
|
|
958
|
+
const { rehydrate: r = !1 } = s.properties(), a = t.getRouteData().params.id || s.node.name || "component", i = await e.createController(a, {
|
|
962
959
|
rehydrate: r
|
|
963
|
-
}),
|
|
964
|
-
|
|
960
|
+
}), c = e.registerController(
|
|
961
|
+
i,
|
|
965
962
|
s
|
|
966
|
-
),
|
|
963
|
+
), d = 3 * 60 * 1e3, u = (g) => {
|
|
967
964
|
const { providers: p = [] } = g;
|
|
968
965
|
if (p) {
|
|
969
966
|
const m = Array.isArray(p) ? p : [p];
|
|
970
|
-
return
|
|
967
|
+
return i.setProviders(m), m;
|
|
971
968
|
}
|
|
972
969
|
};
|
|
973
970
|
u(
|
|
974
971
|
s.properties(u)
|
|
975
|
-
),
|
|
972
|
+
), i.setComponentMountedState(!0);
|
|
976
973
|
const l = (g) => {
|
|
977
974
|
const { loading: p, typingActors: m, messages: P } = g;
|
|
978
975
|
s.writeProperties({
|
|
979
976
|
loading: p,
|
|
980
977
|
typingActors: m,
|
|
981
|
-
messages: ee(P,
|
|
978
|
+
messages: ee(P, d)
|
|
982
979
|
});
|
|
983
980
|
};
|
|
984
|
-
l(
|
|
985
|
-
conversationControllerId:
|
|
981
|
+
l(i.getMessageStream()), c && (s.writeProperties({
|
|
982
|
+
conversationControllerId: i.id
|
|
986
983
|
}), s.actions.create("user-submit", (g, p) => {
|
|
987
984
|
if (p) {
|
|
988
985
|
const { preventDefault: m, validationPromise: P } = p;
|
|
989
986
|
if (m) {
|
|
990
987
|
P && P().then((D) => {
|
|
991
|
-
D &&
|
|
988
|
+
D && i.user.print(D);
|
|
992
989
|
});
|
|
993
990
|
return;
|
|
994
991
|
}
|
|
995
992
|
}
|
|
996
|
-
|
|
993
|
+
i.user.print(g.text);
|
|
997
994
|
}), s.actions.create("user-typing", (g, p) => {
|
|
998
995
|
}), s.actions.create("form", (g, p) => {
|
|
999
996
|
}), s.actions.create("action", (g, p) => {
|
|
@@ -1021,14 +1018,14 @@ const ee = (o, e) => o.reduce((t, s, r) => {
|
|
|
1021
1018
|
});
|
|
1022
1019
|
}
|
|
1023
1020
|
));
|
|
1024
|
-
const v =
|
|
1021
|
+
const v = i.events.subscribe(
|
|
1025
1022
|
"conversation:updated",
|
|
1026
1023
|
(g, p) => {
|
|
1027
1024
|
l(p);
|
|
1028
1025
|
}
|
|
1029
1026
|
);
|
|
1030
1027
|
return () => {
|
|
1031
|
-
|
|
1028
|
+
i.setComponentMountedState(!1), v(), i.active || l({ messages: [], typingActors: [], loading: !1 });
|
|
1032
1029
|
};
|
|
1033
1030
|
},
|
|
1034
1031
|
{ reuseController: !0 }
|
|
@@ -1042,10 +1039,10 @@ const ee = (o, e) => o.reduce((t, s, r) => {
|
|
|
1042
1039
|
"conversation-return-button",
|
|
1043
1040
|
import("./return-button-3e542ab7.mjs"),
|
|
1044
1041
|
(r) => {
|
|
1045
|
-
r.actions.create("toggle", (
|
|
1042
|
+
r.actions.create("toggle", (n = {}) => {
|
|
1046
1043
|
var a;
|
|
1047
|
-
(a = t.getComponentRoute()) == null || a.then((
|
|
1048
|
-
|
|
1044
|
+
(a = t.getComponentRoute()) == null || a.then((i) => {
|
|
1045
|
+
i && s.navigate(i.name, i.params);
|
|
1049
1046
|
});
|
|
1050
1047
|
});
|
|
1051
1048
|
}
|
|
@@ -1067,7 +1064,7 @@ export {
|
|
|
1067
1064
|
S as ConversationEndedBehavior,
|
|
1068
1065
|
J as ConversationEntry,
|
|
1069
1066
|
te as ConversationMessageListItemType,
|
|
1070
|
-
|
|
1067
|
+
w as ConversationMessageType,
|
|
1071
1068
|
A as ConversationPlatform,
|
|
1072
1069
|
T as ConversationProvider,
|
|
1073
1070
|
le as ConversationReturnButtonComponent,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/widget-conversation",
|
|
3
|
-
"version": "1.1.7-rc.
|
|
3
|
+
"version": "1.1.7-rc.4",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@telia-ace/widget-core": "^1.1.7-rc.
|
|
14
|
-
"@telia-ace/widget-forms": "^1.1.7-rc.
|
|
15
|
-
"@telia-ace/widget-plugins": "^1.1.7-rc.
|
|
16
|
-
"@telia-ace/widget-routing": "^1.1.7-rc.
|
|
17
|
-
"@telia-ace/widget-services": "^1.1.7-rc.
|
|
18
|
-
"@telia-ace/widget-ui": "^1.1.7-rc.
|
|
19
|
-
"@telia-ace/widget-utilities": "^1.1.7-rc.
|
|
13
|
+
"@telia-ace/widget-core": "^1.1.7-rc.4",
|
|
14
|
+
"@telia-ace/widget-forms": "^1.1.7-rc.4",
|
|
15
|
+
"@telia-ace/widget-plugins": "^1.1.7-rc.4",
|
|
16
|
+
"@telia-ace/widget-routing": "^1.1.7-rc.4",
|
|
17
|
+
"@telia-ace/widget-services": "^1.1.7-rc.4",
|
|
18
|
+
"@telia-ace/widget-ui": "^1.1.7-rc.4",
|
|
19
|
+
"@telia-ace/widget-utilities": "^1.1.7-rc.4",
|
|
20
20
|
"@webprovisions/platform": "^1.1.4"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
package/user.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { Container, Widget } from '@webprovisions/platform';
|
|
2
1
|
import { ConversationController, ConversationEntry } from './conversation-controller';
|
|
3
2
|
import { ConversationMessageSettings } from './types';
|
|
4
3
|
export declare class User {
|
|
5
4
|
private controller;
|
|
6
|
-
container?: Container;
|
|
7
|
-
widget?: Widget;
|
|
8
5
|
constructor(controller: ConversationController);
|
|
9
6
|
print: (settings: string | ConversationMessageSettings, options?: {
|
|
10
7
|
key?: string;
|