@telia-ace/conversational-hub-bot-provider 1.3.19-rc.0 → 1.3.19
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/{contact-method-881cb6d7.js → contact-method-2cfae642.js} +1 -1
- package/{contact-method-ef6ff504.mjs → contact-method-ee54b786.mjs} +1 -1
- package/{contact-method-list-eec9b6aa.mjs → contact-method-list-0050453e.mjs} +2 -2
- package/{contact-method-list-2cdf2193.js → contact-method-list-69907dba.js} +1 -1
- package/index-0d0a5fc2.js +1 -0
- package/{index-0efa1461.mjs → index-3bfdc270.mjs} +101 -101
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +10 -10
- package/index-0962774e.js +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("react/jsx-runtime"),R=require("@emotion/styled"),F=require("@telia-ace/knowledge-data-client"),$=require("@telia-ace/knowledge-widget-adapters"),C=require("@telia-ace/knowledge-widget-ui"),z=require("@telia-ace/widget-forms"),O=require("@telia-ace/widget-utilities"),l=require("react"),x=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("react/jsx-runtime"),R=require("@emotion/styled"),F=require("@telia-ace/knowledge-data-client"),$=require("@telia-ace/knowledge-widget-adapters"),C=require("@telia-ace/knowledge-widget-ui"),z=require("@telia-ace/widget-forms"),O=require("@telia-ace/widget-utilities"),l=require("react"),x=require("./index-0d0a5fc2.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");require("@webprovisions/platform");const U=({contactMethodId:i,guideId:n,groupId:b,className:T})=>{var h,q,k,S,j;const[e,u]=l.useState(),c=C.useContainer(),A=C.useDispatch(),f=l.useRef(!0),y=C.useConversation();l.useEffect(()=>{const{events:t}=c.get("$widget"),m=t.subscribe("conversational-hub-provider:form-submitted",async(a,o)=>{var D;if(((D=o.form.meta)==null?void 0:D.groupId)!==b||o.id!==(e==null?void 0:e.id))return;y&&(o.form.meta||(o.form.meta={}),o.form.meta.conversation=y);const p=await c.getAsync("contactMethods"),r={...e,body:{...e.body,form:o.form}},{errors:d,valid:g,errorTypes:_}=await p.validate(r);if(!g){const E=new z.FormBuilder(e.body.form);u(void 0),E.setValidationErrors(d),r.body={...r.body,form:E.get()},u({...r});return}const B=await p.submit(r);r.confirmation=B,u(r)}),s=t.subscribe("bot-provider:evaluate",async(a,o)=>{if(o.id!==i)return;const r=await(await c.getAsync("contactMethods")).evaluate(e);let d={...e,body:{...e.body,form:r}};const g=x.updateForm(d,{submit:"Submit",errors:{},meta:{groupId:b}});d={...d,body:g},u(d)});return()=>{m(),s()}},[c,e,u,y]);const v=(t,m,s=null)=>{if(t["ui:component"]&&t["ui:component"]==="Date")return Object.assign(t,{"ui:bot":!0,"ui:entrance":m}),t;for(const a in t)if(typeof t[a]=="object"&&t[a]!==null){const o=v(t[a],m,t);if(o!==void 0)return o}},w=l.useCallback(async t=>{const s=await(await F.DataClient.getInstance(c)).fetch(F.DataType.ContactMethod,{contactMethodId:t,guideId:n},{noCache:!0,isBot:!0}),a=x.updateForm(s,{submit:"Submit",errors:{},meta:{groupId:b}});if(s.body=a,s.body.guideId=n,!f.current)return null;u(s)},[f]);return l.useEffect(()=>(w(i),()=>{f.current=!1}),[i,w]),e?(e.clientName==="ace.callback"&&((h=e.body)!=null&&h.entrance)&&v(e,(q=e.body)==null?void 0:q.entrance),N.jsx(W,{...e,body:{...e.body,form:e.body.form?{...e.body.form,data:(k=e.body.form)==null?void 0:k.data,layout:{...e.body.form.layout},meta:(S=e.body.form)==null?void 0:S.meta,schema:(j=e.body.form)==null?void 0:j.schema}:void 0,guideId:e.body.guideId},inline:!0,expanded:!0,dispatch:A,className:O.appendClassNames("humany-bot-contact-method",T)})):null},W=R($.ContactMethod)`
|
|
2
2
|
padding: ${i=>{var n;return(n=i.theme.sizes)==null?void 0:n.normal}} ${i=>{var n;return(n=i.theme.sizes)==null?void 0:n.medium}};
|
|
3
3
|
`;exports.default=U;
|
|
@@ -6,7 +6,7 @@ import { useContainer as _, useDispatch as G, useConversation as I } from "@teli
|
|
|
6
6
|
import { FormBuilder as M } from "@telia-ace/widget-forms";
|
|
7
7
|
import { appendClassNames as O } from "@telia-ace/widget-utilities";
|
|
8
8
|
import { useState as V, useRef as q, useEffect as $, useCallback as H } from "react";
|
|
9
|
-
import { u as j } from "./index-
|
|
9
|
+
import { u as j } from "./index-3bfdc270.mjs";
|
|
10
10
|
import "@telia-ace/widget-conversation";
|
|
11
11
|
import "@telia-ace/widget-services";
|
|
12
12
|
import "@webprovisions/platform";
|
|
@@ -3,11 +3,11 @@ import m from "@emotion/styled";
|
|
|
3
3
|
import { ContactList as M, ContactMethod as b } from "@telia-ace/knowledge-widget-adapters";
|
|
4
4
|
import { useDispatch as $, useContainer as k } from "@telia-ace/knowledge-widget-ui";
|
|
5
5
|
import { useState as f, useEffect as E } from "react";
|
|
6
|
-
import S from "./contact-method-
|
|
6
|
+
import S from "./contact-method-ee54b786.mjs";
|
|
7
7
|
import "@telia-ace/knowledge-data-client";
|
|
8
8
|
import "@telia-ace/widget-forms";
|
|
9
9
|
import "@telia-ace/widget-utilities";
|
|
10
|
-
import "./index-
|
|
10
|
+
import "./index-3bfdc270.mjs";
|
|
11
11
|
import "@telia-ace/widget-conversation";
|
|
12
12
|
import "@telia-ace/widget-services";
|
|
13
13
|
import "@webprovisions/platform";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),u=require("@emotion/styled"),y=require("@telia-ace/knowledge-widget-adapters"),g=require("@telia-ace/knowledge-widget-ui"),l=require("react"),b=require("./contact-method-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),u=require("@emotion/styled"),y=require("@telia-ace/knowledge-widget-adapters"),g=require("@telia-ace/knowledge-widget-ui"),l=require("react"),b=require("./contact-method-2cfae642.js");require("@telia-ace/knowledge-data-client");require("@telia-ace/widget-forms");require("@telia-ace/widget-utilities");require("./index-0d0a5fc2.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");require("@webprovisions/platform");const k=({actions:e,entryId:t,groupId:x})=>{const q=g.useDispatch(),o=g.useContainer(),[h,C]=l.useState([]),[d,M]=l.useState([]);return l.useEffect(()=>{o.getAsync("contactMethods").then(n=>{if(!n)return;const c=e.map(async i=>{var m;if(!((m=i.data)!=null&&m.clientName))return null;const s=await n.handleAdapters(i.data);return{...s,...i.data,description:i.data.description?i.data.description:s.description,onClick:(p,r)=>{if(typeof s.onClick=="function"&&s.onClick(p,r),!p.defaultPrevented)if(r.inline&&!r.expanded)M([...d,r.id]);else{const{events:f}=o.get("$widget");f.dispatch("conversational-hub-provider:open-contact-method",{entryId:t,contactMethod:r,actionKey:i.actionKey}),f.dispatch("tracking:contact-method-list-item-clicked",r)}}}});Promise.all(c).then(i=>{C(i.filter(s=>!!s))})})},[e,o,t,d]),h.length?a.jsx(j,{className:"humany-bot-contact-list",contactMethods:h,dispatch:q,itemRenderer:(n,c)=>(d.includes(n.id)||n.expanded)&&n.inline||n.clientName==="custom.link"?a.jsx(S,{contactMethodId:n.id,groupId:x,guideId:n.body.guideId}):a.jsx($,{...n,...c})}):null},j=u(y.ContactList)`
|
|
2
2
|
> ul > li {
|
|
3
3
|
a {
|
|
4
4
|
display: flex;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var X=Object.defineProperty;var Y=(i,e,n)=>e in i?X(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n;var O=(i,e,n)=>(Y(i,typeof e!="symbol"?e+"":e,n),n);const N=require("@telia-ace/widget-conversation"),j=require("@telia-ace/widget-services"),K=require("@telia-ace/widget-utilities"),F=require("@telia-ace/widget-forms"),Z=require("@webprovisions/platform");class tt{constructor(e){O(this,"enabled",!0);O(this,"botProviderGlobalStateKey","bot-provider-global-state");O(this,"botProviderLocalStateKey","bot-provider-local-state");O(this,"botProviderEntriesKey","bot-provider-entries");O(this,"botProviderMetaStateKey","bot-provider-conversation-meta");this.container=e}getKey(e){let n;switch(e){case"localState":n=this.botProviderLocalStateKey;break;case"globalState":n=this.botProviderGlobalStateKey;break;case"entries":n=this.botProviderEntriesKey;break;case"meta":n=this.botProviderMetaStateKey;break}return n}async read(e){const n=this.getKey(e);if(!(!this.enabled||!n))return j.readStorage(this.container,n)}async write(e,n){const t=this.getKey(n);if(!this.enabled||!t)return;(await j.createStorageWriter(this.container,t,j.StorageCategory.Necessary))(e)}}var $=(i=>(i.ContactMethod="ace-conversational-hub-contact-method",i.ContactList="ace-conversational-hub-contact-list",i))($||{});const et=i=>{if(i){const{type:e,content:n}=i;if(e&&n)return{type:e,content:n}}},nt=({isUser:i,items:e=[],meta:n={}})=>{const t=K.uuid();return{id:t,isUser:i,items:e.map(y=>({id:y.id||K.uuid(),isUser:i,groupId:t,message:y.message||[]})),meta:n}},it=({id:i,title:e,defaultIcon:n,exits:[t],exitType:d,confirmationText:y,expandFormAutomatically:p,form:M,description:P},a={})=>{const{adapter:l}=t||{Adapter:{}},{clientName:u="",settings:b={},customClientName:m=""}=l,{validation:v}=a,g={id:i.toString(),title:e,description:P,symbol:et(n),clientName:u==="custom.adapter"?m:u,expanded:!0,inline:!0,body:{}};if(u.indexOf("phone")>-1||u.indexOf("freetext")>-1){const{displayTextBeforeClick:f,textBeforeClick:L}=b;f==="true"&&(g.expanded=!1,g.title=L),u.indexOf("phone.text")>-1?g.body.phoneNumber=b.phoneNumber:g.body.freetext=b.freetext}return(u.indexOf("chat.popup")>-1||u.indexOf("link")>-1||u==="custom.adapter"&&d==="custom")&&(g.body=b,g.body.confirmationFallback=y),u.indexOf("ace")>-1&&(g.body=b),M&&M.hasValueComponents&&(v?g.body.form=F.FormBuilder.fromLegacyForm(i.toString(),M,v).get():g.body.form=F.FormBuilder.fromLegacyForm(i.toString(),M).get(),p||(g.expanded=g.inline=!1),g.body=z(g,{submit:"Submit"})),a.guideId&&(g.body.guideId=a.guideId),g},ot=i=>{const{localState:e}=i;return i.tags.includes("category")&&i.tags.includes("contact")?N.ConversationMessageListItemType.ItemList:i.tags.includes("suggestion")?N.ConversationMessageListItemType.LinkList:(e==null?void 0:e.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"?$.ContactList:N.ConversationMessageListItemType.ButtonList},z=(i,{submit:e,errors:n,meta:t})=>{var d;if((d=i==null?void 0:i.body)!=null&&d.form){const{body:y}=i,p=new F.FormBuilder(y.form);return y.form.layout.submit||p.createComponent(F.submitButton(e,"submit")),n&&p.setValidationErrors(n),t&&p.setMeta(t),{...y,form:p.get()}}return(i==null?void 0:i.body)||{}},st=async(i,e,n)=>{(await(await i.getAsync("dataClient")).getClient()).parameters.set(e,n)},A=({messageId:i,message:e,group:n})=>({id:i,message:e,groupId:n.id,isUser:n.isUser}),at=async(i,e,n)=>{const t=(a,l,u,b={actions:[],entryId:l.id,groupId:u})=>{const m=[];return b.actions=l.content.items.map(v=>{var f;const g={label:v.title,actionKey:v.actionKey,symbol:v.symbol?v.symbol:void 0,description:v.description||void 0};if(v.data){const L=l.actions[v.actionKey];a===$.ContactList?(m.push(v.data.id),g.data=it(v.data,{guideId:(f=L==null?void 0:L.guideId)==null?void 0:f.toString()})):g.data=v.data}return g}),a===$.ContactList&&(b.contactMethodIds=m),b},d=async(a,l,u=[],b)=>{var v,g;const m=K.uuid();switch(a.type!=="List"&&a.tags.includes("guide")&&((g=(v=a.content.hints)==null?void 0:v[0])!=null&&g.id)&&await st(i,"LastGuideId",a.content.hints[0].id),a.type){case"List":{if(!a.content)return[];const{items:f,html:L}=a.content,k=[];let C={actions:[],entryId:a.id,groupId:l.id};if((f==null?void 0:f.length)>0){const T=ot(a);if(C=t(T,a,l.id,C),u.length){const x=u.find(H=>H.tags.includes("paging"));x!=null&&x.content&&(l.meta.paging={actions:x.actions,items:x.content.items,localState:x.localState},x.content.items.forEach(H=>{C.actions.push({label:H.title,actionKey:H.actionKey,data:{groupId:b?b.id:l.id}})}))}k.unshift(A({messageId:m,message:[T,C],group:l}))}return L&&k.unshift(A({messageId:m,message:[N.ConversationMessageListItemType.HTML,{body:L}],group:l})),k}case"Text":{const f=[];if(f.push(A({messageId:m,message:[N.ConversationMessageListItemType.HTML,{body:a.content.html}],group:l})),u.length){const L=u.find(C=>{var T;return C.type==="List"&&((T=C.localState)==null?void 0:T.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"}),k=u.find(C=>C.tags.includes("contact")&&C.type==="Contact");if(k&&f.push(A({messageId:m,message:[$.ContactMethod,{contactMethodId:k.content.id,groupId:l.id,guideId:k.content.guideId}],group:l})),L){const C=t($.ContactList,L,l.id);f.push(A({messageId:m,message:[N.ConversationMessageListItemType.Separator,void 0],group:l})),f.push(A({messageId:m,message:[$.ContactList,C],group:l}))}}return f}case"Contact":return[A({messageId:m,message:[$.ContactMethod,{contactMethodId:a.content.id,groupId:l.id,guideId:a.content.guideId}],group:l})];case"Error":return[A({messageId:m,message:[N.ConversationMessageListItemType.HTML,{body:a.content.message||"Something went wrong."}],group:l})];default:return[]}},y=new Map([["Text",1],["List",2],["Contact",3]]),p=[],M=e.sort((a,l)=>{const b=y.get(a.type)||20,m=y.get(l.type)||20;return b-m}).filter(a=>!a.relation).reduce((a,l)=>a.concat(l),[]),P=a=>typeof a.actions.selector<"u";for(const a of M){const l=e.filter(m=>m.relation===a.id&&!P(m)),u=nt({isUser:!1});(await d(a,u,l,n)).forEach(m=>{u.items.push(m)}),u.items.length&&p.push(u)}return p};class rt{constructor(e,n,t,d){O(this,"globalState");O(this,"localState");O(this,"clientId");O(this,"entries");this.endpoint=e,this.events=n,this.store=t,this.container=d,this.clientId=K.uuid(),this.entries=[]}async fetchGuide(e){const n={command:{guide:{id:e}},globalState:this.globalState,clientId:this.clientId};return await this.postEnvelope(n)}async postEnvelope(e,n){try{const t=await fetch(this.endpoint,this.getHttpOptions(e));if(!t.ok)throw t;const d=await t.json();return this.handleResponse(d,n)}catch(t){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let d="Something went wrong";return(t.message==="Failed to fetch"||t.message==="NetworkError when attempting to fetch resource.")&&(d="Lost connection... Please try again."),this.events.dispatch("tracking:http-client-error",{message:d,error:t}),this.handleResponse({entries:[{id:K.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:d},actions:{},tags:[]}]})}}async handleResponse(e,n){this.entries=this.entries.concat(e.entries),this.store.write(this.entries,"entries");const t=e.entries.find(y=>y.type==="Widget");return t&&this.events.dispatch("provider:widget-entry",t.content),e.globalState&&(this.globalState=e.globalState,this.store.write(e.globalState,"globalState")),this.localState=e.entries.reduce((y,p)=>p.localState?p.localState:y,void 0),this.store.write(this.localState,"localState"),await at(this.container,e.entries,n)}getHttpOptions(e){const n={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"}};return e.funnel=this.container.get("$widget").name,e.localState=e.localState||this.localState,Object.assign({},n,{body:JSON.stringify(e),credentials:"same-origin"})}}const ct="@telia-ace/conversational-hub-bot-provider",lt="0.0.16",dt="./index.js",ut="./index.d.ts",gt={".":{import:"./index.mjs",require:"./index.js"}},mt={"@telia-ace/widget-conversation":"*","@webprovisions/platform":"^1.1.4","@telia-ace/knowledge-widget-core":"*","@telia-ace/widget-utilities":"*","@telia-ace/widget-services":"*","@telia-ace/widget-core":"*","@telia-ace/knowledge-data-client":"*","@telia-ace/knowledge-widget-adapters":"*","@telia-ace/knowledge-widget-ui":"*","@telia-ace/widget-forms":"*"},pt={"@emotion/react":"11.11.1","@emotion/styled":"11.11.0",react:"18.2.0"},B={name:ct,version:lt,main:dt,types:ut,exports:gt,dependencies:mt,peerDependencies:pt},ft=async i=>{var V,G,J,U,D;const e="chub-plugin",n=i.get("$widget"),t=(D=(U=(J=(G=(V=n==null?void 0:n.container)==null?void 0:V.get("$settings"))==null?void 0:G.components)==null?void 0:J.conversation)==null?void 0:U.properties)==null?void 0:D.conversationalHubPluginSettings;let d,y,p,M=(t==null?void 0:t.connectionAttempts)??5,P,a,l;K.Logger.info((B==null?void 0:B.name)+" version: "+(B==null?void 0:B.version)),N.registerCustomMessageComponent(i,$.ContactMethod,Promise.resolve().then(()=>require("./contact-method-2cfae642.js"))),N.registerCustomMessageComponent(i,$.ContactList,Promise.resolve().then(()=>require("./contact-method-list-69907dba.js")));const u=await j.createStorageWriter(i,"conversational-hub-session",j.StorageCategory.Necessary),b=(r,s)=>{const{knowledgeBotEndpoint:o}=s.properties();if(o)return`${o}/conversations`;const{data:c}=r.get("$settings");if(!c||!c.projection)throw new Error("Missing Knowledge Bot endpoint");return`${c.projection}/conversations`},m=r=>{var s;if(r.target instanceof HTMLButtonElement){const o=r.target;if((s=o.getAttribute("class"))!=null&&s.includes("dialog-option-cx")){const c=o.getAttribute("value");T(c),d.user.print(c.replace(/</g,"<").replace(/>/g,">"))}}};(await N.ConversationPlatform.getInstance(i)).registerProvider(e,(r,s)=>{d=r,y=d.controller,p=d.createAgent({name:t==null?void 0:t.botName,avatar:t==null?void 0:t.avatar}),l=b(i,s);const{events:o}=i.get("$widget"),c=new tt(i);a=new rt(l,o,c,i),k();const[h]=i.get("widgetDOMElements");h.querySelectorAll(".humany-bot-contact-method").forEach(I=>{var w;(w=I.closest(".humany-conversation-entry"))==null||w.remove()}),h.removeEventListener("click",m),h.addEventListener("click",m);const S=()=>y.providers.includes(e);s.actions.create("submit",I=>{const{events:w}=i.get("$widget");w.dispatch("conversational-hub-provider:form-submitted",I)}),s.actions.watch("conversation.action",(I,w)=>(S()&&C(I),w(I))),s.actions.watch("conversation.user-submit",(I,w)=>{if(!S())return w(I);T(I.text),d.user.print(I.text.replace(/</g,"<").replace(/>/g,">"))}),n.events.subscribe("conversational-hub-provider:fetch-guide",async(I,w)=>{if(!(w!=null&&w.guideId))return;const _=await a.fetchGuide(parseInt(w.guideId));_&&g(_)})});async function g(r){r.forEach(s=>{const o=s.items.map(c=>c.message);s.writer=p.print(o)})}const f=sessionStorage.getItem(`humany_${L(n.implementation.tenant+n.implementation.name+n.name)}`);function L(r){let s=0;if(r.length===0)return s.toString();for(let o=0;o<r.length;o++){const c=r.charCodeAt(o);s=(s<<5)-s+c,s=s&s}return s.toString()}async function k(r=!0){const s=await j.readStorage(i,"conversational-hub-session"),o=i.get("dialogflowSettings");if(o!=null&&o.silentStart)delete o.silentStart,n.events.dispatch("conversational-hub-provider:started",{});else if(s!=null&&s.sessionId&&r)P=s==null?void 0:s.sessionId;else if(t!=null&&t.welcomeMessage){if(!(f!=null&&f.length?JSON.parse(f):{})["conversation-conversation"]){const h=t.welcomeMessage.replaceAll("$lt;","<").replaceAll("$gt;",">");p.print(h)}}else{const c={extension:t.extension};o!=null&&o.initCommand&&(c.input={type:"event",language:t.language,content:{name:o.initCommand,parameters:o.initParameters||{}}}),await x(t.baseUrl+"/initialize",JSON.stringify(c),r)}}async function C(r){await x(`${t.baseUrl}/input/${P}`,`{"type":"button_click","language":"${t.language}","content":{"button_text":"${r.label}","value":"${r.actionKey}"}}`)}async function T(r){const s={text:r};if(!P){const o={extension:t.extension},c=i.get("dialogflowSettings");c!=null&&c.initCommand&&(o.input={type:"event",language:t.language,content:{name:c.initCommand,parameters:c.initParameters||{}}}),await x(t.baseUrl+"/initialize",JSON.stringify(o),!1)}await x(`${t.baseUrl}/input/${P}`,`{"type":"text","language":"${t.language}","content":${JSON.stringify(s)}}`)}async function x(r,s,o=!0){var I,w,_,R;const c=d.loading();let h,S;try{h=await fetch(r,{method:"POST",body:s}),S=await(h==null?void 0:h.json())}catch(q){q instanceof SyntaxError?K.Logger.error("Incorrect JSON format.",q):K.Logger.error("Network error: check connection or baseUrl.",q),c(),p.print(t.errorMessage||"An error occurred");return}if(!(h!=null&&h.ok)){if(K.Logger.error(`HTTP ${h==null?void 0:h.status}.`,JSON.stringify(S)),c(),!!((I=S==null?void 0:S.errors)!=null&&I.filter(E=>E.code==="1003").length)&&M>0){M--,await new Promise(Q=>setTimeout(Q,500)),await k(!1);const E=JSON.parse(s);(w=E==null?void 0:E.content)!=null&&w.text?await T(E.content.text):(_=E==null?void 0:E.content)!=null&&_.action&&await C((R=E==null?void 0:E.content)==null?void 0:R.action)}else p.print(t.errorMessage||"An error occurred");return}c(),M=(t==null?void 0:t.connectionAttempts)??5,S!=null&&S.action_payload&&H(S.action_payload),P=S==null?void 0:S.session_id,u({sessionId:P}),o&&W(S)}async function H(r){var h;const s=(h=r==null?void 0:r.transfer_parameters)==null?void 0:h.contactGuide,o=d.loading(),c=await a.fetchGuide(parseInt(s));o(),c&&g(c)}function W(r){var s;r==null||r.agent_response.forEach(o=>{p.print(o.payload.text)}),(s=r==null?void 0:r.prompt)!=null&&s.items&&p.print(["button-list",{actions:r.prompt.items.map(o=>{let c;return o.type==="button"&&(c={actionKey:o.value,label:o.text}),o.type==="link"&&(c={actionKey:o.value,label:o.text,data:{href:o.url,target:(t==null?void 0:t.linkTarget)??"_blank"}}),c})}])}},ht=Z.createConfigurationApi(i=>{i.createCommand("dialogflow",e=>n=>{const t={initCommand:n.initCommand};n.initParameters&&(t.initParameters=n.initParameters),n.silentStart&&(t.silentStart=n.silentStart),e.container.register("dialogflowSettings",t)})});exports.ConversationalHubPlugin=ft;exports.dialogflowConfigurationApi=ht;exports.updateForm=z;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var tt = Object.defineProperty;
|
|
2
2
|
var et = (i, e, n) => e in i ? tt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n;
|
|
3
|
-
var
|
|
3
|
+
var M = (i, e, n) => (et(i, typeof e != "symbol" ? e + "" : e, n), n);
|
|
4
4
|
import { ConversationMessageListItemType as A, registerCustomMessageComponent as q, ConversationPlatform as nt } from "@telia-ace/widget-conversation";
|
|
5
5
|
import { readStorage as W, createStorageWriter as Q, StorageCategory as X } from "@telia-ace/widget-services";
|
|
6
6
|
import { uuid as j, Logger as V } from "@telia-ace/widget-utilities";
|
|
@@ -8,12 +8,12 @@ import { FormBuilder as G, submitButton as it } from "@telia-ace/widget-forms";
|
|
|
8
8
|
import { createConfigurationApi as ot } from "@webprovisions/platform";
|
|
9
9
|
class st {
|
|
10
10
|
constructor(e) {
|
|
11
|
-
|
|
11
|
+
M(this, "enabled", !0);
|
|
12
12
|
// set whether or not to store data
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
M(this, "botProviderGlobalStateKey", "bot-provider-global-state");
|
|
14
|
+
M(this, "botProviderLocalStateKey", "bot-provider-local-state");
|
|
15
|
+
M(this, "botProviderEntriesKey", "bot-provider-entries");
|
|
16
|
+
M(this, "botProviderMetaStateKey", "bot-provider-conversation-meta");
|
|
17
17
|
this.container = e;
|
|
18
18
|
}
|
|
19
19
|
getKey(e) {
|
|
@@ -66,11 +66,11 @@ const at = (i) => {
|
|
|
66
66
|
return {
|
|
67
67
|
id: t,
|
|
68
68
|
isUser: i,
|
|
69
|
-
items: e.map((
|
|
70
|
-
id:
|
|
69
|
+
items: e.map((b) => ({
|
|
70
|
+
id: b.id || j(),
|
|
71
71
|
isUser: i,
|
|
72
72
|
groupId: t,
|
|
73
|
-
message:
|
|
73
|
+
message: b.message || []
|
|
74
74
|
})),
|
|
75
75
|
meta: n
|
|
76
76
|
};
|
|
@@ -80,16 +80,16 @@ const at = (i) => {
|
|
|
80
80
|
defaultIcon: n,
|
|
81
81
|
exits: [t],
|
|
82
82
|
exitType: d,
|
|
83
|
-
confirmationText:
|
|
83
|
+
confirmationText: b,
|
|
84
84
|
expandFormAutomatically: f,
|
|
85
85
|
form: k,
|
|
86
86
|
description: P
|
|
87
87
|
}, a = {}) => {
|
|
88
88
|
const { adapter: l } = t || { Adapter: {} }, {
|
|
89
89
|
clientName: u = "",
|
|
90
|
-
settings:
|
|
90
|
+
settings: y = {},
|
|
91
91
|
customClientName: m = ""
|
|
92
|
-
} = l, { validation:
|
|
92
|
+
} = l, { validation: v } = a, g = {
|
|
93
93
|
id: i.toString(),
|
|
94
94
|
title: e,
|
|
95
95
|
description: P,
|
|
@@ -100,13 +100,13 @@ const at = (i) => {
|
|
|
100
100
|
body: {}
|
|
101
101
|
};
|
|
102
102
|
if (u.indexOf("phone") > -1 || u.indexOf("freetext") > -1) {
|
|
103
|
-
const { displayTextBeforeClick:
|
|
104
|
-
|
|
103
|
+
const { displayTextBeforeClick: p, textBeforeClick: x } = y;
|
|
104
|
+
p === "true" && (g.expanded = !1, g.title = x), u.indexOf("phone.text") > -1 ? g.body.phoneNumber = y.phoneNumber : g.body.freetext = y.freetext;
|
|
105
105
|
}
|
|
106
|
-
return (u.indexOf("chat.popup") > -1 || u.indexOf("link") > -1 || u === "custom.adapter" && d === "custom") && (g.body =
|
|
106
|
+
return (u.indexOf("chat.popup") > -1 || u.indexOf("link") > -1 || u === "custom.adapter" && d === "custom") && (g.body = y, g.body.confirmationFallback = b), u.indexOf("ace") > -1 && (g.body = y), k && k.hasValueComponents && (v ? g.body.form = G.fromLegacyForm(
|
|
107
107
|
i.toString(),
|
|
108
108
|
k,
|
|
109
|
-
|
|
109
|
+
v
|
|
110
110
|
).get() : g.body.form = G.fromLegacyForm(
|
|
111
111
|
i.toString(),
|
|
112
112
|
k
|
|
@@ -121,16 +121,16 @@ const at = (i) => {
|
|
|
121
121
|
}) => {
|
|
122
122
|
var d;
|
|
123
123
|
if ((d = i == null ? void 0 : i.body) != null && d.form) {
|
|
124
|
-
const { body:
|
|
125
|
-
return
|
|
126
|
-
...
|
|
124
|
+
const { body: b } = i, f = new G(b.form);
|
|
125
|
+
return b.form.layout.submit || f.createComponent(it(e, "submit")), n && f.setValidationErrors(n), t && f.setMeta(t), {
|
|
126
|
+
...b,
|
|
127
127
|
form: f.get()
|
|
128
128
|
};
|
|
129
129
|
}
|
|
130
130
|
return (i == null ? void 0 : i.body) || {};
|
|
131
131
|
}, ut = async (i, e, n) => {
|
|
132
132
|
(await (await i.getAsync("dataClient")).getClient()).parameters.set(e, n);
|
|
133
|
-
},
|
|
133
|
+
}, K = ({
|
|
134
134
|
messageId: i,
|
|
135
135
|
message: e,
|
|
136
136
|
group: n
|
|
@@ -140,32 +140,32 @@ const at = (i) => {
|
|
|
140
140
|
groupId: n.id,
|
|
141
141
|
isUser: n.isUser
|
|
142
142
|
}), gt = async (i, e, n) => {
|
|
143
|
-
const t = (a, l, u,
|
|
143
|
+
const t = (a, l, u, y = {
|
|
144
144
|
actions: [],
|
|
145
145
|
entryId: l.id,
|
|
146
146
|
groupId: u
|
|
147
147
|
}) => {
|
|
148
148
|
const m = [];
|
|
149
|
-
return
|
|
150
|
-
var
|
|
149
|
+
return y.actions = l.content.items.map((v) => {
|
|
150
|
+
var p;
|
|
151
151
|
const g = {
|
|
152
|
-
label:
|
|
153
|
-
actionKey:
|
|
154
|
-
symbol:
|
|
155
|
-
description:
|
|
152
|
+
label: v.title,
|
|
153
|
+
actionKey: v.actionKey,
|
|
154
|
+
symbol: v.symbol ? v.symbol : void 0,
|
|
155
|
+
description: v.description || void 0
|
|
156
156
|
};
|
|
157
|
-
if (
|
|
158
|
-
const x = l.actions[
|
|
159
|
-
a === $.ContactList ? (m.push(
|
|
160
|
-
guideId: (
|
|
161
|
-
})) : g.data =
|
|
157
|
+
if (v.data) {
|
|
158
|
+
const x = l.actions[v.actionKey];
|
|
159
|
+
a === $.ContactList ? (m.push(v.data.id), g.data = ct(v.data, {
|
|
160
|
+
guideId: (p = x == null ? void 0 : x.guideId) == null ? void 0 : p.toString()
|
|
161
|
+
})) : g.data = v.data;
|
|
162
162
|
}
|
|
163
163
|
return g;
|
|
164
|
-
}), a === $.ContactList && (
|
|
165
|
-
}, d = async (a, l, u = [],
|
|
166
|
-
var
|
|
164
|
+
}), a === $.ContactList && (y.contactMethodIds = m), y;
|
|
165
|
+
}, d = async (a, l, u = [], y) => {
|
|
166
|
+
var v, g;
|
|
167
167
|
const m = j();
|
|
168
|
-
switch (a.type !== "List" && a.tags.includes("guide") && ((g = (
|
|
168
|
+
switch (a.type !== "List" && a.tags.includes("guide") && ((g = (v = a.content.hints) == null ? void 0 : v[0]) != null && g.id) && await ut(
|
|
169
169
|
i,
|
|
170
170
|
"LastGuideId",
|
|
171
171
|
a.content.hints[0].id
|
|
@@ -173,16 +173,16 @@ const at = (i) => {
|
|
|
173
173
|
case "List": {
|
|
174
174
|
if (!a.content)
|
|
175
175
|
return [];
|
|
176
|
-
const { items:
|
|
176
|
+
const { items: p, html: x } = a.content, O = [];
|
|
177
177
|
let C = {
|
|
178
178
|
actions: [],
|
|
179
179
|
entryId: a.id,
|
|
180
180
|
groupId: l.id
|
|
181
181
|
};
|
|
182
|
-
if ((
|
|
183
|
-
const
|
|
182
|
+
if ((p == null ? void 0 : p.length) > 0) {
|
|
183
|
+
const N = lt(a);
|
|
184
184
|
if (C = t(
|
|
185
|
-
|
|
185
|
+
N,
|
|
186
186
|
a,
|
|
187
187
|
l.id,
|
|
188
188
|
C
|
|
@@ -199,31 +199,31 @@ const at = (i) => {
|
|
|
199
199
|
label: T.title,
|
|
200
200
|
actionKey: T.actionKey,
|
|
201
201
|
data: {
|
|
202
|
-
groupId:
|
|
202
|
+
groupId: y ? y.id : l.id
|
|
203
203
|
}
|
|
204
204
|
});
|
|
205
205
|
}));
|
|
206
206
|
}
|
|
207
|
-
|
|
208
|
-
|
|
207
|
+
O.unshift(
|
|
208
|
+
K({
|
|
209
209
|
messageId: m,
|
|
210
|
-
message: [
|
|
210
|
+
message: [N, C],
|
|
211
211
|
group: l
|
|
212
212
|
})
|
|
213
213
|
);
|
|
214
214
|
}
|
|
215
|
-
return x &&
|
|
216
|
-
|
|
215
|
+
return x && O.unshift(
|
|
216
|
+
K({
|
|
217
217
|
messageId: m,
|
|
218
218
|
message: [A.HTML, { body: x }],
|
|
219
219
|
group: l
|
|
220
220
|
})
|
|
221
|
-
),
|
|
221
|
+
), O;
|
|
222
222
|
}
|
|
223
223
|
case "Text": {
|
|
224
|
-
const
|
|
225
|
-
if (
|
|
226
|
-
|
|
224
|
+
const p = [];
|
|
225
|
+
if (p.push(
|
|
226
|
+
K({
|
|
227
227
|
messageId: m,
|
|
228
228
|
message: [
|
|
229
229
|
A.HTML,
|
|
@@ -234,21 +234,21 @@ const at = (i) => {
|
|
|
234
234
|
), u.length) {
|
|
235
235
|
const x = u.find(
|
|
236
236
|
(C) => {
|
|
237
|
-
var
|
|
238
|
-
return C.type === "List" && ((
|
|
237
|
+
var N;
|
|
238
|
+
return C.type === "List" && ((N = C.localState) == null ? void 0 : N.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching";
|
|
239
239
|
}
|
|
240
|
-
),
|
|
240
|
+
), O = u.find(
|
|
241
241
|
(C) => C.tags.includes("contact") && C.type === "Contact"
|
|
242
242
|
);
|
|
243
|
-
if (
|
|
244
|
-
|
|
243
|
+
if (O && p.push(
|
|
244
|
+
K({
|
|
245
245
|
messageId: m,
|
|
246
246
|
message: [
|
|
247
247
|
$.ContactMethod,
|
|
248
248
|
{
|
|
249
|
-
contactMethodId:
|
|
249
|
+
contactMethodId: O.content.id,
|
|
250
250
|
groupId: l.id,
|
|
251
|
-
guideId:
|
|
251
|
+
guideId: O.content.guideId
|
|
252
252
|
}
|
|
253
253
|
],
|
|
254
254
|
group: l
|
|
@@ -259,8 +259,8 @@ const at = (i) => {
|
|
|
259
259
|
x,
|
|
260
260
|
l.id
|
|
261
261
|
);
|
|
262
|
-
|
|
263
|
-
|
|
262
|
+
p.push(
|
|
263
|
+
K({
|
|
264
264
|
messageId: m,
|
|
265
265
|
message: [
|
|
266
266
|
A.Separator,
|
|
@@ -268,8 +268,8 @@ const at = (i) => {
|
|
|
268
268
|
],
|
|
269
269
|
group: l
|
|
270
270
|
})
|
|
271
|
-
),
|
|
272
|
-
|
|
271
|
+
), p.push(
|
|
272
|
+
K({
|
|
273
273
|
messageId: m,
|
|
274
274
|
message: [$.ContactList, C],
|
|
275
275
|
group: l
|
|
@@ -277,11 +277,11 @@ const at = (i) => {
|
|
|
277
277
|
);
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
|
-
return
|
|
280
|
+
return p;
|
|
281
281
|
}
|
|
282
282
|
case "Contact":
|
|
283
283
|
return [
|
|
284
|
-
|
|
284
|
+
K({
|
|
285
285
|
messageId: m,
|
|
286
286
|
message: [
|
|
287
287
|
$.ContactMethod,
|
|
@@ -296,7 +296,7 @@ const at = (i) => {
|
|
|
296
296
|
];
|
|
297
297
|
case "Error":
|
|
298
298
|
return [
|
|
299
|
-
|
|
299
|
+
K({
|
|
300
300
|
messageId: m,
|
|
301
301
|
message: [
|
|
302
302
|
A.HTML,
|
|
@@ -310,13 +310,13 @@ const at = (i) => {
|
|
|
310
310
|
default:
|
|
311
311
|
return [];
|
|
312
312
|
}
|
|
313
|
-
},
|
|
313
|
+
}, b = /* @__PURE__ */ new Map([
|
|
314
314
|
["Text", 1],
|
|
315
315
|
["List", 2],
|
|
316
316
|
["Contact", 3]
|
|
317
317
|
]), f = [], k = e.sort((a, l) => {
|
|
318
|
-
const
|
|
319
|
-
return
|
|
318
|
+
const y = b.get(a.type) || 20, m = b.get(l.type) || 20;
|
|
319
|
+
return y - m;
|
|
320
320
|
}).filter((a) => !a.relation).reduce((a, l) => a.concat(l), []), P = (a) => typeof a.actions.selector < "u";
|
|
321
321
|
for (const a of k) {
|
|
322
322
|
const l = e.filter(
|
|
@@ -330,10 +330,10 @@ const at = (i) => {
|
|
|
330
330
|
};
|
|
331
331
|
class mt {
|
|
332
332
|
constructor(e, n, t, d) {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
333
|
+
M(this, "globalState");
|
|
334
|
+
M(this, "localState");
|
|
335
|
+
M(this, "clientId");
|
|
336
|
+
M(this, "entries");
|
|
337
337
|
this.endpoint = e, this.events = n, this.store = t, this.container = d, this.clientId = j(), this.entries = [];
|
|
338
338
|
}
|
|
339
339
|
async fetchGuide(e) {
|
|
@@ -375,9 +375,9 @@ class mt {
|
|
|
375
375
|
}
|
|
376
376
|
async handleResponse(e, n) {
|
|
377
377
|
this.entries = this.entries.concat(e.entries), this.store.write(this.entries, "entries");
|
|
378
|
-
const t = e.entries.find((
|
|
378
|
+
const t = e.entries.find((b) => b.type === "Widget");
|
|
379
379
|
return t && this.events.dispatch("provider:widget-entry", t.content), e.globalState && (this.globalState = e.globalState, this.store.write(e.globalState, "globalState")), this.localState = e.entries.reduce(
|
|
380
|
-
(
|
|
380
|
+
(b, f) => f.localState ? f.localState : b,
|
|
381
381
|
void 0
|
|
382
382
|
), this.store.write(this.localState, "localState"), await gt(
|
|
383
383
|
this.container,
|
|
@@ -430,21 +430,21 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
430
430
|
}, kt = async (i) => {
|
|
431
431
|
var J, U, D, R, z;
|
|
432
432
|
const e = "chub-plugin", n = i.get("$widget"), t = (z = (R = (D = (U = (J = n == null ? void 0 : n.container) == null ? void 0 : J.get("$settings")) == null ? void 0 : U.components) == null ? void 0 : D.conversation) == null ? void 0 : R.properties) == null ? void 0 : z.conversationalHubPluginSettings;
|
|
433
|
-
let d,
|
|
433
|
+
let d, b, f, k = (t == null ? void 0 : t.connectionAttempts) ?? 5, P, a, l;
|
|
434
434
|
V.info((H == null ? void 0 : H.name) + " version: " + (H == null ? void 0 : H.version)), q(
|
|
435
435
|
i,
|
|
436
436
|
$.ContactMethod,
|
|
437
|
-
import("./contact-method-
|
|
437
|
+
import("./contact-method-ee54b786.mjs")
|
|
438
438
|
), q(
|
|
439
439
|
i,
|
|
440
440
|
$.ContactList,
|
|
441
|
-
import("./contact-method-list-
|
|
441
|
+
import("./contact-method-list-0050453e.mjs")
|
|
442
442
|
);
|
|
443
443
|
const u = await Q(
|
|
444
444
|
i,
|
|
445
445
|
"conversational-hub-session",
|
|
446
446
|
X.Necessary
|
|
447
|
-
),
|
|
447
|
+
), y = (r, s) => {
|
|
448
448
|
const { knowledgeBotEndpoint: o } = s.properties();
|
|
449
449
|
if (o)
|
|
450
450
|
return `${o}/conversations`;
|
|
@@ -458,7 +458,7 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
458
458
|
const o = r.target;
|
|
459
459
|
if ((s = o.getAttribute("class")) != null && s.includes("dialog-option-cx")) {
|
|
460
460
|
const c = o.getAttribute("value");
|
|
461
|
-
|
|
461
|
+
N(c), d.user.print(
|
|
462
462
|
c.replace(/</g, "<").replace(/>/g, ">")
|
|
463
463
|
);
|
|
464
464
|
}
|
|
@@ -467,25 +467,25 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
467
467
|
(await nt.getInstance(
|
|
468
468
|
i
|
|
469
469
|
)).registerProvider(e, (r, s) => {
|
|
470
|
-
d = r,
|
|
470
|
+
d = r, b = d.controller, f = d.createAgent({
|
|
471
471
|
name: t == null ? void 0 : t.botName,
|
|
472
472
|
avatar: t == null ? void 0 : t.avatar
|
|
473
|
-
}), l =
|
|
473
|
+
}), l = y(i, s);
|
|
474
474
|
const { events: o } = i.get("$widget"), c = new st(i);
|
|
475
|
-
a = new mt(l, o, c, i),
|
|
476
|
-
const [
|
|
477
|
-
|
|
475
|
+
a = new mt(l, o, c, i), O();
|
|
476
|
+
const [h] = i.get("widgetDOMElements");
|
|
477
|
+
h.querySelectorAll(".humany-bot-contact-method").forEach((I) => {
|
|
478
478
|
var w;
|
|
479
479
|
(w = I.closest(".humany-conversation-entry")) == null || w.remove();
|
|
480
|
-
}),
|
|
481
|
-
const S = () =>
|
|
480
|
+
}), h.removeEventListener("click", m), h.addEventListener("click", m);
|
|
481
|
+
const S = () => b.providers.includes(e);
|
|
482
482
|
s.actions.create("submit", (I) => {
|
|
483
483
|
const { events: w } = i.get("$widget");
|
|
484
484
|
w.dispatch("conversational-hub-provider:form-submitted", I);
|
|
485
485
|
}), s.actions.watch("conversation.action", (I, w) => (S() && C(I), w(I))), s.actions.watch("conversation.user-submit", (I, w) => {
|
|
486
486
|
if (!S())
|
|
487
487
|
return w(I);
|
|
488
|
-
|
|
488
|
+
N(I.text), d.user.print(
|
|
489
489
|
I.text.replace(/</g, "<").replace(/>/g, ">")
|
|
490
490
|
);
|
|
491
491
|
}), n.events.subscribe(
|
|
@@ -504,7 +504,7 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
504
504
|
s.writer = f.print(o);
|
|
505
505
|
});
|
|
506
506
|
}
|
|
507
|
-
const
|
|
507
|
+
const p = sessionStorage.getItem(
|
|
508
508
|
`humany_${x(
|
|
509
509
|
n.implementation.tenant + n.implementation.name + n.name
|
|
510
510
|
)}`
|
|
@@ -519,7 +519,7 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
519
519
|
}
|
|
520
520
|
return s.toString();
|
|
521
521
|
}
|
|
522
|
-
async function
|
|
522
|
+
async function O(r = !0) {
|
|
523
523
|
const s = await W(
|
|
524
524
|
i,
|
|
525
525
|
"conversational-hub-session"
|
|
@@ -529,9 +529,9 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
529
529
|
else if (s != null && s.sessionId && r)
|
|
530
530
|
P = s == null ? void 0 : s.sessionId;
|
|
531
531
|
else if (t != null && t.welcomeMessage) {
|
|
532
|
-
if (!(
|
|
533
|
-
const
|
|
534
|
-
f.print(
|
|
532
|
+
if (!(p != null && p.length ? JSON.parse(p) : {})["conversation-conversation"]) {
|
|
533
|
+
const h = t.welcomeMessage.replaceAll("$lt;", "<").replaceAll("$gt;", ">");
|
|
534
|
+
f.print(h);
|
|
535
535
|
}
|
|
536
536
|
} else {
|
|
537
537
|
const c = {
|
|
@@ -557,7 +557,7 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
557
557
|
`{"type":"button_click","language":"${t.language}","content":{"button_text":"${r.label}","value":"${r.actionKey}"}}`
|
|
558
558
|
);
|
|
559
559
|
}
|
|
560
|
-
async function
|
|
560
|
+
async function N(r) {
|
|
561
561
|
const s = { text: r };
|
|
562
562
|
if (!P) {
|
|
563
563
|
const o = {
|
|
@@ -584,23 +584,23 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
584
584
|
async function L(r, s, o = !0) {
|
|
585
585
|
var I, w, B, F;
|
|
586
586
|
const c = d.loading();
|
|
587
|
-
let
|
|
587
|
+
let h, S;
|
|
588
588
|
try {
|
|
589
|
-
|
|
589
|
+
h = await fetch(r, {
|
|
590
590
|
method: "POST",
|
|
591
591
|
body: s
|
|
592
|
-
}), S = await (
|
|
592
|
+
}), S = await (h == null ? void 0 : h.json());
|
|
593
593
|
} catch (_) {
|
|
594
594
|
_ instanceof SyntaxError ? V.error("Incorrect JSON format.", _) : V.error("Network error: check connection or baseUrl.", _), c(), f.print(t.errorMessage || "An error occurred");
|
|
595
595
|
return;
|
|
596
596
|
}
|
|
597
|
-
if (!(
|
|
598
|
-
if (V.error(`HTTP ${
|
|
597
|
+
if (!(h != null && h.ok)) {
|
|
598
|
+
if (V.error(`HTTP ${h == null ? void 0 : h.status}.`, JSON.stringify(S)), c(), !!((I = S == null ? void 0 : S.errors) != null && I.filter(
|
|
599
599
|
(E) => E.code === "1003"
|
|
600
600
|
).length) && k > 0) {
|
|
601
|
-
k--, await new Promise((Z) => setTimeout(Z, 500)), await
|
|
601
|
+
k--, await new Promise((Z) => setTimeout(Z, 500)), await O(!1);
|
|
602
602
|
const E = JSON.parse(s);
|
|
603
|
-
(w = E == null ? void 0 : E.content) != null && w.text ? await
|
|
603
|
+
(w = E == null ? void 0 : E.content) != null && w.text ? await N(E.content.text) : (B = E == null ? void 0 : E.content) != null && B.action && await C((F = E == null ? void 0 : E.content) == null ? void 0 : F.action);
|
|
604
604
|
} else
|
|
605
605
|
f.print(t.errorMessage || "An error occurred");
|
|
606
606
|
return;
|
|
@@ -608,8 +608,8 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
608
608
|
c(), k = (t == null ? void 0 : t.connectionAttempts) ?? 5, S != null && S.action_payload && T(S.action_payload), P = S == null ? void 0 : S.session_id, u({ sessionId: P }), o && Y(S);
|
|
609
609
|
}
|
|
610
610
|
async function T(r) {
|
|
611
|
-
var
|
|
612
|
-
const s = (
|
|
611
|
+
var h;
|
|
612
|
+
const s = (h = r == null ? void 0 : r.transfer_parameters) == null ? void 0 : h.contactGuide, o = d.loading(), c = await a.fetchGuide(parseInt(s));
|
|
613
613
|
o(), c && g(c);
|
|
614
614
|
}
|
|
615
615
|
function Y(r) {
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-0d0a5fc2.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");require("@telia-ace/widget-utilities");require("@telia-ace/widget-forms");require("@webprovisions/platform");exports.ConversationalHubPlugin=e.ConversationalHubPlugin;exports.dialogflowConfigurationApi=e.dialogflowConfigurationApi;
|
package/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/conversational-hub-bot-provider",
|
|
3
|
-
"version": "1.3.19
|
|
3
|
+
"version": "1.3.19",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@telia-ace/widget-conversation": "^1.3.19
|
|
13
|
+
"@telia-ace/widget-conversation": "^1.3.19",
|
|
14
14
|
"@webprovisions/platform": "^1.1.4",
|
|
15
|
-
"@telia-ace/knowledge-widget-core": "^1.3.19
|
|
16
|
-
"@telia-ace/widget-utilities": "^1.3.19
|
|
17
|
-
"@telia-ace/widget-services": "^1.3.19
|
|
18
|
-
"@telia-ace/widget-core": "^1.3.19
|
|
19
|
-
"@telia-ace/knowledge-data-client": "^1.3.19
|
|
20
|
-
"@telia-ace/knowledge-widget-adapters": "^1.3.19
|
|
21
|
-
"@telia-ace/knowledge-widget-ui": "^1.3.19
|
|
22
|
-
"@telia-ace/widget-forms": "^1.3.19
|
|
15
|
+
"@telia-ace/knowledge-widget-core": "^1.3.19",
|
|
16
|
+
"@telia-ace/widget-utilities": "^1.3.19",
|
|
17
|
+
"@telia-ace/widget-services": "^1.3.19",
|
|
18
|
+
"@telia-ace/widget-core": "^1.3.19",
|
|
19
|
+
"@telia-ace/knowledge-data-client": "^1.3.19",
|
|
20
|
+
"@telia-ace/knowledge-widget-adapters": "^1.3.19",
|
|
21
|
+
"@telia-ace/knowledge-widget-ui": "^1.3.19",
|
|
22
|
+
"@telia-ace/widget-forms": "^1.3.19"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@emotion/react": "11.11.1",
|
package/index-0962774e.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var X=Object.defineProperty;var Y=(i,e,n)=>e in i?X(i,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[e]=n;var O=(i,e,n)=>(Y(i,typeof e!="symbol"?e+"":e,n),n);const T=require("@telia-ace/widget-conversation"),j=require("@telia-ace/widget-services"),N=require("@telia-ace/widget-utilities"),F=require("@telia-ace/widget-forms"),Z=require("@webprovisions/platform");class tt{constructor(e){O(this,"enabled",!0);O(this,"botProviderGlobalStateKey","bot-provider-global-state");O(this,"botProviderLocalStateKey","bot-provider-local-state");O(this,"botProviderEntriesKey","bot-provider-entries");O(this,"botProviderMetaStateKey","bot-provider-conversation-meta");this.container=e}getKey(e){let n;switch(e){case"localState":n=this.botProviderLocalStateKey;break;case"globalState":n=this.botProviderGlobalStateKey;break;case"entries":n=this.botProviderEntriesKey;break;case"meta":n=this.botProviderMetaStateKey;break}return n}async read(e){const n=this.getKey(e);if(!(!this.enabled||!n))return j.readStorage(this.container,n)}async write(e,n){const t=this.getKey(n);if(!this.enabled||!t)return;(await j.createStorageWriter(this.container,t,j.StorageCategory.Necessary))(e)}}var $=(i=>(i.ContactMethod="ace-conversational-hub-contact-method",i.ContactList="ace-conversational-hub-contact-list",i))($||{});const et=i=>{if(i){const{type:e,content:n}=i;if(e&&n)return{type:e,content:n}}},nt=({isUser:i,items:e=[],meta:n={}})=>{const t=N.uuid();return{id:t,isUser:i,items:e.map(p=>({id:p.id||N.uuid(),isUser:i,groupId:t,message:p.message||[]})),meta:n}},it=({id:i,title:e,defaultIcon:n,exits:[t],exitType:d,confirmationText:p,expandFormAutomatically:f,form:M,description:P},a={})=>{const{adapter:l}=t||{Adapter:{}},{clientName:u="",settings:y={},customClientName:m=""}=l,{validation:b}=a,g={id:i.toString(),title:e,description:P,symbol:et(n),clientName:u==="custom.adapter"?m:u,expanded:!0,inline:!0,body:{}};if(u.indexOf("phone")>-1||u.indexOf("freetext")>-1){const{displayTextBeforeClick:h,textBeforeClick:L}=y;h==="true"&&(g.expanded=!1,g.title=L),u.indexOf("phone.text")>-1?g.body.phoneNumber=y.phoneNumber:g.body.freetext=y.freetext}return(u.indexOf("chat.popup")>-1||u.indexOf("link")>-1||u==="custom.adapter"&&d==="custom")&&(g.body=y,g.body.confirmationFallback=p),u.indexOf("ace")>-1&&(g.body=y),M&&M.hasValueComponents&&(b?g.body.form=F.FormBuilder.fromLegacyForm(i.toString(),M,b).get():g.body.form=F.FormBuilder.fromLegacyForm(i.toString(),M).get(),f||(g.expanded=g.inline=!1),g.body=z(g,{submit:"Submit"})),a.guideId&&(g.body.guideId=a.guideId),g},ot=i=>{const{localState:e}=i;return i.tags.includes("category")&&i.tags.includes("contact")?T.ConversationMessageListItemType.ItemList:i.tags.includes("suggestion")?T.ConversationMessageListItemType.LinkList:(e==null?void 0:e.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"?$.ContactList:T.ConversationMessageListItemType.ButtonList},z=(i,{submit:e,errors:n,meta:t})=>{var d;if((d=i==null?void 0:i.body)!=null&&d.form){const{body:p}=i,f=new F.FormBuilder(p.form);return p.form.layout.submit||f.createComponent(F.submitButton(e,"submit")),n&&f.setValidationErrors(n),t&&f.setMeta(t),{...p,form:f.get()}}return(i==null?void 0:i.body)||{}},st=async(i,e,n)=>{(await(await i.getAsync("dataClient")).getClient()).parameters.set(e,n)},A=({messageId:i,message:e,group:n})=>({id:i,message:e,groupId:n.id,isUser:n.isUser}),at=async(i,e,n)=>{const t=(a,l,u,y={actions:[],entryId:l.id,groupId:u})=>{const m=[];return y.actions=l.content.items.map(b=>{var h;const g={label:b.title,actionKey:b.actionKey,symbol:b.symbol?b.symbol:void 0,description:b.description||void 0};if(b.data){const L=l.actions[b.actionKey];a===$.ContactList?(m.push(b.data.id),g.data=it(b.data,{guideId:(h=L==null?void 0:L.guideId)==null?void 0:h.toString()})):g.data=b.data}return g}),a===$.ContactList&&(y.contactMethodIds=m),y},d=async(a,l,u=[],y)=>{var b,g;const m=N.uuid();switch(a.type!=="List"&&a.tags.includes("guide")&&((g=(b=a.content.hints)==null?void 0:b[0])!=null&&g.id)&&await st(i,"LastGuideId",a.content.hints[0].id),a.type){case"List":{if(!a.content)return[];const{items:h,html:L}=a.content,k=[];let C={actions:[],entryId:a.id,groupId:l.id};if((h==null?void 0:h.length)>0){const K=ot(a);if(C=t(K,a,l.id,C),u.length){const x=u.find(H=>H.tags.includes("paging"));x!=null&&x.content&&(l.meta.paging={actions:x.actions,items:x.content.items,localState:x.localState},x.content.items.forEach(H=>{C.actions.push({label:H.title,actionKey:H.actionKey,data:{groupId:y?y.id:l.id}})}))}k.unshift(A({messageId:m,message:[K,C],group:l}))}return L&&k.unshift(A({messageId:m,message:[T.ConversationMessageListItemType.HTML,{body:L}],group:l})),k}case"Text":{const h=[];if(h.push(A({messageId:m,message:[T.ConversationMessageListItemType.HTML,{body:a.content.html}],group:l})),u.length){const L=u.find(C=>{var K;return C.type==="List"&&((K=C.localState)==null?void 0:K.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"}),k=u.find(C=>C.tags.includes("contact")&&C.type==="Contact");if(k&&h.push(A({messageId:m,message:[$.ContactMethod,{contactMethodId:k.content.id,groupId:l.id,guideId:k.content.guideId}],group:l})),L){const C=t($.ContactList,L,l.id);h.push(A({messageId:m,message:[T.ConversationMessageListItemType.Separator,void 0],group:l})),h.push(A({messageId:m,message:[$.ContactList,C],group:l}))}}return h}case"Contact":return[A({messageId:m,message:[$.ContactMethod,{contactMethodId:a.content.id,groupId:l.id,guideId:a.content.guideId}],group:l})];case"Error":return[A({messageId:m,message:[T.ConversationMessageListItemType.HTML,{body:a.content.message||"Something went wrong."}],group:l})];default:return[]}},p=new Map([["Text",1],["List",2],["Contact",3]]),f=[],M=e.sort((a,l)=>{const y=p.get(a.type)||20,m=p.get(l.type)||20;return y-m}).filter(a=>!a.relation).reduce((a,l)=>a.concat(l),[]),P=a=>typeof a.actions.selector<"u";for(const a of M){const l=e.filter(m=>m.relation===a.id&&!P(m)),u=nt({isUser:!1});(await d(a,u,l,n)).forEach(m=>{u.items.push(m)}),u.items.length&&f.push(u)}return f};class rt{constructor(e,n,t,d){O(this,"globalState");O(this,"localState");O(this,"clientId");O(this,"entries");this.endpoint=e,this.events=n,this.store=t,this.container=d,this.clientId=N.uuid(),this.entries=[]}async fetchGuide(e){const n={command:{guide:{id:e}},globalState:this.globalState,clientId:this.clientId};return await this.postEnvelope(n)}async postEnvelope(e,n){try{const t=await fetch(this.endpoint,this.getHttpOptions(e));if(!t.ok)throw t;const d=await t.json();return this.handleResponse(d,n)}catch(t){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let d="Something went wrong";return(t.message==="Failed to fetch"||t.message==="NetworkError when attempting to fetch resource.")&&(d="Lost connection... Please try again."),this.events.dispatch("tracking:http-client-error",{message:d,error:t}),this.handleResponse({entries:[{id:N.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:d},actions:{},tags:[]}]})}}async handleResponse(e,n){this.entries=this.entries.concat(e.entries),this.store.write(this.entries,"entries");const t=e.entries.find(p=>p.type==="Widget");return t&&this.events.dispatch("provider:widget-entry",t.content),e.globalState&&(this.globalState=e.globalState,this.store.write(e.globalState,"globalState")),this.localState=e.entries.reduce((p,f)=>f.localState?f.localState:p,void 0),this.store.write(this.localState,"localState"),await at(this.container,e.entries,n)}getHttpOptions(e){const n={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"}};return e.funnel=this.container.get("$widget").name,e.localState=e.localState||this.localState,Object.assign({},n,{body:JSON.stringify(e),credentials:"same-origin"})}}const ct="@telia-ace/conversational-hub-bot-provider",lt="0.0.16",dt="./index.js",ut="./index.d.ts",gt={".":{import:"./index.mjs",require:"./index.js"}},mt={"@telia-ace/widget-conversation":"*","@webprovisions/platform":"^1.1.4","@telia-ace/knowledge-widget-core":"*","@telia-ace/widget-utilities":"*","@telia-ace/widget-services":"*","@telia-ace/widget-core":"*","@telia-ace/knowledge-data-client":"*","@telia-ace/knowledge-widget-adapters":"*","@telia-ace/knowledge-widget-ui":"*","@telia-ace/widget-forms":"*"},ft={"@emotion/react":"11.11.1","@emotion/styled":"11.11.0",react:"18.2.0"},B={name:ct,version:lt,main:dt,types:ut,exports:gt,dependencies:mt,peerDependencies:ft},pt=async i=>{var V,G,U,J,D;const e="chub-plugin",n=i.get("$widget"),t=(D=(J=(U=(G=(V=n==null?void 0:n.container)==null?void 0:V.get("$settings"))==null?void 0:G.components)==null?void 0:U.conversation)==null?void 0:J.properties)==null?void 0:D.conversationalHubPluginSettings;let d,p,f,M=(t==null?void 0:t.connectionAttempts)??5,P,a,l;N.Logger.info((B==null?void 0:B.name)+" version: "+(B==null?void 0:B.version)),T.registerCustomMessageComponent(i,$.ContactMethod,Promise.resolve().then(()=>require("./contact-method-881cb6d7.js"))),T.registerCustomMessageComponent(i,$.ContactList,Promise.resolve().then(()=>require("./contact-method-list-2cdf2193.js")));const u=await j.createStorageWriter(i,"conversational-hub-session",j.StorageCategory.Necessary),y=(r,s)=>{const{knowledgeBotEndpoint:o}=s.properties();if(o)return`${o}/conversations`;const{data:c}=r.get("$settings");if(!c||!c.projection)throw new Error("Missing Knowledge Bot endpoint");return`${c.projection}/conversations`},m=r=>{var s;if(r.target instanceof HTMLButtonElement){const o=r.target;if((s=o.getAttribute("class"))!=null&&s.includes("dialog-option-cx")){const c=o.getAttribute("value");K(c),d.user.print(c.replace(/</g,"<").replace(/>/g,">"))}}};(await T.ConversationPlatform.getInstance(i)).registerProvider(e,(r,s)=>{d=r,p=d.controller,f=d.createAgent({name:t==null?void 0:t.botName,avatar:t==null?void 0:t.avatar}),l=y(i,s);const{events:o}=i.get("$widget"),c=new tt(i);a=new rt(l,o,c,i),k();const[v]=i.get("widgetDOMElements");v.querySelectorAll(".humany-bot-contact-method").forEach(I=>{var w;(w=I.closest(".humany-conversation-entry"))==null||w.remove()}),v.removeEventListener("click",m),v.addEventListener("click",m);const S=()=>p.providers.includes(e);s.actions.create("submit",I=>{const{events:w}=i.get("$widget");w.dispatch("conversational-hub-provider:form-submitted",I)}),s.actions.watch("conversation.action",(I,w)=>(S()&&C(I),w(I))),s.actions.watch("conversation.user-submit",(I,w)=>{if(!S())return w(I);K(I.text),d.user.print(I.text.replace(/</g,"<").replace(/>/g,">"))}),n.events.subscribe("conversational-hub-provider:fetch-guide",async(I,w)=>{if(!(w!=null&&w.guideId))return;const _=await a.fetchGuide(parseInt(w.guideId));_&&g(_)})});async function g(r){r.forEach(s=>{const o=s.items.map(c=>c.message);s.writer=f.print(o)})}const h=sessionStorage.getItem(`humany_${L(n.implementation.tenant+n.implementation.name+n.name)}`);function L(r){let s=0;if(r.length===0)return s.toString();for(let o=0;o<r.length;o++){const c=r.charCodeAt(o);s=(s<<5)-s+c,s=s&s}return s.toString()}async function k(r=!0){const s=await j.readStorage(i,"conversational-hub-session"),o=i.get("dialogflowSettings");if(o!=null&&o.silentStart)delete o.silentStart,n.events.dispatch("conversational-hub-provider:started",{});else if(s!=null&&s.sessionId&&r)P=s==null?void 0:s.sessionId;else if(t!=null&&t.welcomeMessage){if(!(h!=null&&h.length)){const c=t.welcomeMessage.replaceAll("$lt;","<").replaceAll("$gt;",">");f.print(c)}}else{const c={extension:t.extension};o!=null&&o.initCommand&&(c.input={type:"event",language:t.language,content:{name:o.initCommand,parameters:o.initParameters||{}}}),await x(t.baseUrl+"/initialize",JSON.stringify(c),r)}}async function C(r){await x(`${t.baseUrl}/input/${P}`,`{"type":"button_click","language":"${t.language}","content":{"button_text":"${r.label}","value":"${r.actionKey}"}}`)}async function K(r){const s={text:r};if(!P){const o={extension:t.extension},c=i.get("dialogflowSettings");c!=null&&c.initCommand&&(o.input={type:"event",language:t.language,content:{name:c.initCommand,parameters:c.initParameters||{}}}),await x(t.baseUrl+"/initialize",JSON.stringify(o),!1)}await x(`${t.baseUrl}/input/${P}`,`{"type":"text","language":"${t.language}","content":${JSON.stringify(s)}}`)}async function x(r,s,o=!0){var I,w,_,R;const c=d.loading();let v,S;try{v=await fetch(r,{method:"POST",body:s}),S=await(v==null?void 0:v.json())}catch(q){q instanceof SyntaxError?N.Logger.error("Incorrect JSON format.",q):N.Logger.error("Network error: check connection or baseUrl.",q),c(),f.print(t.errorMessage||"An error occurred");return}if(!(v!=null&&v.ok)){if(N.Logger.error(`HTTP ${v==null?void 0:v.status}.`,JSON.stringify(S)),c(),!!((I=S==null?void 0:S.errors)!=null&&I.filter(E=>E.code==="1003").length)&&M>0){M--,await new Promise(Q=>setTimeout(Q,500)),await k(!1);const E=JSON.parse(s);(w=E==null?void 0:E.content)!=null&&w.text?await K(E.content.text):(_=E==null?void 0:E.content)!=null&&_.action&&await C((R=E==null?void 0:E.content)==null?void 0:R.action)}else f.print(t.errorMessage||"An error occurred");return}c(),M=(t==null?void 0:t.connectionAttempts)??5,S!=null&&S.action_payload&&H(S.action_payload),P=S==null?void 0:S.session_id,u({sessionId:P}),o&&W(S)}async function H(r){var v;const s=(v=r==null?void 0:r.transfer_parameters)==null?void 0:v.contactGuide,o=d.loading(),c=await a.fetchGuide(parseInt(s));o(),c&&g(c)}function W(r){var s;r==null||r.agent_response.forEach(o=>{f.print(o.payload.text)}),(s=r==null?void 0:r.prompt)!=null&&s.items&&f.print(["button-list",{actions:r.prompt.items.map(o=>{let c;return o.type==="button"&&(c={actionKey:o.value,label:o.text}),o.type==="link"&&(c={actionKey:o.value,label:o.text,data:{href:o.url,target:(t==null?void 0:t.linkTarget)??"_blank"}}),c})}])}},ht=Z.createConfigurationApi(i=>{i.createCommand("dialogflow",e=>n=>{const t={initCommand:n.initCommand};n.initParameters&&(t.initParameters=n.initParameters),n.silentStart&&(t.silentStart=n.silentStart),e.container.register("dialogflowSettings",t)})});exports.ConversationalHubPlugin=pt;exports.dialogflowConfigurationApi=ht;exports.updateForm=z;
|