@telia-ace/knowledge-widget-bot-provider 1.1.5-rc.2 → 1.1.5-rc.3

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.
@@ -6,7 +6,7 @@ import { useContainer as N, useDispatch as R, useConversation as T } from "@teli
6
6
  import { FormBuilder as _ } from "@telia-ace/widget-forms";
7
7
  import { appendClassNames as j } from "@telia-ace/widget-utilities";
8
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";
9
+ import { u as S } from "./index-3955a071.mjs";
10
10
  import "@telia-ace/widget-conversation";
11
11
  import "@telia-ace/widget-services";
12
12
  const tt = ({
@@ -1,3 +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)`
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-acad4fca.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
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;
@@ -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-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)`
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-6c51a24f.js");require("@telia-ace/knowledge-data-client");require("@telia-ace/widget-forms");require("@telia-ace/widget-utilities");require("./index-acad4fca.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");const j=({actions:e,entryId:t,groupId:x})=>{const q=g.useDispatch(),d=g.useContainer(),[h,C]=l.useState([]),[o,M]=l.useState([]);return l.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)M([...o,r.id]);else{const{events:f}=d.get("$widget");f.dispatch("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,d,t,o]),h.length?a.jsx(k,{className:"humany-bot-contact-list",contactMethods:h,dispatch:q,itemRenderer:(n,c)=>(o.includes(n.id)||n.expanded)&&n.inline?a.jsx(S,{contactMethodId:n.id,groupId:x,guideId:n.body.guideId}):a.jsx($,{...n,...c})}):null},k=u(y.ContactList)`
2
2
  > ul > li {
3
3
  a {
4
4
  display: flex;
@@ -10,14 +10,14 @@
10
10
  ${e=>e.theme.border&&`border-bottom: ${e.theme.border};`}
11
11
  }
12
12
  }
13
- `,$=l(b.default)`
13
+ `,S=u(b.default)`
14
14
  i {
15
15
  margin: 0 ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.medium}} 0 0;
16
16
  display: flex;
17
17
  justify-content: center;
18
18
  align-items: center;
19
19
  }
20
- `,k=l(g.ContactMethod)`
20
+ `,$=u(y.ContactMethod)`
21
21
  padding: ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.medium}};
22
22
  i {
23
23
  margin: 0 ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.medium}} 0 0;
@@ -1,66 +1,69 @@
1
1
  import { jsx as a } from "react/jsx-runtime";
2
2
  import m from "@emotion/styled";
3
3
  import { ContactList as M, ContactMethod as $ } from "@telia-ace/knowledge-widget-adapters";
4
- import { useDispatch as b, useContainer as E } from "@telia-ace/knowledge-widget-ui";
5
- import { useState as f, useEffect as S } from "react";
6
- import j from "./contact-method-ad283c44.mjs";
4
+ import { useDispatch as b, useContainer as k } from "@telia-ace/knowledge-widget-ui";
5
+ import { useState as f, useEffect as E } from "react";
6
+ import S from "./contact-method-59329b29.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-6cc85689.mjs";
10
+ import "./index-3955a071.mjs";
11
11
  import "@telia-ace/widget-conversation";
12
12
  import "@telia-ace/widget-services";
13
- const F = ({ actions: t, entryId: e, groupId: h }) => {
14
- const y = b(), d = E(), [l, g] = f([]), [r, x] = f([]);
15
- return S(() => {
16
- d.getAsync("contactMethods").then((n) => {
17
- if (!n)
13
+ const F = ({ actions: t, entryId: e, groupId: y }) => {
14
+ const g = b(), d = k(), [l, x] = f([]), [r, C] = f([]);
15
+ return E(() => {
16
+ d.getAsync("contactMethods").then((i) => {
17
+ if (!i)
18
18
  return;
19
- const c = t.map(async (i) => {
19
+ const c = t.map(async (n) => {
20
20
  var p;
21
- if (!((p = i.data) != null && p.clientName))
21
+ if (!((p = n.data) != null && p.clientName))
22
22
  return null;
23
- const o = await n.handleAdapters(i.data);
23
+ const o = await i.handleAdapters(n.data);
24
24
  return {
25
25
  ...o,
26
- ...i.data,
27
- description: i.data.description ? i.data.description : o.description,
26
+ ...n.data,
27
+ description: n.data.description ? n.data.description : o.description,
28
28
  onClick: (u, s) => {
29
29
  if (typeof o.onClick == "function" && o.onClick(u, s), !u.defaultPrevented)
30
30
  if (s.inline && !s.expanded)
31
- x([...r, s.id]);
31
+ C([...r, s.id]);
32
32
  else {
33
- const { events: C } = d.get("$widget");
34
- C.dispatch("provider:open-contact-method", {
33
+ const { events: h } = d.get("$widget");
34
+ h.dispatch("provider:open-contact-method", {
35
35
  entryId: e,
36
36
  contactMethod: s,
37
- actionKey: i.actionKey
38
- });
37
+ actionKey: n.actionKey
38
+ }), h.dispatch(
39
+ "tracking:contact-method-list-item-clicked",
40
+ s
41
+ );
39
42
  }
40
43
  }
41
44
  };
42
45
  });
43
- Promise.all(c).then((i) => {
44
- g(i.filter((o) => !!o));
46
+ Promise.all(c).then((n) => {
47
+ x(n.filter((o) => !!o));
45
48
  });
46
49
  });
47
50
  }, [t, d, e, r]), l.length ? /* @__PURE__ */ a(
48
- k,
51
+ j,
49
52
  {
50
53
  className: "humany-bot-contact-list",
51
54
  contactMethods: l,
52
- dispatch: y,
53
- itemRenderer: (n, c) => (r.includes(n.id) || n.expanded) && n.inline ? /* @__PURE__ */ a(
55
+ dispatch: g,
56
+ itemRenderer: (i, c) => (r.includes(i.id) || i.expanded) && i.inline ? /* @__PURE__ */ a(
54
57
  z,
55
58
  {
56
- contactMethodId: n.id,
57
- groupId: h,
58
- guideId: n.body.guideId
59
+ contactMethodId: i.id,
60
+ groupId: y,
61
+ guideId: i.body.guideId
59
62
  }
60
- ) : /* @__PURE__ */ a(I, { ...n, ...c })
63
+ ) : /* @__PURE__ */ a(I, { ...i, ...c })
61
64
  }
62
65
  ) : null;
63
- }, k = m(M)`
66
+ }, j = m(M)`
64
67
  > ul > li {
65
68
  a {
66
69
  display: flex;
@@ -72,7 +75,7 @@ const F = ({ actions: t, entryId: e, groupId: h }) => {
72
75
  ${(t) => t.theme.border && `border-bottom: ${t.theme.border};`}
73
76
  }
74
77
  }
75
- `, z = m(j)`
78
+ `, z = m(S)`
76
79
  i {
77
80
  margin: 0 ${(t) => {
78
81
  var e;
@@ -1,37 +1,39 @@
1
- import { jsx as r, jsxs as s } from "react/jsx-runtime";
2
- import a from "@emotion/styled";
3
- import { useDispatch as i, Icon as n, List as l, list as c, Button as m, buttonCss as d, invertedHoverButton as h } from "@telia-ace/knowledge-widget-ui";
4
- import { m as f } from "./styles-5f6d3622.mjs";
1
+ import { jsx as a, jsxs as i } from "react/jsx-runtime";
2
+ import n from "@emotion/styled";
3
+ import { useContainer as c, useDispatch as l, Icon as d, List as m, list as f, Button as h, buttonCss as p, invertedHoverButton as u } from "@telia-ace/knowledge-widget-ui";
4
+ import { m as y } from "./styles-5f6d3622.mjs";
5
5
  import "@emotion/react";
6
- const k = ({ actions: e }) => {
7
- const t = i();
8
- return /* @__PURE__ */ r(
9
- p,
6
+ const v = ({ actions: e }) => {
7
+ const t = c(), { events: s } = t.get("$widget"), r = l();
8
+ return /* @__PURE__ */ a(
9
+ b,
10
10
  {
11
11
  className: "humany-bot-feedback-list",
12
12
  items: e,
13
13
  "data-direction": "vertical",
14
- renderItem: (o) => /* @__PURE__ */ r("li", { children: /* @__PURE__ */ s(
15
- u,
14
+ renderItem: (o) => /* @__PURE__ */ a("li", { children: /* @__PURE__ */ i(
15
+ $,
16
16
  {
17
17
  className: "humany-feedback-button",
18
18
  disabled: !1,
19
19
  "aria-pressed": !0,
20
20
  "data-selected": !0,
21
21
  onClick: () => {
22
- t("action", o.actionKey);
22
+ r("action", o.actionKey), s.dispatch("tracking:feedback-given-bot", {
23
+ feedbackResponse: o.actionKey
24
+ });
23
25
  },
24
26
  children: [
25
- /* @__PURE__ */ r(n, { faIcon: o.actionKey === "yes" ? "smile-o" : "frown-o" }),
26
- /* @__PURE__ */ r("span", { children: o.label })
27
+ /* @__PURE__ */ a(d, { faIcon: o.actionKey === "yes" ? "smile-o" : "frown-o" }),
28
+ /* @__PURE__ */ a("span", { children: o.label })
27
29
  ]
28
30
  }
29
31
  ) }, o.actionKey)
30
32
  }
31
33
  );
32
- }, p = a(l)`
33
- ${(e) => c(e)}
34
- ${f}
34
+ }, b = n(m)`
35
+ ${(e) => f(e)}
36
+ ${y}
35
37
  display: flex;
36
38
  gap: ${(e) => {
37
39
  var t;
@@ -42,8 +44,8 @@ const k = ({ actions: e }) => {
42
44
  flex: 1;
43
45
  margin: 0;
44
46
  }
45
- `, u = a(m)`
46
- ${d}
47
+ `, $ = n(h)`
48
+ ${p}
47
49
  font-size: ${(e) => {
48
50
  var t;
49
51
  return (t = e.theme.fonts) == null ? void 0 : t.normal;
@@ -58,7 +60,7 @@ const k = ({ actions: e }) => {
58
60
 
59
61
  ${(e) => {
60
62
  var t;
61
- return h({
63
+ return u({
62
64
  primaryColor: `${(t = e.theme.colors) == null ? void 0 : t.primary}`,
63
65
  secondaryColor: "#FFFFFF",
64
66
  theme: e.theme
@@ -74,5 +76,5 @@ const k = ({ actions: e }) => {
74
76
  }
75
77
  `;
76
78
  export {
77
- k as default
79
+ v as default
78
80
  };
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),n=require("@emotion/styled"),s=require("@telia-ace/knowledge-widget-ui"),i=require("./styles-66aa2377.js");require("@emotion/react");const a=({actions:e})=>{const t=s.useDispatch();return o.jsx(l,{className:"humany-bot-feedback-list",items:e,"data-direction":"vertical",renderItem:r=>o.jsx("li",{children:o.jsxs(c,{className:"humany-feedback-button",disabled:!1,"aria-pressed":!0,"data-selected":!0,onClick:()=>{t("action",r.actionKey)},children:[o.jsx(s.Icon,{faIcon:r.actionKey==="yes"?"smile-o":"frown-o"}),o.jsx("span",{children:r.label})]})},r.actionKey)})},l=n(s.List)`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),i=require("@emotion/styled"),s=require("@telia-ace/knowledge-widget-ui"),c=require("./styles-66aa2377.js");require("@emotion/react");const l=({actions:e})=>{const t=s.useContainer(),{events:r}=t.get("$widget"),a=s.useDispatch();return o.jsx(d,{className:"humany-bot-feedback-list",items:e,"data-direction":"vertical",renderItem:n=>o.jsx("li",{children:o.jsxs(u,{className:"humany-feedback-button",disabled:!1,"aria-pressed":!0,"data-selected":!0,onClick:()=>{a("action",n.actionKey),r.dispatch("tracking:feedback-given-bot",{feedbackResponse:n.actionKey})},children:[o.jsx(s.Icon,{faIcon:n.actionKey==="yes"?"smile-o":"frown-o"}),o.jsx("span",{children:n.label})]})},n.actionKey)})},d=i(s.List)`
2
2
  ${e=>s.list(e)}
3
- ${i.messageContentPadding}
3
+ ${c.messageContentPadding}
4
4
  display: flex;
5
5
  gap: ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.normal}};
6
6
  flex-direction: ${e=>e["data-direction"]==="horizontal"?"row":"column"};
@@ -8,7 +8,7 @@
8
8
  flex: 1;
9
9
  margin: 0;
10
10
  }
11
- `,c=n(s.Button)`
11
+ `,u=i(s.Button)`
12
12
  ${s.buttonCss}
13
13
  font-size: ${e=>{var t;return(t=e.theme.fonts)==null?void 0:t.normal}};
14
14
  border-color: ${e=>{var t;return(t=e.theme.colors)==null?void 0:t.primary}};
@@ -22,4 +22,4 @@
22
22
  }
23
23
  span {
24
24
  }
25
- `;exports.default=a;
25
+ `;exports.default=l;
@@ -538,7 +538,7 @@ class q {
538
538
  } catch (i) {
539
539
  process.env.NODE_ENV !== "production" && console.warn("Something went wrong when posting the envelope.");
540
540
  let n = "Something went wrong";
541
- return (i.message === "Failed to fetch" || i.message === "NetworkError when attempting to fetch resource.") && (n = "Lost connection... Please try again."), this.handleResponse({
541
+ return (i.message === "Failed to fetch" || i.message === "NetworkError when attempting to fetch resource.") && (n = "Lost connection... Please try again."), this.events.dispatch("tracking:http-client-error", { message: n, error: i }), this.handleResponse({
542
542
  entries: [
543
543
  {
544
544
  id: E(),
@@ -755,11 +755,11 @@ const st = async (s) => {
755
755
  N(
756
756
  s,
757
757
  p.ContactList,
758
- import("./contact-method-list-6a85e696.mjs")
758
+ import("./contact-method-list-4c1c417c.mjs")
759
759
  ), N(
760
760
  s,
761
761
  p.ContactMethod,
762
- import("./contact-method-ad283c44.mjs")
762
+ import("./contact-method-59329b29.mjs")
763
763
  ), N(
764
764
  s,
765
765
  p.NotificationList,
@@ -771,7 +771,7 @@ const st = async (s) => {
771
771
  ), N(
772
772
  s,
773
773
  p.FeedbackList,
774
- import("./feedback-list-1eef6ff2.mjs")
774
+ import("./feedback-list-0cf5a7d8.mjs")
775
775
  ), t.registerProvider("ace-knowledge-bot", (e, i) => {
776
776
  const n = new X(
777
777
  s,
@@ -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-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;
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.events.dispatch("tracking:http-client-error",{message:n,error:s}),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-2c1b41d6.js"))),m.registerCustomMessageComponent(i,f.ContactMethod,Promise.resolve().then(()=>require("./contact-method-6c51a24f.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-48c7bffb.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-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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-acad4fca.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-6cc85689.mjs";
1
+ import { K as n } from "./index-3955a071.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.5-rc.2",
3
+ "version": "1.1.5-rc.3",
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.5-rc.2",
14
- "@telia-ace/knowledge-widget-adapters": "^1.1.5-rc.2",
15
- "@telia-ace/knowledge-widget-ui": "^1.1.5-rc.2",
16
- "@telia-ace/widget-conversation": "^1.1.5-rc.2",
17
- "@telia-ace/widget-forms": "^1.1.5-rc.2",
18
- "@telia-ace/widget-services": "^1.1.5-rc.2",
19
- "@telia-ace/widget-utilities": "^1.1.5-rc.2",
13
+ "@telia-ace/knowledge-data-client": "^1.1.5-rc.3",
14
+ "@telia-ace/knowledge-widget-adapters": "^1.1.5-rc.3",
15
+ "@telia-ace/knowledge-widget-ui": "^1.1.5-rc.3",
16
+ "@telia-ace/widget-conversation": "^1.1.5-rc.3",
17
+ "@telia-ace/widget-forms": "^1.1.5-rc.3",
18
+ "@telia-ace/widget-services": "^1.1.5-rc.3",
19
+ "@telia-ace/widget-utilities": "^1.1.5-rc.3",
20
20
  "@webprovisions/platform": "^1.1.4",
21
- "@telia-ace/knowledge-widget-core": "^1.1.5-rc.2"
21
+ "@telia-ace/knowledge-widget-core": "^1.1.5-rc.3"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@emotion/react": "11.11.1",