@telia-ace/widget-conversation 1.3.20-rc.0 → 1.3.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +2 -2
  2. package/index.mjs +122 -108
  3. package/package.json +8 -8
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 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(`
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 N=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"),O=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
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-92e4cb62.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;
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 D=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}}function Q(o){let e=0;if(o.length===0)return e.toString();for(let t=0;t<o.length;t++){const s=o.charCodeAt(t);e=(e<<5)-e+s,e=e&e}return e.toString()}class j{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=D(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.filter(i=>(i==null?void 0:i.content)!=null).filter(i=>!i.chat||!t.providers.includes("ace.chat")).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"&&(e.chat=this.conversation.providers.includes("ace.chat"),e.hash=Q(JSON.stringify(e.content)+e.timestamp)),t==="messages"&&a.messages.findIndex(c=>c.key===e.key||c.hash===e.hash)>-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 F{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 F(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 j(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 J=(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?J(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)},V=(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||N.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=D(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):V(e,t)}}const Y=(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},[]),X=o=>Promise.all([w.getInstance(o),o.getAsync("router")]).then(([e,t])=>O.createReactComponent(o,"conversation",Promise.resolve().then(()=>require("./conversation-92e4cb62.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:Y(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})),Z=o=>Promise.all([N.ComponentPlatform.getInstance(o),w.getInstance(o),o.getAsync("router")]).then(([e,t,s])=>O.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 ee=(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=X;exports.ConversationController=H;exports.ConversationEndedBehavior=S;exports.ConversationEntry=$;exports.ConversationMessageListItemType=B;exports.ConversationMessageType=y;exports.ConversationPlatform=w;exports.ConversationProvider=A;exports.ConversationReturnButtonComponent=Z;exports.registerCustomMessageComponent=ee;
package/index.mjs CHANGED
@@ -1,17 +1,17 @@
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 h = (o, e, t) => (L(o, typeof e != "symbol" ? e + "" : e, t), t);
3
+ var d = (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";
7
7
  import { FormBuilder as Q } from "@telia-ace/widget-forms";
8
- import { closeAllModals as M } from "@telia-ace/widget-plugins";
8
+ import { closeAllModals as D } from "@telia-ace/widget-plugins";
9
9
  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
- h(this, "cache", /* @__PURE__ */ new Map());
14
- h(this, "subscriptions", []);
13
+ d(this, "cache", /* @__PURE__ */ new Map());
14
+ d(this, "subscriptions", []);
15
15
  this.controller = e;
16
16
  const { events: t } = e.container.get("$widget"), s = t.subscribe("data-client:fetched", (r, n) => {
17
17
  n.type === "contact-method" && this.cache.set(n.response.id, n.response);
@@ -21,20 +21,20 @@ class q {
21
21
  getConversationLogs() {
22
22
  return this.controller.messages.reduce(
23
23
  (t, s) => {
24
- const r = C(s), { key: n, content: a, type: i, sender: c, timestamp: d } = r.content, u = this.parseEntry(a, i, c, d);
24
+ const r = C(s), { key: n, content: a, type: i, sender: c, timestamp: h } = r.content, u = this.parseEntry(a, i, c, h);
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 n = (d) => {
31
+ const n = (h) => {
32
32
  let u = [], l = [], v;
33
- if (Array.isArray(d)) {
34
- const [p, m] = d;
33
+ if (Array.isArray(h)) {
34
+ const [p, m] = h;
35
35
  v = m;
36
36
  } else
37
- v = d;
37
+ v = h;
38
38
  return this.createMessageContent(v).length && (l = [
39
39
  ...l,
40
40
  this.createMessageContent(v)
@@ -45,14 +45,14 @@ class q {
45
45
  };
46
46
  let a = [], i = [];
47
47
  if (Array.isArray(e.items)) {
48
- const { items: d } = e;
49
- d.forEach((u) => {
48
+ const { items: h } = e;
49
+ h.forEach((u) => {
50
50
  const l = n(u);
51
51
  a = [...a, ...l.options], i = [...i, ...l.messagesAsList];
52
52
  });
53
53
  } else {
54
- const d = n(e);
55
- a = [...a, ...d.options], i = [...i, ...d.messagesAsList];
54
+ const h = n(e);
55
+ a = [...a, ...h.options], i = [...i, ...h.messagesAsList];
56
56
  }
57
57
  return {
58
58
  options: a,
@@ -86,7 +86,7 @@ class q {
86
86
  description: a,
87
87
  text: i,
88
88
  html: c,
89
- body: d,
89
+ body: h,
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)), 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;
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)), h && typeof h == "string" && (l = this.appendText(l, h, t)), l;
98
98
  }
99
99
  createMessageContent(e) {
100
100
  let t = "";
@@ -119,11 +119,11 @@ ${t}` : e.length ? `${e} ${t}` : t;
119
119
  }
120
120
  class k {
121
121
  constructor(e, t) {
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;
122
+ d(this, "id");
123
+ d(this, "name");
124
+ d(this, "avatar");
125
+ d(this, "print", (e, t, s = null) => {
126
+ var i, c, h;
127
127
  const r = {
128
128
  name: this.name,
129
129
  avatar: this.avatar,
@@ -133,7 +133,7 @@ class k {
133
133
  const a = (c = (i = this.provider) == null ? void 0 : i.controller) == null ? void 0 : c.container.get(
134
134
  "$widget"
135
135
  );
136
- return (d = a == null ? void 0 : a.events) == null || d.dispatch("tracking:conversation-message", {
136
+ return (h = a == null ? void 0 : a.events) == null || h.dispatch("tracking:conversation-message", {
137
137
  sender: "agent"
138
138
  }), this.provider.createEntry(
139
139
  n.key,
@@ -143,7 +143,7 @@ class k {
143
143
  s
144
144
  );
145
145
  });
146
- h(this, "typing", () => this.provider.setTypingState({
146
+ d(this, "typing", () => this.provider.setTypingState({
147
147
  name: this.name,
148
148
  avatar: this.avatar
149
149
  }));
@@ -159,9 +159,9 @@ class k {
159
159
  }
160
160
  class T {
161
161
  constructor(e, t, s) {
162
- h(this, "subscriptions", []);
163
- h(this, "options");
164
- h(this, "user");
162
+ d(this, "subscriptions", []);
163
+ d(this, "options");
164
+ d(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
  };
@@ -238,8 +238,8 @@ class T {
238
238
  const _ = (o) => `conversation-${o}`;
239
239
  class j {
240
240
  constructor() {
241
- h(this, "_locking", Promise.resolve());
242
- h(this, "_locks", 0);
241
+ d(this, "_locking", Promise.resolve());
242
+ d(this, "_locks", 0);
243
243
  }
244
244
  isLocked() {
245
245
  return this._locks > 0;
@@ -255,17 +255,27 @@ class j {
255
255
  return this._locking = this._locking.then(() => t), s;
256
256
  }
257
257
  }
258
- class F {
258
+ function F(o) {
259
+ let e = 0;
260
+ if (o.length === 0)
261
+ return e.toString();
262
+ for (let t = 0; t < o.length; t++) {
263
+ const s = o.charCodeAt(t);
264
+ e = (e << 5) - e + s, e = e & e;
265
+ }
266
+ return e.toString();
267
+ }
268
+ class J {
259
269
  constructor(e, t, s) {
260
- h(this, "sessionStorageKey");
261
- h(this, "locker", new j());
262
- h(this, "initialStoredAgents", []);
270
+ d(this, "sessionStorageKey");
271
+ d(this, "locker", new j());
272
+ d(this, "initialStoredAgents", []);
263
273
  this.container = e, this.conversation = t, this.enabled = s, this.sessionStorageKey = _(t.id), t.onStarted(async () => {
264
274
  if (t.messages.length > 0)
265
275
  return;
266
276
  const { agents: r } = await this.read(), n = [];
267
277
  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, {
278
+ const c = t.providerIndex(i.providerName), h = c > -1 ? t.registeredProviders[c] : t.createProvider(i.providerName), u = new k(h, {
269
279
  name: i.name,
270
280
  avatar: i.avatar,
271
281
  id: i.id
@@ -273,12 +283,14 @@ class F {
273
283
  n.push(u);
274
284
  });
275
285
  const { messages: a } = await this.read();
276
- a.forEach((i) => {
286
+ a.filter((i) => (i == null ? void 0 : i.content) != null).filter(
287
+ (i) => !i.chat || !t.providers.includes("ace.chat")
288
+ ).forEach((i) => {
277
289
  switch (i.type) {
278
290
  case "agent": {
279
- const c = n.find((d) => {
291
+ const c = n.find((h) => {
280
292
  var u;
281
- return d.id === ((u = i.sender) == null ? void 0 : u.id);
293
+ return h.id === ((u = i.sender) == null ? void 0 : u.id);
282
294
  });
283
295
  c && c.print(
284
296
  i.content.items || i.content,
@@ -360,7 +372,9 @@ class F {
360
372
  ).then(async (n) => {
361
373
  if (s === "add") {
362
374
  const a = await this.read();
363
- if (t === "messages" && a.messages.findIndex((c) => c.key === e.key) > -1) {
375
+ if (t === "messages" && (e.chat = this.conversation.providers.includes("ace.chat"), e.hash = F(JSON.stringify(e.content) + e.timestamp)), t === "messages" && a.messages.findIndex(
376
+ (c) => c.key === e.key || c.hash === e.hash
377
+ ) > -1) {
364
378
  r();
365
379
  return;
366
380
  }
@@ -397,7 +411,7 @@ class F {
397
411
  }
398
412
  class G {
399
413
  constructor(e) {
400
- h(this, "print", (e, t, s = null) => {
414
+ d(this, "print", (e, t, s = null) => {
401
415
  var a, i;
402
416
  const r = C(e, t);
403
417
  return s = s ?? r.timestamp, (i = ((a = this.controller) == null ? void 0 : a.container.get("$widget")).events) == null || i.dispatch("tracking:conversation-message", {
@@ -433,7 +447,7 @@ const x = async (o, e, t) => {
433
447
  });
434
448
  }
435
449
  };
436
- class J {
450
+ class V {
437
451
  constructor(e) {
438
452
  this.writer = e;
439
453
  }
@@ -473,32 +487,32 @@ const C = (o, e) => {
473
487
  o.timestamp === null && (r = null);
474
488
  }
475
489
  return { content: t, key: s, timestamp: r };
476
- }, N = (o, e) => {
490
+ }, M = (o, e) => {
477
491
  if (!e)
478
492
  return;
479
493
  const t = JSON.stringify(e), s = o.findIndex((r) => t === JSON.stringify(r));
480
494
  if (s > -1)
481
495
  return o.splice(s, 1);
482
496
  };
483
- class V {
497
+ class Y {
484
498
  constructor(e, t, s) {
485
- h(this, "formHandlers", {});
499
+ d(this, "formHandlers", {});
486
500
  /**
487
501
  * Represents the current end user.
488
502
  */
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) => {
503
+ d(this, "user", new G(this));
504
+ d(this, "events");
505
+ d(this, "providers", []);
506
+ d(this, "active", !1);
507
+ d(this, "queuedProviders", []);
508
+ d(this, "registeredProviders", []);
509
+ d(this, "loaders", 0);
510
+ d(this, "componentMounted", !1);
511
+ d(this, "store");
512
+ d(this, "messages", []);
513
+ d(this, "typingActors", []);
514
+ d(this, "conversationHistory");
515
+ d(this, "print", (e, t = null) => {
502
516
  const s = C(e);
503
517
  t = t ?? s.timestamp;
504
518
  const r = this.container.get("$widget");
@@ -514,7 +528,7 @@ class V {
514
528
  });
515
529
  this.container = e, this.id = t;
516
530
  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);
531
+ this.events = r.events.createChild(this), this.store = new J(e, this, s.rehydrate), this.conversationHistory = new q(this);
518
532
  }
519
533
  setInitialStorage(e) {
520
534
  this.store.setInitialData(e);
@@ -602,14 +616,14 @@ class V {
602
616
  sender: r || null,
603
617
  timestamp: n || n === null ? n : Date.now()
604
618
  };
605
- this.messages.push(a), a.type === "agent" && N(this.typingActors, r);
606
- const i = new J((c) => {
619
+ this.messages.push(a), a.type === "agent" && M(this.typingActors, r);
620
+ const i = new V((c) => {
607
621
  if (c !== null) {
608
- const { timestamp: d = void 0, ...u } = c;
609
- a.content = u, d && (a.timestamp = d);
622
+ const { timestamp: h = void 0, ...u } = c;
623
+ a.content = u, h && (a.timestamp = h);
610
624
  } else {
611
- const d = this.messages.indexOf(a);
612
- a.content = null, d > -1 && this.messages.splice(d, 1);
625
+ const h = this.messages.indexOf(a);
626
+ a.content = null, h > -1 && this.messages.splice(h, 1);
613
627
  }
614
628
  this.events.dispatch("conversation:message-updated", { message: a }), this.update();
615
629
  });
@@ -631,7 +645,7 @@ class V {
631
645
  }
632
646
  setTypingState(e, t) {
633
647
  return this.typingActors.indexOf(e) === -1 && (this.typingActors.push(e), this.update()), () => {
634
- N(this.typingActors, e), this.update();
648
+ M(this.typingActors, e), this.update();
635
649
  };
636
650
  }
637
651
  /**
@@ -654,20 +668,20 @@ class V {
654
668
  return this.conversationHistory.getConversationLogs();
655
669
  }
656
670
  }
657
- const Y = (o, e) => {
671
+ const X = (o, e) => {
658
672
  const t = o.split("_contact");
659
673
  return e.widgets.get(t[0]);
660
- }, W = (o) => {
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);
674
+ }, N = (o) => {
675
+ const e = o.get("$widget"), { name: t, implementation: s } = o.get("$widget"), r = t.indexOf("_contact") > -1 ? X(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
676
  return c && !a ? { chatWidget: c, mainWidget: r, data: n } : { mainWidget: r, data: n };
663
- }, X = (o) => {
664
- const { chatWidget: e } = W(o);
677
+ }, Z = (o) => {
678
+ const { chatWidget: e } = N(o);
665
679
  return !!e;
666
680
  }, O = (o, e, t) => {
667
- const { mainWidget: s, data: r, chatWidget: n } = W(o);
681
+ const { mainWidget: s, data: r, chatWidget: n } = N(o);
668
682
  return n ? n.state === "activated" ? n.invoke("open").then(() => {
669
683
  n.container.getAsync("conversation").then((a) => {
670
- a.navigateToConversationIfActive(e.id).then(() => M(o));
684
+ a.navigateToConversationIfActive(e.id).then(() => D(o));
671
685
  });
672
686
  }) : n.activate().then(() => {
673
687
  const { trigger: a } = n.container.get("$settings");
@@ -688,13 +702,13 @@ const Y = (o, e) => {
688
702
  target: c,
689
703
  provider: "localStorage"
690
704
  });
691
- const d = i.components().ofType("conversation");
705
+ const h = i.components().ofType("conversation");
692
706
  i.write({
693
707
  key: "setConversationProvider",
694
708
  attributes: {
695
709
  properties: { providers: [e.clientName] }
696
710
  },
697
- target: d,
711
+ target: h,
698
712
  provider: "localStorage"
699
713
  });
700
714
  }));
@@ -714,13 +728,13 @@ const Y = (o, e) => {
714
728
  a.setConversationEndedBehavior(
715
729
  S.Deactivate
716
730
  );
717
- }).then(() => M(o)).then(() => !1))) : (s.container.getAsync("conversation").then((a) => a.navigateToConversationIfActive(e.id).then(
731
+ }).then(() => D(o)).then(() => !1))) : (s.container.getAsync("conversation").then((a) => a.navigateToConversationIfActive(e.id).then(
718
732
  () => a.setConversationEndedBehavior(
719
733
  S.Navigate
720
734
  )
721
735
  )), !n);
722
- }, Z = (o, e, t = "conversation") => {
723
- const { mainWidget: s, chatWidget: r } = W(o);
736
+ }, ee = (o, e, t = "conversation") => {
737
+ const { mainWidget: s, chatWidget: r } = N(o);
724
738
  return r ? r.container.getAsync("router").then((n) => {
725
739
  n.navigate(t, { id: e.id });
726
740
  }) : s.container.getAsync("conversation").then((n) => {
@@ -728,13 +742,13 @@ const Y = (o, e) => {
728
742
  (a = n.setConversationEndedBehavior(S.Navigate)) == null || a.then(() => {
729
743
  s.container.getAsync("router").then((i) => {
730
744
  s.container.getAsync("components").then((c) => {
731
- const d = c.components().ofType("conversation");
745
+ const h = c.components().ofType("conversation");
732
746
  c.write({
733
747
  key: "setConversationProvider",
734
748
  attributes: {
735
749
  properties: { providers: [e.clientName] }
736
750
  },
737
- target: d,
751
+ target: h,
738
752
  provider: "localStorage"
739
753
  });
740
754
  }).then(() => {
@@ -747,15 +761,15 @@ const Y = (o, e) => {
747
761
  var S = /* @__PURE__ */ ((o) => (o.Deactivate = "deactivate", o.Navigate = "navigate", o.None = "none", o))(S || {});
748
762
  class A {
749
763
  constructor(e, t) {
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);
764
+ d(this, "events");
765
+ d(this, "controllers", []);
766
+ d(this, "providers", []);
767
+ d(this, "disposeProviders", {});
768
+ d(this, "subscriptions", []);
769
+ d(this, "storageWriter", null);
770
+ d(this, "router", null);
771
+ d(this, "buttonQuery", null);
772
+ d(this, "sessionInfo", null);
759
773
  this.container = e, this.components = t;
760
774
  const s = e.get("$widget");
761
775
  this.events = s.events.createChild(this);
@@ -823,7 +837,7 @@ class A {
823
837
  async createController(e, t) {
824
838
  const s = _(e), { agents: r } = await f(this.container, s) || { agents: [] }, n = this.controllers.findIndex((i) => i.conversation.id === e);
825
839
  let a;
826
- return n > -1 ? a = this.controllers[n].conversation : a = new V(this.container, e, t), a.setInitialStorage({ agents: r || [] }), a;
840
+ return n > -1 ? a = this.controllers[n].conversation : a = new Y(this.container, e, t), a.setInitialStorage({ agents: r || [] }), a;
827
841
  }
828
842
  registerProvider(e, t) {
829
843
  const s = {
@@ -851,7 +865,7 @@ class A {
851
865
  return this.subscriptions.push(
852
866
  e.onDispose((a, i) => {
853
867
  const c = this.controllers.findIndex(
854
- (d) => d.conversation === i
868
+ (h) => h.conversation === i
855
869
  );
856
870
  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 });
857
871
  })
@@ -859,9 +873,9 @@ class A {
859
873
  e.onProvidersChange((a, i) => {
860
874
  const {
861
875
  added: c,
862
- removed: d = []
876
+ removed: h = []
863
877
  } = i;
864
- d.forEach((u) => {
878
+ h.forEach((u) => {
865
879
  (this.disposeProviders[u] || []).forEach(
866
880
  (l) => {
867
881
  l();
@@ -871,10 +885,10 @@ class A {
871
885
  })
872
886
  ), this.subscriptions.push(
873
887
  e.onStarted((a, i) => {
874
- var d, u;
888
+ var h, u;
875
889
  const c = {
876
890
  id: e.id,
877
- route: (d = this.router) == null ? void 0 : d.getRouteData(),
891
+ route: (h = this.router) == null ? void 0 : h.getRouteData(),
878
892
  conversationEndedBehavior: (u = this.sessionInfo) == null ? void 0 : u.conversationEndedBehavior
879
893
  };
880
894
  this.sessionInfo = c, this.storageWriter && this.storageWriter(c), this.writeToComponents({ active: i });
@@ -919,7 +933,7 @@ class A {
919
933
  }), this.controllers = [], this.providers = [];
920
934
  }
921
935
  static async handleContactMethodClick(e, t, s, r) {
922
- if (X(t)) {
936
+ if (Z(t)) {
923
937
  e.preventDefault();
924
938
  let n = document.getElementById("humany-dynamic-anchor");
925
939
  n || (n = document.createElement("a"), n.setAttribute("href", "#"), n.id = "humany-dynamic-anchor", document.body.appendChild(n)), O(t, s, n);
@@ -932,10 +946,10 @@ class A {
932
946
  e,
933
947
  t.body.form.meta.conversation.id,
934
948
  t.clientName
935
- ) : Z(e, t);
949
+ ) : ee(e, t);
936
950
  }
937
951
  }
938
- const ee = (o, e) => o.reduce((t, s, r) => {
952
+ const te = (o, e) => o.reduce((t, s, r) => {
939
953
  var a, i;
940
954
  const n = {
941
955
  ...s,
@@ -947,7 +961,7 @@ const ee = (o, e) => o.reduce((t, s, r) => {
947
961
  return c.timestamp = s.timestamp, c.content.push({ ...s.content, key: s.key }), t;
948
962
  }
949
963
  return t.push(n), t;
950
- }, []), he = (o) => Promise.all([
964
+ }, []), le = (o) => Promise.all([
951
965
  A.getInstance(o),
952
966
  o.getAsync("router")
953
967
  ]).then(([e, t]) => H(
@@ -960,7 +974,7 @@ const ee = (o, e) => o.reduce((t, s, r) => {
960
974
  }), c = e.registerController(
961
975
  i,
962
976
  s
963
- ), d = 3 * 60 * 1e3, u = (g) => {
977
+ ), h = 3 * 60 * 1e3, u = (g) => {
964
978
  const { providers: p = [] } = g;
965
979
  if (p) {
966
980
  const m = Array.isArray(p) ? p : [p];
@@ -975,7 +989,7 @@ const ee = (o, e) => o.reduce((t, s, r) => {
975
989
  s.writeProperties({
976
990
  loading: p,
977
991
  typingActors: m,
978
- messages: ee(P, d)
992
+ messages: te(P, h)
979
993
  });
980
994
  };
981
995
  l(i.getMessageStream()), c && (s.writeProperties({
@@ -984,8 +998,8 @@ const ee = (o, e) => o.reduce((t, s, r) => {
984
998
  if (p) {
985
999
  const { preventDefault: m, validationPromise: P } = p;
986
1000
  if (m) {
987
- P && P().then((D) => {
988
- D && i.user.print(D);
1001
+ P && P().then((W) => {
1002
+ W && i.user.print(W);
989
1003
  });
990
1004
  return;
991
1005
  }
@@ -1029,7 +1043,7 @@ const ee = (o, e) => o.reduce((t, s, r) => {
1029
1043
  };
1030
1044
  },
1031
1045
  { reuseController: !0 }
1032
- )), le = (o) => Promise.all([
1046
+ )), ue = (o) => Promise.all([
1033
1047
  R.getInstance(o),
1034
1048
  A.getInstance(o),
1035
1049
  o.getAsync("router")
@@ -1048,8 +1062,8 @@ const ee = (o, e) => o.reduce((t, s, r) => {
1048
1062
  }
1049
1063
  )
1050
1064
  );
1051
- var te = /* @__PURE__ */ ((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))(te || {});
1052
- const ue = (o, e, t) => o.getAsync("componentResolver").then(async (s) => {
1065
+ var se = /* @__PURE__ */ ((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))(se || {});
1066
+ const pe = (o, e, t) => o.getAsync("componentResolver").then(async (s) => {
1053
1067
  (await A.getInstance(o)).addSubscription(
1054
1068
  s.registerComponent(
1055
1069
  e,
@@ -1059,14 +1073,14 @@ const ue = (o, e, t) => o.getAsync("componentResolver").then(async (s) => {
1059
1073
  });
1060
1074
  export {
1061
1075
  k as Agent,
1062
- he as ConversationComponent,
1063
- V as ConversationController,
1076
+ le as ConversationComponent,
1077
+ Y as ConversationController,
1064
1078
  S as ConversationEndedBehavior,
1065
- J as ConversationEntry,
1066
- te as ConversationMessageListItemType,
1079
+ V as ConversationEntry,
1080
+ se as ConversationMessageListItemType,
1067
1081
  w as ConversationMessageType,
1068
1082
  A as ConversationPlatform,
1069
1083
  T as ConversationProvider,
1070
- le as ConversationReturnButtonComponent,
1071
- ue as registerCustomMessageComponent
1084
+ ue as ConversationReturnButtonComponent,
1085
+ pe as registerCustomMessageComponent
1072
1086
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/widget-conversation",
3
- "version": "1.3.20-rc.0",
3
+ "version": "1.3.20",
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.3.20-rc.0",
14
- "@telia-ace/widget-forms": "^1.3.20-rc.0",
15
- "@telia-ace/widget-plugins": "^1.3.20-rc.0",
16
- "@telia-ace/widget-routing": "^1.3.20-rc.0",
17
- "@telia-ace/widget-services": "^1.3.20-rc.0",
18
- "@telia-ace/widget-ui": "^1.3.20-rc.0",
19
- "@telia-ace/widget-utilities": "^1.3.20-rc.0",
13
+ "@telia-ace/widget-core": "^1.3.20",
14
+ "@telia-ace/widget-forms": "^1.3.20",
15
+ "@telia-ace/widget-plugins": "^1.3.20",
16
+ "@telia-ace/widget-routing": "^1.3.20",
17
+ "@telia-ace/widget-services": "^1.3.20",
18
+ "@telia-ace/widget-ui": "^1.3.20",
19
+ "@telia-ace/widget-utilities": "^1.3.20",
20
20
  "@webprovisions/platform": "^1.1.4"
21
21
  },
22
22
  "peerDependencies": {