@telia-ace/knowledge-widget-bot-provider 1.1.3 → 1.1.4-rc.1

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.
@@ -0,0 +1,3 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react/jsx-runtime"),A=require("@emotion/styled"),S=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"),F=require("./index-aaaa9471.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(),l=c.useRef(!0),b=p.useConversation();c.useEffect(()=>{const{events:u}=d.get("$widget"),q=u.subscribe("bot-provider:form-submitted",async(f,r)=>{var M;if(((M=r.form.meta)==null?void 0:M.groupId)!==m||r.id!==e.id)return;b&&(r.form.meta||(r.form.meta={}),r.form.meta.conversation=b);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 k=new T.FormBuilder(e.body.form);s(void 0),k.setValidationErrors(i),t.body={...t.body,form:k.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=F.updateForm(i,{submit:"Skicka",errors:{},meta:{groupId:m}});i={...i,body:h},s(i)});return()=>{q(),a()}},[d,e,s,b]);const g=c.useCallback(async u=>{const a=await(await S.DataClient.getInstance(d)).fetch(S.DataType.ContactMethod,{contactMethodId:u,guideId:o},{noCache:!0}),f=F.updateForm(a,{submit:"Skicka",errors:{},meta:{groupId:m}});if(a.body=f,a.body.guideId=o,!l.current)return null;s(a)},[l]);return c.useEffect(()=>(g(n),()=>{l.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
+ 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
+ `;exports.default=z;
@@ -1,31 +1,31 @@
1
- import { jsx as F } from "react/jsx-runtime";
2
- import z from "@emotion/styled";
3
- import { DataClient as A, DataType as B } from "@telia-ace/knowledge-data-client";
4
- import { ContactMethod as N } from "@telia-ace/knowledge-widget-adapters";
5
- import { useContainer as R, useDispatch as T, useConversation as _ } from "@telia-ace/knowledge-widget-ui";
6
- import { FormBuilder as j } from "@telia-ace/widget-forms";
7
- import { appendClassNames as k } from "@telia-ace/widget-utilities";
8
- import { useState as G, useRef as I, useEffect as S, useCallback as V } from "react";
9
- import { u as $ } from "./index-40a1afe2.mjs";
1
+ import { jsx as E } from "react/jsx-runtime";
2
+ import F from "@emotion/styled";
3
+ import { DataClient as z, DataType as A } from "@telia-ace/knowledge-data-client";
4
+ import { ContactMethod as B } from "@telia-ace/knowledge-widget-adapters";
5
+ import { useContainer as N, useDispatch as R, useConversation as T } from "@telia-ace/knowledge-widget-ui";
6
+ import { FormBuilder as _ } from "@telia-ace/widget-forms";
7
+ import { appendClassNames as j } from "@telia-ace/widget-utilities";
8
+ import { useState as G, useRef as I, useEffect as k, useCallback as V } from "react";
9
+ import { u as S } from "./index-6cc85689.mjs";
10
10
  import "@telia-ace/widget-conversation";
11
11
  import "@telia-ace/widget-services";
12
12
  const tt = ({
13
13
  contactMethodId: a,
14
14
  guideId: e,
15
15
  groupId: c,
16
- className: x
16
+ className: $
17
17
  }) => {
18
18
  var h, C, v;
19
- const [t, n] = G(), i = R(), D = T(), u = I(!0), f = _();
20
- S(() => {
21
- const { events: d } = i.get("$widget"), M = d.subscribe(
19
+ const [t, n] = G(), m = N(), x = R(), u = I(!0), f = T();
20
+ k(() => {
21
+ const { events: d } = m.get("$widget"), M = d.subscribe(
22
22
  "bot-provider:form-submitted",
23
23
  async (b, r) => {
24
24
  var w;
25
25
  if (((w = r.form.meta) == null ? void 0 : w.groupId) !== c || r.id !== t.id)
26
26
  return;
27
27
  f && (r.form.meta || (r.form.meta = {}), r.form.meta.conversation = f);
28
- const y = await i.getAsync(
28
+ const y = await m.getAsync(
29
29
  "contactMethods"
30
30
  ), o = {
31
31
  ...t,
@@ -33,61 +33,61 @@ const tt = ({
33
33
  ...t.body,
34
34
  form: r.form
35
35
  }
36
- }, { errors: m, valid: l, errorTypes: H } = await y.validate(
36
+ }, { errors: i, valid: l, errorTypes: H } = await y.validate(
37
37
  o
38
38
  );
39
39
  if (!l) {
40
- const g = new j(t.body.form);
41
- n(void 0), g.setValidationErrors(m), o.body = {
40
+ const g = new _(t.body.form);
41
+ n(void 0), g.setValidationErrors(i), o.body = {
42
42
  ...o.body,
43
43
  form: g.get()
44
44
  }, n({ ...o });
45
45
  return;
46
46
  }
47
- const E = await y.submit(o);
48
- o.confirmation = E, n(o);
47
+ const D = await y.submit(o);
48
+ o.confirmation = D, n(o);
49
49
  }
50
50
  ), s = d.subscribe(
51
51
  "bot-provider:evaluate",
52
52
  async (b, r) => {
53
53
  if (r.id !== a)
54
54
  return;
55
- const o = await (await i.getAsync(
55
+ const o = await (await m.getAsync(
56
56
  "contactMethods"
57
57
  )).evaluate(t);
58
- let m = {
58
+ let i = {
59
59
  ...t,
60
60
  body: {
61
61
  ...t.body,
62
62
  form: o
63
63
  }
64
64
  };
65
- const l = $(m, {
66
- submit: "Submit",
65
+ const l = S(i, {
66
+ submit: "Skicka",
67
67
  errors: {},
68
68
  meta: { groupId: c }
69
69
  });
70
- m = {
71
- ...m,
70
+ i = {
71
+ ...i,
72
72
  body: l
73
- }, n(m);
73
+ }, n(i);
74
74
  }
75
75
  );
76
76
  return () => {
77
77
  M(), s();
78
78
  };
79
- }, [i, t, n, f]);
79
+ }, [m, t, n, f]);
80
80
  const p = V(
81
81
  async (d) => {
82
- const s = await (await A.getInstance(i)).fetch(
83
- B.ContactMethod,
82
+ const s = await (await z.getInstance(m)).fetch(
83
+ A.ContactMethod,
84
84
  {
85
85
  contactMethodId: d,
86
86
  guideId: e
87
87
  },
88
88
  { noCache: !0 }
89
- ), b = $(s, {
90
- submit: "Submit",
89
+ ), b = S(s, {
90
+ submit: "Skicka",
91
91
  errors: {},
92
92
  meta: { groupId: c }
93
93
  });
@@ -98,9 +98,9 @@ const tt = ({
98
98
  // eslint-disable-next-line react-hooks/exhaustive-deps
99
99
  [u]
100
100
  );
101
- return S(() => (p(a), () => {
101
+ return k(() => (p(a), () => {
102
102
  u.current = !1;
103
- }), [a, p]), t ? /* @__PURE__ */ F(
103
+ }), [a, p]), t ? /* @__PURE__ */ E(
104
104
  q,
105
105
  {
106
106
  ...t,
@@ -117,11 +117,11 @@ const tt = ({
117
117
  },
118
118
  inline: !0,
119
119
  expanded: !0,
120
- dispatch: D,
121
- className: k("humany-bot-contact-method", x)
120
+ dispatch: x,
121
+ className: j("humany-bot-contact-method", $)
122
122
  }
123
123
  ) : null;
124
- }, q = z(N)`
124
+ }, q = F(B)`
125
125
  padding: ${(a) => {
126
126
  var e;
127
127
  return (e = a.theme.sizes) == null ? void 0 : e.normal;
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),l=require("@emotion/styled"),g=require("@telia-ace/knowledge-widget-adapters"),f=require("@telia-ace/knowledge-widget-ui"),u=require("react"),b=require("./contact-method-35f483b1.js");require("@telia-ace/knowledge-data-client");require("@telia-ace/widget-forms");require("@telia-ace/widget-utilities");require("./index-b33b8ed1.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");const j=({actions:e,entryId:t,groupId:y})=>{const x=f.useDispatch(),d=f.useContainer(),[h,q]=u.useState([]),[o,C]=u.useState([]);return u.useEffect(()=>{d.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)C([...o,r.id]);else{const{events:M}=d.get("$widget");M.dispatch("provider:open-contact-method",{entryId:t,contactMethod:r,actionKey:i.actionKey})}}}});Promise.all(c).then(i=>{q(i.filter(s=>!!s))})})},[e,d,t,o]),h.length?a.jsx(S,{className:"humany-bot-contact-list",contactMethods:h,dispatch:x,itemRenderer:(n,c)=>(o.includes(n.id)||n.expanded)&&n.inline?a.jsx($,{contactMethodId:n.id,groupId:y,guideId:n.body.guideId}):a.jsx(k,{...n,...c})}):null},S=l(g.ContactList)`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),l=require("@emotion/styled"),g=require("@telia-ace/knowledge-widget-adapters"),f=require("@telia-ace/knowledge-widget-ui"),u=require("react"),b=require("./contact-method-a66d08fa.js");require("@telia-ace/knowledge-data-client");require("@telia-ace/widget-forms");require("@telia-ace/widget-utilities");require("./index-aaaa9471.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");const j=({actions:e,entryId:t,groupId:y})=>{const x=f.useDispatch(),d=f.useContainer(),[h,q]=u.useState([]),[o,C]=u.useState([]);return u.useEffect(()=>{d.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)C([...o,r.id]);else{const{events:M}=d.get("$widget");M.dispatch("provider:open-contact-method",{entryId:t,contactMethod:r,actionKey:i.actionKey})}}}});Promise.all(c).then(i=>{q(i.filter(s=>!!s))})})},[e,d,t,o]),h.length?a.jsx(S,{className:"humany-bot-contact-list",contactMethods:h,dispatch:x,itemRenderer:(n,c)=>(o.includes(n.id)||n.expanded)&&n.inline?a.jsx($,{contactMethodId:n.id,groupId:y,guideId:n.body.guideId}):a.jsx(k,{...n,...c})}):null},S=l(g.ContactList)`
2
2
  > ul > li {
3
3
  a {
4
4
  display: flex;
@@ -3,11 +3,11 @@ import m from "@emotion/styled";
3
3
  import { ContactList as M, ContactMethod as $ } from "@telia-ace/knowledge-widget-adapters";
4
4
  import { useDispatch as b, useContainer as E } from "@telia-ace/knowledge-widget-ui";
5
5
  import { useState as f, useEffect as S } from "react";
6
- import j from "./contact-method-09938f6d.mjs";
6
+ import j from "./contact-method-ad283c44.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-40a1afe2.mjs";
10
+ import "./index-6cc85689.mjs";
11
11
  import "@telia-ace/widget-conversation";
12
12
  import "@telia-ace/widget-services";
13
13
  const F = ({ actions: t, entryId: e, groupId: h }) => {
@@ -755,11 +755,11 @@ const st = async (s) => {
755
755
  N(
756
756
  s,
757
757
  p.ContactList,
758
- import("./contact-method-list-1ae2809b.mjs")
758
+ import("./contact-method-list-6a85e696.mjs")
759
759
  ), N(
760
760
  s,
761
761
  p.ContactMethod,
762
- import("./contact-method-09938f6d.mjs")
762
+ import("./contact-method-ad283c44.mjs")
763
763
  ), N(
764
764
  s,
765
765
  p.NotificationList,
@@ -1 +1 @@
1
- "use strict";var F=Object.defineProperty;var R=(i,t,e)=>t in i?F(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var y=(i,t,e)=>(R(i,typeof t!="symbol"?t+"":t,e),e);const m=require("@telia-ace/widget-conversation"),N=require("@telia-ace/widget-services"),k=require("@telia-ace/widget-utilities"),P=require("@telia-ace/widget-forms");var f=(i=>(i.ContactMethod="ace-knowledge-bot-contact-method",i.ContactList="ace-knowledge-bot-contact-list",i.FeedbackList="ace-knowledge-bot-feedback-list",i.NotificationList="ace-knowledge-bot-notification-list",i.NoGoodAlternative="ace-knowledge-bot-no-good-alternative",i))(f||{});const $=i=>{if(i){const{type:t,content:e}=i;if(t&&e)return{type:t,content:e}}},H=({isUser:i,items:t=[],meta:e={}})=>{const s=k.uuid();return{id:s,isUser:i,items:t.map(r=>({id:r.id||k.uuid(),isUser:i,groupId:s,message:r.message||[]})),meta:e}},G=({id:i,title:t,defaultIcon:e,exits:[s],exitType:n,confirmationText:r,expandFormAutomatically:c,form:u,description:E},K={})=>{const{adapter:a}=s||{Adapter:{}},{clientName:o="",settings:g={},customClientName:S=""}=a,{validation:l}=K,d={id:i.toString(),title:t,description:E,symbol:$(e),clientName:o==="custom.adapter"?S:o,expanded:!0,inline:!0,body:{}};if(o.indexOf("phone")>-1||o.indexOf("freetext")>-1){const{displayTextBeforeClick:M,textBeforeClick:p}=g;M==="true"&&(d.expanded=!1,d.title=p),o.indexOf("phone.text")>-1?d.body.phoneNumber=g.phoneNumber:d.body.freetext=g.freetext}return(o.indexOf("chat.popup")>-1||o.indexOf("link")>-1||o==="custom.adapter"&&n==="custom")&&(d.body=g,d.body.confirmationFallback=r),o.indexOf("ace")>-1&&(d.body=g),u&&u.hasValueComponents&&(l?d.body.form=P.FormBuilder.fromLegacyForm(i.toString(),u,l).get():d.body.form=P.FormBuilder.fromLegacyForm(i.toString(),u).get(),c||(d.expanded=d.inline=!1),d.body=B(d,{submit:"Submit"})),K.guideId&&(d.body.guideId=K.guideId),d},U=i=>{const{localState:t}=i;return i.tags.includes("category")&&i.tags.includes("contact")?m.ConversationMessageListItemType.ItemList:i.tags.includes("suggestion")||(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching"?m.ConversationMessageListItemType.LinkList:(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching"?f.FeedbackList:(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"?f.ContactList:m.ConversationMessageListItemType.ButtonList},q=(i,t)=>{const{knowledgeBotEndpoint:e}=t.properties();if(e)return`${e}/conversations`;const{data:s}=i.get("$settings");if(!s||!s.projection)throw new Error("Missing Knowledge Bot endpoint");return`${s.projection}/conversations`},B=(i,{submit:t,errors:e,meta:s})=>{var n;if((n=i==null?void 0:i.body)!=null&&n.form){const{body:r}=i,c=new P.FormBuilder(r.form);return r.form.layout.submit||c.createComponent(P.submitButton(t,"submit")),e&&c.setValidationErrors(e),s&&c.setMeta(s),{...r,form:c.get()}}return(i==null?void 0:i.body)||{}},A=async(i,t,e)=>{(await(await i.getAsync("dataClient")).getClient()).parameters.set(t,e)},b=({messageId:i,message:t,group:e})=>({id:i,message:t,groupId:e.id,isUser:e.isUser}),V=async(i,t,e)=>{const s=(a,o,g,S={actions:[],entryId:o.id,groupId:g})=>{const l=[];return S.actions=o.content.items.map(d=>{var p;const M={label:d.title,actionKey:d.actionKey,symbol:d.symbol?d.symbol:void 0,description:d.description||void 0};if(d.data){const v=o.actions[d.actionKey];a===f.ContactList?(l.push(d.data.id),M.data=G(d.data,{guideId:(p=v==null?void 0:v.guideId)==null?void 0:p.toString()})):M.data=d.data}return M}),a===f.ContactList&&(S.contactMethodIds=l),S},n=async(a,o,g=[],S)=>{var d,M;const l=k.uuid();switch(a.type!=="List"&&a.tags.includes("guide")&&((M=(d=a.content.hints)==null?void 0:d[0])!=null&&M.id)&&await A(i,"LastGuideId",a.content.hints[0].id),a.type){case"List":{const{header:p,items:v,html:x}=a.content,w=[];let I={actions:[],entryId:a.id,groupId:o.id};if(p&&(I.header=p),(v==null?void 0:v.length)>0){const h=U(a);if(I=s(h,a,o.id,I),g.length){const C=g.find(L=>L.tags.includes("paging")),T=g.find(L=>L.tags.includes("fallback"));if(C!=null&&C.content&&(o.meta.paging={actions:C.actions,items:C.content.items,localState:C.localState},C.content.items.forEach(L=>{I.actions.push({label:L.title,actionKey:L.actionKey,data:{groupId:S?S.id:o.id}})})),T){const L=T.content.items.find(O=>O.actionKey==="help");L&&(w.push(b({messageId:l,message:[m.ConversationMessageListItemType.Separator,void 0],group:o})),w.push(b({messageId:l,message:[f.NoGoodAlternative,{body:L.title}],group:o})))}}w.unshift(b({messageId:l,message:[h,I],group:o}))}return x&&w.unshift(b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:x}],group:o})),w}case"Text":{const p=[];if(p.push(b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:a.content.html}],group:o})),g.length){const v=g.find(h=>{var C;return h.type==="List"&&((C=h.localState)==null?void 0:C.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"}),x=g.find(h=>h.tags.includes("dialog")),w=g.find(h=>h.tags.includes("feedback")),I=g.find(h=>h.tags.includes("contact")&&h.type==="Contact");if(I&&p.push(b({messageId:l,message:[f.ContactMethod,{contactMethodId:I.content.id,groupId:o.id,guideId:I.content.guideId}],group:o})),x&&p.push(b({messageId:l,message:[m.ConversationMessageListItemType.ButtonList,{actions:x.content.items.map(h=>({label:h.title,actionKey:h.actionKey,data:h.data}))}],group:o})),v){const h=s(f.ContactList,v,o.id);p.push(b({messageId:l,message:[m.ConversationMessageListItemType.Separator,void 0],group:o})),p.push(b({messageId:l,message:[f.ContactList,h],group:o}))}w&&(w.content.html&&p.push(b({messageId:l,group:o,message:[m.ConversationMessageListItemType.HTML,{body:w.content.html}]})),p.push(b({messageId:l,group:o,message:[f.FeedbackList,{actions:w.content.items.map(h=>({actionKey:h.actionKey,label:h.title}))}]})))}return p}case"Contact":return[b({messageId:l,message:[f.ContactMethod,{contactMethodId:a.content.id,groupId:o.id,guideId:a.content.guideId}],group:o})];case"CategorizedNoticeList":{const p=[b({messageId:l,message:[f.NotificationList,{id:a.content.item.id.toString(),header:a.content.item.title,items:a.content.item.listNotices,symbol:a.content.item.defaultIcon}],group:o})];return(a.content.notices||[]).forEach(v=>{p.push(b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:v.body}],group:o}))}),p}case"footerNotice":return[b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:a.content.item.body}],group:o})];case"Error":return[b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:a.content.message||"Something went wrong."}],group:o})];default:return[]}},r=a=>["CategorizedNoticeList","NoticeList"].includes(a.type)?(a.content.items||[]).reduce((o,g)=>(a.content.isInitialNotices&&o.push({...a,id:k.uuid(),type:g.type||a.type,content:{$type:a.content.$type,isInitialNotices:a.content.isInitialNotices,notices:g.notices,item:g}}),o),[]):a,c=new Map([["Text",1],["List",2],["Contact",3],["CategorizedNoticeList",10]]),u=[],E=t.sort((a,o)=>{const S=c.get(a.type)||20,l=c.get(o.type)||20;return S-l}).filter(a=>!a.relation).reduce((a,o)=>a.concat(r(o)),[]),K=a=>typeof a.actions.selector<"u";for(const a of E){const o=t.filter(l=>l.relation===a.id&&!K(l)),g=H({isUser:!1});(await n(a,g,o,e)).forEach(l=>{g.items.push(l)}),g.items.length&&u.push(g)}return u};class j{constructor(t,e,s,n){y(this,"globalState");y(this,"localState");y(this,"clientId");y(this,"entries");this.endpoint=t,this.events=e,this.store=s,this.container=n,this.clientId=k.uuid(),this.entries=[]}async start({silent:t}){const e=await this.store.read("globalState"),s=await this.store.read("localState"),n=await this.store.read("entries");if(this.globalState=e||this.globalState,this.localState=s||this.localState,this.entries=n||this.entries,t)return;const r=this.createInitialEnvelope();return await this.postEnvelope(r)}async sendMessage(t){const e={command:{phrase:t},globalState:this.globalState,clientId:this.clientId};return await this.postEnvelope(e)}async helpAction(){return this.postEnvelope({action:{key:"help",content:{$type:"Humany.Matching.Bots.Conversations.Actions.Help, Humany.Matching"}},globalState:this.globalState,clientId:this.clientId})}async nextAction(t){var s;const{paging:e}=t.meta;if((s=e.actions)!=null&&s.next)return this.postEnvelope({action:{key:"next",content:e.actions.next},localState:e.localState,globalState:this.globalState,clientId:this.clientId},t).then(n=>{const r=t.items.findIndex(c=>c.message[0]==="link-list");return r===-1||!n?t:{...t,meta:{...t.meta,...n[0].meta},items:[...t.items.slice(0,r),{...t.items[r],message:[n[0].items[0].message[0],{...t.items[r].message[1],...n[0].items[0].message[1]}]},...t.items.slice(r+1)]}})}async showContactMethodAction(t){const e=this.entries.find(n=>n.id===t.entryId),s=e==null?void 0:e.actions[t.actionKey];if(s)return this.postEnvelope({action:{key:t.actionKey,content:s},localState:e.localState,globalState:this.globalState,clientId:this.clientId})}async defaultAction(t){const e=this.getEntryOfAction(t);if(e)return this.postEnvelope({action:{key:t,content:e.actions[t]},localState:e.localState,globalState:this.globalState,clientId:this.clientId})}createInitialEnvelope(){return{command:{site:this.endpoint},clientId:this.clientId,globalState:{},funnel:this.container.get("$widget").name}}async postEnvelope(t,e){try{const s=await fetch(this.endpoint,this.getHttpOptions(t));if(!s.ok)throw s;const n=await s.json();return this.handleResponse(n,e)}catch(s){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let n="Something went wrong";return(s.message==="Failed to fetch"||s.message==="NetworkError when attempting to fetch resource.")&&(n="Lost connection... Please try again."),this.handleResponse({entries:[{id:k.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:n},actions:{},tags:[]}]})}}async handleResponse(t,e){this.entries=this.entries.concat(t.entries),this.store.write(this.entries,"entries");const s=t.entries.find(r=>r.type==="Widget");return s&&this.events.dispatch("provider:widget-entry",s.content),t.globalState&&(this.globalState=t.globalState,this.store.write(t.globalState,"globalState")),this.localState=t.entries.reduce((r,c)=>c.localState?c.localState:r,void 0),this.store.write(this.localState,"localState"),await V(this.container,t.entries,e)}getHttpOptions(t){const e={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({},e,{body:JSON.stringify(t),credentials:"same-origin"})}getEntryOfAction(t){return this.entries.find(e=>!!e.actions[t])}}class z{constructor(t){y(this,"enabled",!0);y(this,"botProviderGlobalStateKey","bot-provider-global-state");y(this,"botProviderLocalStateKey","bot-provider-local-state");y(this,"botProviderEntriesKey","bot-provider-entries");y(this,"botProviderMetaStateKey","bot-provider-conversation-meta");this.container=t}getKey(t){let e;switch(t){case"localState":e=this.botProviderLocalStateKey;break;case"globalState":e=this.botProviderGlobalStateKey;break;case"entries":e=this.botProviderEntriesKey;break;case"meta":e=this.botProviderMetaStateKey;break}return e}async read(t){const e=this.getKey(t);if(!(!this.enabled||!e))return N.readStorage(this.container,e)}async write(t,e){const s=this.getKey(e);if(!this.enabled||!s)return;(await N.createStorageWriter(this.container,s,N.StorageCategory.Necessary))(t)}}class W{constructor(t,e,s){y(this,"agent");y(this,"user");y(this,"httpClient");y(this,"events");y(this,"groups",[]);y(this,"store");this.container=t,this.conversation=e;const{events:n}=this.container.get("$widget");this.events=n,this.store=new z(t),this.agent=e.createAgent({id:"knowledge-bot-agent",name:"",avatar:void 0}),this.user=e.user;const r=q(t,s);this.httpClient=new j(r,n,this.store,this.container),this.events.subscribe("provider:widget-entry",(c,u)=>{this.onWidgetEntryReceived(u)}),this.events.subscribe("provider:open-contact-method",async(c,u)=>{const E=await this.httpClient.showContactMethodAction(u);E&&(u.contactMethod.title&&this.printUserMessage(u.contactMethod.title),this.onMessagesReceived(E))})}async initialize(){var r;const t=this.conversation.loading(),e=await this.store.read("meta");e!=null&&e.agent&&this.agent.update({name:e.agent.name,avatar:e.agent.avatar});const s=await this.conversation.isRehydrated(),n=await this.httpClient.start({silent:((r=this.conversation.options)==null?void 0:r.silent)||s});n&&this.onMessagesReceived(n),t()}async onMessagesReceived(t){this.groups=this.groups.concat(t),t.forEach(e=>{const s=e.items.map(n=>n.message);e.isUser?e.writer=this.user.print(s):e.writer=this.agent.print(s)})}async onInput(t){const e=typeof t=="string"?t:t.actionKey;switch(e){case"next":{if(typeof t=="string")return;const s=this.groups.find(n=>{var r;return n.id===((r=t.data)==null?void 0:r.groupId)});if(s){const n=await this.httpClient.nextAction(s);if(n){const r=n.items.map(c=>c.message);s.meta.paging=n==null?void 0:n.meta.paging,s.writer.update(r)}}}break;case"help":{const s=this.conversation.loading(),n=await this.httpClient.helpAction();s(),n&&this.onMessagesReceived(n)}break;default:{typeof t!="string"&&t.label&&this.printUserMessage(t.label);const s=this.conversation.loading(),n=await this.httpClient.defaultAction(e);n&&this.onMessagesReceived(n),s()}break}}printUserMessage(t){const e=H({isUser:!0,items:[{id:k.uuid(),isUser:!0,message:[m.ConversationMessageListItemType.HTML,{body:t}]}]});return this.onMessagesReceived([e]),e}async onMessageSend(t){const e=this.conversation.loading(),s=await this.httpClient.sendMessage(t);await A(this.container,"phrase",t),this.printUserMessage(t),s&&this.onMessagesReceived(s),e()}async onWidgetEntryReceived(t){if(t.agent){const e={name:t.agent.name,avatar:t.agent.avatar};this.agent.update(e),(await N.createStorageWriter(this.container,"bot-provider-conversation-meta",N.StorageCategory.Necessary))({agent:e})}}}const _=async i=>{const t=await m.ConversationPlatform.getInstance(i);m.registerCustomMessageComponent(i,f.ContactList,Promise.resolve().then(()=>require("./contact-method-list-52fb36fb.js"))),m.registerCustomMessageComponent(i,f.ContactMethod,Promise.resolve().then(()=>require("./contact-method-35f483b1.js"))),m.registerCustomMessageComponent(i,f.NotificationList,Promise.resolve().then(()=>require("./notification-list-d4d9695d.js"))),m.registerCustomMessageComponent(i,f.NoGoodAlternative,Promise.resolve().then(()=>require("./no-good-alternative-0ced8ab9.js"))),m.registerCustomMessageComponent(i,f.FeedbackList,Promise.resolve().then(()=>require("./feedback-list-6f877c77.js"))),t.registerProvider("ace-knowledge-bot",(e,s)=>{const n=new W(i,e,s);n.initialize();const r=[];return r.push(s.actions.watch("conversation.user-submit",(c,u)=>{n.onMessageSend(c.text)})),r.push(s.actions.watch("conversation.action",(c,u)=>(n.onInput(c),u(c)))),r.push(s.actions.create("evaluate",c=>{const{events:u}=i.get("$widget");u.dispatch("bot-provider:evaluate",c)})),r.push(s.actions.create("submit",c=>{const{events:u}=i.get("$widget");u.dispatch("bot-provider:form-submitted",c)})),()=>{r.forEach(c=>{c()})}})};exports.KnowledgeBotProviderPlugin=_;exports.updateForm=B;
1
+ "use strict";var F=Object.defineProperty;var R=(i,t,e)=>t in i?F(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var y=(i,t,e)=>(R(i,typeof t!="symbol"?t+"":t,e),e);const m=require("@telia-ace/widget-conversation"),N=require("@telia-ace/widget-services"),k=require("@telia-ace/widget-utilities"),P=require("@telia-ace/widget-forms");var f=(i=>(i.ContactMethod="ace-knowledge-bot-contact-method",i.ContactList="ace-knowledge-bot-contact-list",i.FeedbackList="ace-knowledge-bot-feedback-list",i.NotificationList="ace-knowledge-bot-notification-list",i.NoGoodAlternative="ace-knowledge-bot-no-good-alternative",i))(f||{});const $=i=>{if(i){const{type:t,content:e}=i;if(t&&e)return{type:t,content:e}}},H=({isUser:i,items:t=[],meta:e={}})=>{const s=k.uuid();return{id:s,isUser:i,items:t.map(r=>({id:r.id||k.uuid(),isUser:i,groupId:s,message:r.message||[]})),meta:e}},G=({id:i,title:t,defaultIcon:e,exits:[s],exitType:n,confirmationText:r,expandFormAutomatically:c,form:u,description:E},K={})=>{const{adapter:a}=s||{Adapter:{}},{clientName:o="",settings:g={},customClientName:S=""}=a,{validation:l}=K,d={id:i.toString(),title:t,description:E,symbol:$(e),clientName:o==="custom.adapter"?S:o,expanded:!0,inline:!0,body:{}};if(o.indexOf("phone")>-1||o.indexOf("freetext")>-1){const{displayTextBeforeClick:M,textBeforeClick:p}=g;M==="true"&&(d.expanded=!1,d.title=p),o.indexOf("phone.text")>-1?d.body.phoneNumber=g.phoneNumber:d.body.freetext=g.freetext}return(o.indexOf("chat.popup")>-1||o.indexOf("link")>-1||o==="custom.adapter"&&n==="custom")&&(d.body=g,d.body.confirmationFallback=r),o.indexOf("ace")>-1&&(d.body=g),u&&u.hasValueComponents&&(l?d.body.form=P.FormBuilder.fromLegacyForm(i.toString(),u,l).get():d.body.form=P.FormBuilder.fromLegacyForm(i.toString(),u).get(),c||(d.expanded=d.inline=!1),d.body=B(d,{submit:"Submit"})),K.guideId&&(d.body.guideId=K.guideId),d},U=i=>{const{localState:t}=i;return i.tags.includes("category")&&i.tags.includes("contact")?m.ConversationMessageListItemType.ItemList:i.tags.includes("suggestion")||(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching"?m.ConversationMessageListItemType.LinkList:(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching"?f.FeedbackList:(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"?f.ContactList:m.ConversationMessageListItemType.ButtonList},q=(i,t)=>{const{knowledgeBotEndpoint:e}=t.properties();if(e)return`${e}/conversations`;const{data:s}=i.get("$settings");if(!s||!s.projection)throw new Error("Missing Knowledge Bot endpoint");return`${s.projection}/conversations`},B=(i,{submit:t,errors:e,meta:s})=>{var n;if((n=i==null?void 0:i.body)!=null&&n.form){const{body:r}=i,c=new P.FormBuilder(r.form);return r.form.layout.submit||c.createComponent(P.submitButton(t,"submit")),e&&c.setValidationErrors(e),s&&c.setMeta(s),{...r,form:c.get()}}return(i==null?void 0:i.body)||{}},A=async(i,t,e)=>{(await(await i.getAsync("dataClient")).getClient()).parameters.set(t,e)},b=({messageId:i,message:t,group:e})=>({id:i,message:t,groupId:e.id,isUser:e.isUser}),V=async(i,t,e)=>{const s=(a,o,g,S={actions:[],entryId:o.id,groupId:g})=>{const l=[];return S.actions=o.content.items.map(d=>{var p;const M={label:d.title,actionKey:d.actionKey,symbol:d.symbol?d.symbol:void 0,description:d.description||void 0};if(d.data){const v=o.actions[d.actionKey];a===f.ContactList?(l.push(d.data.id),M.data=G(d.data,{guideId:(p=v==null?void 0:v.guideId)==null?void 0:p.toString()})):M.data=d.data}return M}),a===f.ContactList&&(S.contactMethodIds=l),S},n=async(a,o,g=[],S)=>{var d,M;const l=k.uuid();switch(a.type!=="List"&&a.tags.includes("guide")&&((M=(d=a.content.hints)==null?void 0:d[0])!=null&&M.id)&&await A(i,"LastGuideId",a.content.hints[0].id),a.type){case"List":{const{header:p,items:v,html:x}=a.content,w=[];let I={actions:[],entryId:a.id,groupId:o.id};if(p&&(I.header=p),(v==null?void 0:v.length)>0){const h=U(a);if(I=s(h,a,o.id,I),g.length){const C=g.find(L=>L.tags.includes("paging")),T=g.find(L=>L.tags.includes("fallback"));if(C!=null&&C.content&&(o.meta.paging={actions:C.actions,items:C.content.items,localState:C.localState},C.content.items.forEach(L=>{I.actions.push({label:L.title,actionKey:L.actionKey,data:{groupId:S?S.id:o.id}})})),T){const L=T.content.items.find(O=>O.actionKey==="help");L&&(w.push(b({messageId:l,message:[m.ConversationMessageListItemType.Separator,void 0],group:o})),w.push(b({messageId:l,message:[f.NoGoodAlternative,{body:L.title}],group:o})))}}w.unshift(b({messageId:l,message:[h,I],group:o}))}return x&&w.unshift(b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:x}],group:o})),w}case"Text":{const p=[];if(p.push(b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:a.content.html}],group:o})),g.length){const v=g.find(h=>{var C;return h.type==="List"&&((C=h.localState)==null?void 0:C.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"}),x=g.find(h=>h.tags.includes("dialog")),w=g.find(h=>h.tags.includes("feedback")),I=g.find(h=>h.tags.includes("contact")&&h.type==="Contact");if(I&&p.push(b({messageId:l,message:[f.ContactMethod,{contactMethodId:I.content.id,groupId:o.id,guideId:I.content.guideId}],group:o})),x&&p.push(b({messageId:l,message:[m.ConversationMessageListItemType.ButtonList,{actions:x.content.items.map(h=>({label:h.title,actionKey:h.actionKey,data:h.data}))}],group:o})),v){const h=s(f.ContactList,v,o.id);p.push(b({messageId:l,message:[m.ConversationMessageListItemType.Separator,void 0],group:o})),p.push(b({messageId:l,message:[f.ContactList,h],group:o}))}w&&(w.content.html&&p.push(b({messageId:l,group:o,message:[m.ConversationMessageListItemType.HTML,{body:w.content.html}]})),p.push(b({messageId:l,group:o,message:[f.FeedbackList,{actions:w.content.items.map(h=>({actionKey:h.actionKey,label:h.title}))}]})))}return p}case"Contact":return[b({messageId:l,message:[f.ContactMethod,{contactMethodId:a.content.id,groupId:o.id,guideId:a.content.guideId}],group:o})];case"CategorizedNoticeList":{const p=[b({messageId:l,message:[f.NotificationList,{id:a.content.item.id.toString(),header:a.content.item.title,items:a.content.item.listNotices,symbol:a.content.item.defaultIcon}],group:o})];return(a.content.notices||[]).forEach(v=>{p.push(b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:v.body}],group:o}))}),p}case"footerNotice":return[b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:a.content.item.body}],group:o})];case"Error":return[b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:a.content.message||"Something went wrong."}],group:o})];default:return[]}},r=a=>["CategorizedNoticeList","NoticeList"].includes(a.type)?(a.content.items||[]).reduce((o,g)=>(a.content.isInitialNotices&&o.push({...a,id:k.uuid(),type:g.type||a.type,content:{$type:a.content.$type,isInitialNotices:a.content.isInitialNotices,notices:g.notices,item:g}}),o),[]):a,c=new Map([["Text",1],["List",2],["Contact",3],["CategorizedNoticeList",10]]),u=[],E=t.sort((a,o)=>{const S=c.get(a.type)||20,l=c.get(o.type)||20;return S-l}).filter(a=>!a.relation).reduce((a,o)=>a.concat(r(o)),[]),K=a=>typeof a.actions.selector<"u";for(const a of E){const o=t.filter(l=>l.relation===a.id&&!K(l)),g=H({isUser:!1});(await n(a,g,o,e)).forEach(l=>{g.items.push(l)}),g.items.length&&u.push(g)}return u};class j{constructor(t,e,s,n){y(this,"globalState");y(this,"localState");y(this,"clientId");y(this,"entries");this.endpoint=t,this.events=e,this.store=s,this.container=n,this.clientId=k.uuid(),this.entries=[]}async start({silent:t}){const e=await this.store.read("globalState"),s=await this.store.read("localState"),n=await this.store.read("entries");if(this.globalState=e||this.globalState,this.localState=s||this.localState,this.entries=n||this.entries,t)return;const r=this.createInitialEnvelope();return await this.postEnvelope(r)}async sendMessage(t){const e={command:{phrase:t},globalState:this.globalState,clientId:this.clientId};return await this.postEnvelope(e)}async helpAction(){return this.postEnvelope({action:{key:"help",content:{$type:"Humany.Matching.Bots.Conversations.Actions.Help, Humany.Matching"}},globalState:this.globalState,clientId:this.clientId})}async nextAction(t){var s;const{paging:e}=t.meta;if((s=e.actions)!=null&&s.next)return this.postEnvelope({action:{key:"next",content:e.actions.next},localState:e.localState,globalState:this.globalState,clientId:this.clientId},t).then(n=>{const r=t.items.findIndex(c=>c.message[0]==="link-list");return r===-1||!n?t:{...t,meta:{...t.meta,...n[0].meta},items:[...t.items.slice(0,r),{...t.items[r],message:[n[0].items[0].message[0],{...t.items[r].message[1],...n[0].items[0].message[1]}]},...t.items.slice(r+1)]}})}async showContactMethodAction(t){const e=this.entries.find(n=>n.id===t.entryId),s=e==null?void 0:e.actions[t.actionKey];if(s)return this.postEnvelope({action:{key:t.actionKey,content:s},localState:e.localState,globalState:this.globalState,clientId:this.clientId})}async defaultAction(t){const e=this.getEntryOfAction(t);if(e)return this.postEnvelope({action:{key:t,content:e.actions[t]},localState:e.localState,globalState:this.globalState,clientId:this.clientId})}createInitialEnvelope(){return{command:{site:this.endpoint},clientId:this.clientId,globalState:{},funnel:this.container.get("$widget").name}}async postEnvelope(t,e){try{const s=await fetch(this.endpoint,this.getHttpOptions(t));if(!s.ok)throw s;const n=await s.json();return this.handleResponse(n,e)}catch(s){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let n="Something went wrong";return(s.message==="Failed to fetch"||s.message==="NetworkError when attempting to fetch resource.")&&(n="Lost connection... Please try again."),this.handleResponse({entries:[{id:k.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:n},actions:{},tags:[]}]})}}async handleResponse(t,e){this.entries=this.entries.concat(t.entries),this.store.write(this.entries,"entries");const s=t.entries.find(r=>r.type==="Widget");return s&&this.events.dispatch("provider:widget-entry",s.content),t.globalState&&(this.globalState=t.globalState,this.store.write(t.globalState,"globalState")),this.localState=t.entries.reduce((r,c)=>c.localState?c.localState:r,void 0),this.store.write(this.localState,"localState"),await V(this.container,t.entries,e)}getHttpOptions(t){const e={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({},e,{body:JSON.stringify(t),credentials:"same-origin"})}getEntryOfAction(t){return this.entries.find(e=>!!e.actions[t])}}class z{constructor(t){y(this,"enabled",!0);y(this,"botProviderGlobalStateKey","bot-provider-global-state");y(this,"botProviderLocalStateKey","bot-provider-local-state");y(this,"botProviderEntriesKey","bot-provider-entries");y(this,"botProviderMetaStateKey","bot-provider-conversation-meta");this.container=t}getKey(t){let e;switch(t){case"localState":e=this.botProviderLocalStateKey;break;case"globalState":e=this.botProviderGlobalStateKey;break;case"entries":e=this.botProviderEntriesKey;break;case"meta":e=this.botProviderMetaStateKey;break}return e}async read(t){const e=this.getKey(t);if(!(!this.enabled||!e))return N.readStorage(this.container,e)}async write(t,e){const s=this.getKey(e);if(!this.enabled||!s)return;(await N.createStorageWriter(this.container,s,N.StorageCategory.Necessary))(t)}}class W{constructor(t,e,s){y(this,"agent");y(this,"user");y(this,"httpClient");y(this,"events");y(this,"groups",[]);y(this,"store");this.container=t,this.conversation=e;const{events:n}=this.container.get("$widget");this.events=n,this.store=new z(t),this.agent=e.createAgent({id:"knowledge-bot-agent",name:"",avatar:void 0}),this.user=e.user;const r=q(t,s);this.httpClient=new j(r,n,this.store,this.container),this.events.subscribe("provider:widget-entry",(c,u)=>{this.onWidgetEntryReceived(u)}),this.events.subscribe("provider:open-contact-method",async(c,u)=>{const E=await this.httpClient.showContactMethodAction(u);E&&(u.contactMethod.title&&this.printUserMessage(u.contactMethod.title),this.onMessagesReceived(E))})}async initialize(){var r;const t=this.conversation.loading(),e=await this.store.read("meta");e!=null&&e.agent&&this.agent.update({name:e.agent.name,avatar:e.agent.avatar});const s=await this.conversation.isRehydrated(),n=await this.httpClient.start({silent:((r=this.conversation.options)==null?void 0:r.silent)||s});n&&this.onMessagesReceived(n),t()}async onMessagesReceived(t){this.groups=this.groups.concat(t),t.forEach(e=>{const s=e.items.map(n=>n.message);e.isUser?e.writer=this.user.print(s):e.writer=this.agent.print(s)})}async onInput(t){const e=typeof t=="string"?t:t.actionKey;switch(e){case"next":{if(typeof t=="string")return;const s=this.groups.find(n=>{var r;return n.id===((r=t.data)==null?void 0:r.groupId)});if(s){const n=await this.httpClient.nextAction(s);if(n){const r=n.items.map(c=>c.message);s.meta.paging=n==null?void 0:n.meta.paging,s.writer.update(r)}}}break;case"help":{const s=this.conversation.loading(),n=await this.httpClient.helpAction();s(),n&&this.onMessagesReceived(n)}break;default:{typeof t!="string"&&t.label&&this.printUserMessage(t.label);const s=this.conversation.loading(),n=await this.httpClient.defaultAction(e);n&&this.onMessagesReceived(n),s()}break}}printUserMessage(t){const e=H({isUser:!0,items:[{id:k.uuid(),isUser:!0,message:[m.ConversationMessageListItemType.HTML,{body:t}]}]});return this.onMessagesReceived([e]),e}async onMessageSend(t){const e=this.conversation.loading(),s=await this.httpClient.sendMessage(t);await A(this.container,"phrase",t),this.printUserMessage(t),s&&this.onMessagesReceived(s),e()}async onWidgetEntryReceived(t){if(t.agent){const e={name:t.agent.name,avatar:t.agent.avatar};this.agent.update(e),(await N.createStorageWriter(this.container,"bot-provider-conversation-meta",N.StorageCategory.Necessary))({agent:e})}}}const _=async i=>{const t=await m.ConversationPlatform.getInstance(i);m.registerCustomMessageComponent(i,f.ContactList,Promise.resolve().then(()=>require("./contact-method-list-3033366c.js"))),m.registerCustomMessageComponent(i,f.ContactMethod,Promise.resolve().then(()=>require("./contact-method-a66d08fa.js"))),m.registerCustomMessageComponent(i,f.NotificationList,Promise.resolve().then(()=>require("./notification-list-d4d9695d.js"))),m.registerCustomMessageComponent(i,f.NoGoodAlternative,Promise.resolve().then(()=>require("./no-good-alternative-0ced8ab9.js"))),m.registerCustomMessageComponent(i,f.FeedbackList,Promise.resolve().then(()=>require("./feedback-list-6f877c77.js"))),t.registerProvider("ace-knowledge-bot",(e,s)=>{const n=new W(i,e,s);n.initialize();const r=[];return r.push(s.actions.watch("conversation.user-submit",(c,u)=>{n.onMessageSend(c.text)})),r.push(s.actions.watch("conversation.action",(c,u)=>(n.onInput(c),u(c)))),r.push(s.actions.create("evaluate",c=>{const{events:u}=i.get("$widget");u.dispatch("bot-provider:evaluate",c)})),r.push(s.actions.create("submit",c=>{const{events:u}=i.get("$widget");u.dispatch("bot-provider:form-submitted",c)})),()=>{r.forEach(c=>{c()})}})};exports.KnowledgeBotProviderPlugin=_;exports.updateForm=B;
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-b33b8ed1.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");require("@telia-ace/widget-utilities");require("@telia-ace/widget-forms");exports.ConversationPlugin=e.KnowledgeBotProviderPlugin;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-aaaa9471.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");require("@telia-ace/widget-utilities");require("@telia-ace/widget-forms");exports.ConversationPlugin=e.KnowledgeBotProviderPlugin;
package/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { K as n } from "./index-40a1afe2.mjs";
1
+ import { K as n } from "./index-6cc85689.mjs";
2
2
  import "@telia-ace/widget-conversation";
3
3
  import "@telia-ace/widget-services";
4
4
  import "@telia-ace/widget-utilities";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/knowledge-widget-bot-provider",
3
- "version": "1.1.3",
3
+ "version": "1.1.4-rc.1",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
@@ -10,15 +10,15 @@
10
10
  }
11
11
  },
12
12
  "dependencies": {
13
- "@telia-ace/knowledge-data-client": "^1.1.3",
14
- "@telia-ace/knowledge-widget-adapters": "^1.1.3",
15
- "@telia-ace/knowledge-widget-ui": "^1.1.3",
16
- "@telia-ace/widget-conversation": "^1.1.3",
17
- "@telia-ace/widget-forms": "^1.1.3",
18
- "@telia-ace/widget-services": "^1.1.3",
19
- "@telia-ace/widget-utilities": "^1.1.3",
13
+ "@telia-ace/knowledge-data-client": "^1.1.4-rc.1",
14
+ "@telia-ace/knowledge-widget-adapters": "^1.1.4-rc.1",
15
+ "@telia-ace/knowledge-widget-ui": "^1.1.4-rc.1",
16
+ "@telia-ace/widget-conversation": "^1.1.4-rc.1",
17
+ "@telia-ace/widget-forms": "^1.1.4-rc.1",
18
+ "@telia-ace/widget-services": "^1.1.4-rc.1",
19
+ "@telia-ace/widget-utilities": "^1.1.4-rc.1",
20
20
  "@webprovisions/platform": "^1.1.4",
21
- "@telia-ace/knowledge-widget-core": "^1.1.3"
21
+ "@telia-ace/knowledge-widget-core": "^1.1.4-rc.1"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@emotion/react": "11.11.1",
@@ -1,3 +0,0 @@
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-b33b8ed1.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[t,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("bot-provider:form-submitted",async(f,r)=>{var M;if(((M=r.form.meta)==null?void 0:M.groupId)!==m||r.id!==t.id)return;l&&(r.form.meta||(r.form.meta={}),r.form.meta.conversation=l);const y=await d.getAsync("contactMethods"),e={...t,body:{...t.body,form:r.form}},{errors:i,valid:h,errorTypes:N}=await y.validate(e);if(!h){const S=new T.FormBuilder(t.body.form);s(void 0),S.setValidationErrors(i),e.body={...e.body,form:S.get()},s({...e});return}const E=await y.submit(e);e.confirmation=E,s(e)}),a=u.subscribe("bot-provider:evaluate",async(f,r)=>{if(r.id!==n)return;const e=await(await d.getAsync("contactMethods")).evaluate(t);let i={...t,body:{...t.body,form:e}};const h=k.updateForm(i,{submit:"Submit",errors:{},meta:{groupId:m}});i={...i,body:h},s(i)});return()=>{q(),a()}},[d,t,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]),t?j.jsx(B,{...t,body:{...t.body,form:t.body.form?{...t.body.form,data:(C=t.body.form)==null?void 0:C.data,layout:{...t.body.form.layout},meta:(v=t.body.form)==null?void 0:v.meta,schema:(w=t.body.form)==null?void 0:w.schema}:void 0,guideId:t.body.guideId},inline:!0,expanded:!0,dispatch:D,className:$.appendClassNames("humany-bot-contact-method",x)}):null},B=A(R.ContactMethod)`
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
- `;exports.default=z;