@telia-ace/conversational-hub-bot-provider 1.2.8 → 1.2.9
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-800cf649.js → contact-method-4dee0547.js} +1 -1
- package/{contact-method-d1bf5b87.mjs → contact-method-85ab7950.mjs} +1 -1
- package/{index-25ab09c8.mjs → index-30daa259.mjs} +2 -2
- package/{index-21624a6d.js → index-f502b1d3.js} +1 -1
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react/jsx-runtime"),A=require("@emotion/styled"),F=require("@telia-ace/knowledge-data-client"),R=require("@telia-ace/knowledge-widget-adapters"),p=require("@telia-ace/knowledge-widget-ui"),T=require("@telia-ace/widget-forms"),$=require("@telia-ace/widget-utilities"),c=require("react"),k=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react/jsx-runtime"),A=require("@emotion/styled"),F=require("@telia-ace/knowledge-data-client"),R=require("@telia-ace/knowledge-widget-adapters"),p=require("@telia-ace/knowledge-widget-ui"),T=require("@telia-ace/widget-forms"),$=require("@telia-ace/widget-utilities"),c=require("react"),k=require("./index-f502b1d3.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");const z=({contactMethodId:n,guideId:o,groupId:m,className:x})=>{var C,v,w;const[e,s]=c.useState(),d=p.useContainer(),D=p.useDispatch(),b=c.useRef(!0),l=p.useConversation();c.useEffect(()=>{const{events:u}=d.get("$widget"),q=u.subscribe("conversational-hub-provider:form-submitted",async(f,r)=>{var M;if(((M=r.form.meta)==null?void 0:M.groupId)!==m||r.id!==(e==null?void 0:e.id))return;l&&(r.form.meta||(r.form.meta={}),r.form.meta.conversation=l);const y=await d.getAsync("contactMethods"),t={...e,body:{...e.body,form:r.form}},{errors:i,valid:h,errorTypes:N}=await y.validate(t);if(!h){const S=new T.FormBuilder(e.body.form);s(void 0),S.setValidationErrors(i),t.body={...t.body,form:S.get()},s({...t});return}const E=await y.submit(t);t.confirmation=E,s(t)}),a=u.subscribe("bot-provider:evaluate",async(f,r)=>{if(r.id!==n)return;const t=await(await d.getAsync("contactMethods")).evaluate(e);let i={...e,body:{...e.body,form:t}};const h=k.updateForm(i,{submit:"Submit",errors:{},meta:{groupId:m}});i={...i,body:h},s(i)});return()=>{q(),a()}},[d,e,s,l]);const g=c.useCallback(async u=>{const a=await(await F.DataClient.getInstance(d)).fetch(F.DataType.ContactMethod,{contactMethodId:u,guideId:o},{noCache:!0}),f=k.updateForm(a,{submit:"Submit",errors:{},meta:{groupId:m}});if(a.body=f,a.body.guideId=o,!b.current)return null;s(a)},[b]);return c.useEffect(()=>(g(n),()=>{b.current=!1}),[n,g]),e?j.jsx(B,{...e,body:{...e.body,form:e.body.form?{...e.body.form,data:(C=e.body.form)==null?void 0:C.data,layout:{...e.body.form.layout},meta:(v=e.body.form)==null?void 0:v.meta,schema:(w=e.body.form)==null?void 0:w.schema}:void 0,guideId:e.body.guideId},inline:!0,expanded:!0,dispatch:D,className:$.appendClassNames("humany-bot-contact-method",x)}):null},B=A(R.ContactMethod)`
|
|
2
2
|
padding: ${n=>{var o;return(o=n.theme.sizes)==null?void 0:o.normal}} ${n=>{var o;return(o=n.theme.sizes)==null?void 0:o.medium}};
|
|
3
3
|
`;exports.default=z;
|
|
@@ -6,7 +6,7 @@ import { useContainer as R, useDispatch as T, useConversation as _ } from "@teli
|
|
|
6
6
|
import { FormBuilder as j } from "@telia-ace/widget-forms";
|
|
7
7
|
import { appendClassNames as k } from "@telia-ace/widget-utilities";
|
|
8
8
|
import { useState as G, useRef as I, useEffect as S, useCallback as V } from "react";
|
|
9
|
-
import { u as $ } from "./index-
|
|
9
|
+
import { u as $ } from "./index-30daa259.mjs";
|
|
10
10
|
import "@telia-ace/widget-conversation";
|
|
11
11
|
import "@telia-ace/widget-services";
|
|
12
12
|
const tt = ({
|
|
@@ -257,7 +257,7 @@ class it {
|
|
|
257
257
|
});
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
-
const st = "@telia-ace/conversational-hub-bot-provider", rt = "
|
|
260
|
+
const st = "@telia-ace/conversational-hub-bot-provider", rt = "1.2.9", at = "./index.js", ct = "./index.d.ts", lt = {
|
|
261
261
|
".": {
|
|
262
262
|
import: "./index.mjs",
|
|
263
263
|
require: "./index.js"
|
|
@@ -292,7 +292,7 @@ const st = "@telia-ace/conversational-hub-bot-provider", rt = "0.0.16", at = "./
|
|
|
292
292
|
O.info((C == null ? void 0 : C.name) + " version: " + (C == null ? void 0 : C.version)), Q(
|
|
293
293
|
o,
|
|
294
294
|
A.ContactMethod,
|
|
295
|
-
import("./contact-method-
|
|
295
|
+
import("./contact-method-85ab7950.mjs")
|
|
296
296
|
);
|
|
297
297
|
const x = await R(
|
|
298
298
|
o,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var D=Object.defineProperty;var F=(i,t,n)=>t in i?D(i,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[t]=n;var b=(i,t,n)=>(F(i,typeof t!="symbol"?t+"":t,n),n);const T=require("@telia-ace/widget-conversation"),x=require("@telia-ace/widget-services"),S=require("@telia-ace/widget-utilities"),B=require("@telia-ace/widget-forms");class W{constructor(t){b(this,"enabled",!0);b(this,"botProviderGlobalStateKey","bot-provider-global-state");b(this,"botProviderLocalStateKey","bot-provider-local-state");b(this,"botProviderEntriesKey","bot-provider-entries");b(this,"botProviderMetaStateKey","bot-provider-conversation-meta");this.container=t}getKey(t){let n;switch(t){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(t){const n=this.getKey(t);if(!(!this.enabled||!n))return x.readStorage(this.container,n)}async write(t,n){const e=this.getKey(n);if(!this.enabled||!e)return;(await x.createStorageWriter(this.container,e,x.StorageCategory.Necessary))(t)}}var M=(i=>(i.ContactMethod="ace-conversational-hub-contact-method",i))(M||{});const z=({isUser:i,items:t=[],meta:n={}})=>{const e=S.uuid();return{id:e,isUser:i,items:t.map(d=>({id:d.id||S.uuid(),isUser:i,groupId:e,message:d.message||[]})),meta:n}},Q=(i,{submit:t,errors:n,meta:e})=>{var a;if((a=i==null?void 0:i.body)!=null&&a.form){const{body:d}=i,g=new B.FormBuilder(d.form);return d.form.layout.submit||g.createComponent(B.submitButton(t,"submit")),n&&g.setValidationErrors(n),e&&g.setMeta(e),{...d,form:g.get()}}return(i==null?void 0:i.body)||{}},X=async(i,t,n)=>{(await(await i.getAsync("dataClient")).getClient()).parameters.set(t,n)},O=({messageId:i,message:t,group:n})=>({id:i,message:t,groupId:n.id,isUser:n.isUser}),Y=async(i,t,n)=>{const e=async(o,h,f=[],$)=>{var A,k;const m=S.uuid();switch(o.type!=="List"&&o.tags.includes("guide")&&((k=(A=o.content.hints)==null?void 0:A[0])!=null&&k.id)&&await X(i,"LastGuideId",o.content.hints[0].id),o.type){case"Text":{const C=[];if(C.push(O({messageId:m,message:[T.ConversationMessageListItemType.HTML,{body:o.content.html}],group:h})),f.length){f.find(y=>{var K;return y.type==="List"&&((K=y.localState)==null?void 0:K.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"});const I=f.find(y=>y.tags.includes("contact")&&y.type==="Contact");I&&C.push(O({messageId:m,message:[M.ContactMethod,{contactMethodId:I.content.id,groupId:h.id,guideId:I.content.guideId}],group:h}))}return C}case"Contact":return[O({messageId:m,message:[M.ContactMethod,{contactMethodId:o.content.id,groupId:h.id,guideId:o.content.guideId}],group:h})];case"Error":return[O({messageId:m,message:[T.ConversationMessageListItemType.HTML,{body:o.content.message||"Something went wrong."}],group:h})];default:return[]}},a=new Map([["Text",1],["Contact",2]]),d=[],g=t.sort((o,h)=>{const $=a.get(o.type)||20,m=a.get(h.type)||20;return $-m}).filter(o=>!o.relation).reduce((o,h)=>o.concat(h),[]),P=o=>typeof o.actions.selector<"u";for(const o of g){const h=t.filter(m=>m.relation===o.id&&!P(m)),f=z({isUser:!1});(await e(o,f,h)).forEach(m=>{f.items.push(m)}),f.items.length&&d.push(f)}return d};class Z{constructor(t,n,e,a){b(this,"globalState");b(this,"localState");b(this,"clientId");b(this,"entries");this.endpoint=t,this.events=n,this.store=e,this.container=a,this.clientId=S.uuid(),this.entries=[]}async fetchGuide(t){const n={command:{guide:{id:t}},globalState:this.globalState,clientId:this.clientId};return await this.postEnvelope(n)}async postEnvelope(t,n){try{const e=await fetch(this.endpoint,this.getHttpOptions(t));if(!e.ok)throw e;const a=await e.json();return this.handleResponse(a,n)}catch(e){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let a="Something went wrong";return(e.message==="Failed to fetch"||e.message==="NetworkError when attempting to fetch resource.")&&(a="Lost connection... Please try again."),this.handleResponse({entries:[{id:S.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:a},actions:{},tags:[]}]})}}async handleResponse(t,n){this.entries=this.entries.concat(t.entries),this.store.write(this.entries,"entries");const e=t.entries.find(d=>d.type==="Widget");return e&&this.events.dispatch("provider:widget-entry",e.content),t.globalState&&(this.globalState=t.globalState,this.store.write(t.globalState,"globalState")),this.localState=t.entries.reduce((d,g)=>g.localState?g.localState:d,void 0),this.store.write(this.localState,"localState"),await Y(this.container,t.entries)}getHttpOptions(t){const n={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"}};return t.funnel=this.container.get("$widget").name,t.localState=t.localState||this.localState,Object.assign({},n,{body:JSON.stringify(t),credentials:"same-origin"})}}const tt="@telia-ace/conversational-hub-bot-provider",et="
|
|
1
|
+
"use strict";var D=Object.defineProperty;var F=(i,t,n)=>t in i?D(i,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[t]=n;var b=(i,t,n)=>(F(i,typeof t!="symbol"?t+"":t,n),n);const T=require("@telia-ace/widget-conversation"),x=require("@telia-ace/widget-services"),S=require("@telia-ace/widget-utilities"),B=require("@telia-ace/widget-forms");class W{constructor(t){b(this,"enabled",!0);b(this,"botProviderGlobalStateKey","bot-provider-global-state");b(this,"botProviderLocalStateKey","bot-provider-local-state");b(this,"botProviderEntriesKey","bot-provider-entries");b(this,"botProviderMetaStateKey","bot-provider-conversation-meta");this.container=t}getKey(t){let n;switch(t){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(t){const n=this.getKey(t);if(!(!this.enabled||!n))return x.readStorage(this.container,n)}async write(t,n){const e=this.getKey(n);if(!this.enabled||!e)return;(await x.createStorageWriter(this.container,e,x.StorageCategory.Necessary))(t)}}var M=(i=>(i.ContactMethod="ace-conversational-hub-contact-method",i))(M||{});const z=({isUser:i,items:t=[],meta:n={}})=>{const e=S.uuid();return{id:e,isUser:i,items:t.map(d=>({id:d.id||S.uuid(),isUser:i,groupId:e,message:d.message||[]})),meta:n}},Q=(i,{submit:t,errors:n,meta:e})=>{var a;if((a=i==null?void 0:i.body)!=null&&a.form){const{body:d}=i,g=new B.FormBuilder(d.form);return d.form.layout.submit||g.createComponent(B.submitButton(t,"submit")),n&&g.setValidationErrors(n),e&&g.setMeta(e),{...d,form:g.get()}}return(i==null?void 0:i.body)||{}},X=async(i,t,n)=>{(await(await i.getAsync("dataClient")).getClient()).parameters.set(t,n)},O=({messageId:i,message:t,group:n})=>({id:i,message:t,groupId:n.id,isUser:n.isUser}),Y=async(i,t,n)=>{const e=async(o,h,f=[],$)=>{var A,k;const m=S.uuid();switch(o.type!=="List"&&o.tags.includes("guide")&&((k=(A=o.content.hints)==null?void 0:A[0])!=null&&k.id)&&await X(i,"LastGuideId",o.content.hints[0].id),o.type){case"Text":{const C=[];if(C.push(O({messageId:m,message:[T.ConversationMessageListItemType.HTML,{body:o.content.html}],group:h})),f.length){f.find(y=>{var K;return y.type==="List"&&((K=y.localState)==null?void 0:K.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"});const I=f.find(y=>y.tags.includes("contact")&&y.type==="Contact");I&&C.push(O({messageId:m,message:[M.ContactMethod,{contactMethodId:I.content.id,groupId:h.id,guideId:I.content.guideId}],group:h}))}return C}case"Contact":return[O({messageId:m,message:[M.ContactMethod,{contactMethodId:o.content.id,groupId:h.id,guideId:o.content.guideId}],group:h})];case"Error":return[O({messageId:m,message:[T.ConversationMessageListItemType.HTML,{body:o.content.message||"Something went wrong."}],group:h})];default:return[]}},a=new Map([["Text",1],["Contact",2]]),d=[],g=t.sort((o,h)=>{const $=a.get(o.type)||20,m=a.get(h.type)||20;return $-m}).filter(o=>!o.relation).reduce((o,h)=>o.concat(h),[]),P=o=>typeof o.actions.selector<"u";for(const o of g){const h=t.filter(m=>m.relation===o.id&&!P(m)),f=z({isUser:!1});(await e(o,f,h)).forEach(m=>{f.items.push(m)}),f.items.length&&d.push(f)}return d};class Z{constructor(t,n,e,a){b(this,"globalState");b(this,"localState");b(this,"clientId");b(this,"entries");this.endpoint=t,this.events=n,this.store=e,this.container=a,this.clientId=S.uuid(),this.entries=[]}async fetchGuide(t){const n={command:{guide:{id:t}},globalState:this.globalState,clientId:this.clientId};return await this.postEnvelope(n)}async postEnvelope(t,n){try{const e=await fetch(this.endpoint,this.getHttpOptions(t));if(!e.ok)throw e;const a=await e.json();return this.handleResponse(a,n)}catch(e){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let a="Something went wrong";return(e.message==="Failed to fetch"||e.message==="NetworkError when attempting to fetch resource.")&&(a="Lost connection... Please try again."),this.handleResponse({entries:[{id:S.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:a},actions:{},tags:[]}]})}}async handleResponse(t,n){this.entries=this.entries.concat(t.entries),this.store.write(this.entries,"entries");const e=t.entries.find(d=>d.type==="Widget");return e&&this.events.dispatch("provider:widget-entry",e.content),t.globalState&&(this.globalState=t.globalState,this.store.write(t.globalState,"globalState")),this.localState=t.entries.reduce((d,g)=>g.localState?g.localState:d,void 0),this.store.write(this.localState,"localState"),await Y(this.container,t.entries)}getHttpOptions(t){const n={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"}};return t.funnel=this.container.get("$widget").name,t.localState=t.localState||this.localState,Object.assign({},n,{body:JSON.stringify(t),credentials:"same-origin"})}}const tt="@telia-ace/conversational-hub-bot-provider",et="1.2.9",nt="./index.js",it="./index.d.ts",ot={".":{import:"./index.mjs",require:"./index.js"}},st={"@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":"*"},rt={"@emotion/react":"11.11.1","@emotion/styled":"11.11.0",react:"18.2.0"},E={name:tt,version:et,main:nt,types:it,exports:ot,dependencies:st,peerDependencies:rt},at=async i=>{var G,H,j,_,V;const t="chub-plugin",n=i.get("$widget"),e=(V=(_=(j=(H=(G=n==null?void 0:n.container)==null?void 0:G.get("$settings"))==null?void 0:H.components)==null?void 0:j.conversation)==null?void 0:_.properties)==null?void 0:V.conversationalHubPluginSettings;let a,d,g,P=(e==null?void 0:e.connectionAttempts)??5,o,h,f;S.Logger.info((E==null?void 0:E.name)+" version: "+(E==null?void 0:E.version)),T.registerCustomMessageComponent(i,M.ContactMethod,Promise.resolve().then(()=>require("./contact-method-4dee0547.js")));const $=await x.createStorageWriter(i,"conversational-hub-session",x.StorageCategory.Necessary),m=(r,c)=>{const{knowledgeBotEndpoint:l}=c.properties();if(l)return`${l}/conversations`;const{data:u}=r.get("$settings");if(!u||!u.projection)throw new Error("Missing Knowledge Bot endpoint");return`${u.projection}/conversations`};(await T.ConversationPlatform.getInstance(i)).registerProvider(t,(r,c)=>{a=r,d=a.controller,g=a.createAgent({name:e==null?void 0:e.botName,avatar:e==null?void 0:e.avatar}),f=m(i,c);const{events:l}=i.get("$widget"),u=new W(i);h=new Z(f,l,u,i),k();const p=()=>d.providers.includes(t);window.controller=d,c.actions.create("submit",s=>{const{events:v}=i.get("$widget");v.dispatch("conversational-hub-provider:form-submitted",s)}),c.actions.watch("conversation.action",(s,v)=>(p()&&C(s),v(s))),c.actions.watch("conversation.user-submit",(s,v)=>{if(!p())return v(s);I(s.text),a.user.print(s.text.replace(/</g,"<").replace(/>/g,">"))})});async function k(r=!0){const c=await x.readStorage(i,"conversational-hub-session");c!=null&&c.sessionId&&r?o=c==null?void 0:c.sessionId:await y(e.baseUrl+"/initialize",`{"extension": "${e.extension}"}`,r)}async function C(r){await y(`${e.baseUrl}/input/${o}`,`{"type":"button_click","language":"${e.language}","content":{"button_text":"${r.label}","value":"${r.actionKey}"}}`)}async function I(r){const c={text:r};await y(`${e.baseUrl}/input/${o}`,`{"type":"text","language":"${e.language}","content":${JSON.stringify(c)}}`)}async function y(r,c,l=!0){var v,L,U,q;const u=a.loading();let p,s;try{p=await fetch(r,{method:"POST",body:c}),s=await(p==null?void 0:p.json())}catch(N){N instanceof SyntaxError?S.Logger.error("Incorrect JSON format.",N):S.Logger.error("Network error: check connection or baseUrl.",N),u(),g.print(e.errorMessage||"An error occurred");return}if(!(p!=null&&p.ok)){if(S.Logger.error(`HTTP ${p==null?void 0:p.status}.`,JSON.stringify(s)),u(),!!((v=s==null?void 0:s.errors)!=null&&v.filter(w=>w.code==="1003").length)&&P>0){P--,await new Promise(R=>setTimeout(R,500)),await k(!1);const w=JSON.parse(c);(L=w==null?void 0:w.content)!=null&&L.text?await I(w.content.text):(U=w==null?void 0:w.content)!=null&&U.action&&await C((q=w==null?void 0:w.content)==null?void 0:q.action)}else g.print(e.errorMessage||"An error occurred");return}u(),P=(e==null?void 0:e.connectionAttempts)??5,s!=null&&s.action_payload&&K(s.action_payload),o=s==null?void 0:s.session_id,$({sessionId:o}),l&&J(s)}async function K(r){var p;const c=(p=r==null?void 0:r.transfer_parameters)==null?void 0:p.contactGuide,l=a.loading(),u=await h.fetchGuide(parseInt(c));if(l(),u){const s=u.concat(u);if(s.length){const v=s[0].items.map(L=>L.message);g.print(v)}}}function J(r){var c;r==null||r.agent_response.forEach(l=>{g.print(l.payload.text)}),(c=r==null?void 0:r.prompt)!=null&&c.items&&g.print(["button-list",{actions:r.prompt.items.map(l=>{let u;return l.type==="button"&&(u={actionKey:l.value,label:l.text}),l.type==="link"&&(u={actionKey:l.value,label:l.text,data:{href:l.url,target:(e==null?void 0:e.linkTarget)??"_blank"}}),u})}])}};exports.ConversationalHubPlugin=at;exports.updateForm=Q;
|
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-f502b1d3.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");require("@telia-ace/widget-utilities");require("@telia-ace/widget-forms");exports.ConversationalHubPlugin=e.ConversationalHubPlugin;
|
package/index.mjs
CHANGED