@telia-ace/knowledge-widget-bot-provider 1.3.41-rc.1 → 1.3.41-rc.2

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,10 +6,8 @@ import { useContainer as R, useDispatch as _, useConversation as G } from "@teli
6
6
  import { FormBuilder as I } from "@telia-ace/widget-forms";
7
7
  import { appendClassNames as O } from "@telia-ace/widget-utilities";
8
8
  import { useState as V, useRef as q, useEffect as $, useCallback as H } from "react";
9
- import { u as j } from "./index-a559356e.mjs";
10
- import "@telia-ace/widget-conversation";
11
- import "@telia-ace/widget-services";
12
- const rt = ({
9
+ import { u as j } from "./index-BnOsK3l6.mjs";
10
+ const et = ({
13
11
  contactMethodId: a,
14
12
  guideId: n,
15
13
  groupId: f,
@@ -18,20 +16,20 @@ const rt = ({
18
16
  var h, g, k, w, S;
19
17
  const [t, m] = V(), c = R(), B = _(), b = q(!0), l = G();
20
18
  $(() => {
21
- const { events: o } = c.get("$widget"), u = o.subscribe(
19
+ const { events: e } = c.get("$widget"), u = e.subscribe(
22
20
  "bot-provider:form-submitted",
23
- async (s, e) => {
21
+ async (i, o) => {
24
22
  var D;
25
- if (((D = e.form.meta) == null ? void 0 : D.groupId) !== f || e.id !== t.id)
23
+ if (((D = o.form.meta) == null ? void 0 : D.groupId) !== f || o.id !== t.id)
26
24
  return;
27
- l && (e.form.meta || (e.form.meta = {}), e.form.meta.conversation = l);
25
+ l && (o.form.meta || (o.form.meta = {}), o.form.meta.conversation = l);
28
26
  const y = await c.getAsync(
29
27
  "contactMethods"
30
28
  ), r = {
31
29
  ...t,
32
30
  body: {
33
31
  ...t.body,
34
- form: e.form
32
+ form: o.form
35
33
  }
36
34
  }, { errors: d, valid: p, errorTypes: K } = await y.validate(
37
35
  r
@@ -47,10 +45,10 @@ const rt = ({
47
45
  const F = await y.submit(r);
48
46
  r.confirmation = F, m(r);
49
47
  }
50
- ), i = o.subscribe(
48
+ ), s = e.subscribe(
51
49
  "bot-provider:evaluate",
52
- async (s, e) => {
53
- if (String(e.id) !== String(a))
50
+ async (i, o) => {
51
+ if (String(o.id) !== String(a))
54
52
  return;
55
53
  const r = await (await c.getAsync(
56
54
  "contactMethods"
@@ -74,42 +72,42 @@ const rt = ({
74
72
  }
75
73
  );
76
74
  return () => {
77
- u(), i();
75
+ u(), s();
78
76
  };
79
77
  }, [c, t, m, l]);
80
- const C = (o, u, i = null) => {
81
- if (o["ui:component"] && o["ui:component"] === "Date")
82
- return Object.assign(o, {
78
+ const C = (e, u, s = null) => {
79
+ if (e["ui:component"] && e["ui:component"] === "Date")
80
+ return Object.assign(e, {
83
81
  "ui:bot": !0,
84
82
  "ui:entrance": u
85
- }), o;
86
- for (const s in o)
87
- if (typeof o[s] == "object" && o[s] !== null) {
88
- const e = C(
89
- o[s],
83
+ }), e;
84
+ for (const i in e)
85
+ if (typeof e[i] == "object" && e[i] !== null) {
86
+ const o = C(
87
+ e[i],
90
88
  u,
91
- o
89
+ e
92
90
  );
93
- if (e !== void 0)
94
- return e;
91
+ if (o !== void 0)
92
+ return o;
95
93
  }
96
94
  }, v = H(
97
- async (o) => {
98
- const i = await (await T.getInstance(c)).fetch(
95
+ async (e) => {
96
+ const s = await (await T.getInstance(c)).fetch(
99
97
  z.ContactMethod,
100
98
  {
101
- contactMethodId: o,
99
+ contactMethodId: e,
102
100
  guideId: n
103
101
  },
104
102
  { noCache: !0, isBot: !0 }
105
- ), s = j(i, {
103
+ ), i = j(s, {
106
104
  submit: "Skicka",
107
105
  errors: {},
108
106
  meta: { groupId: f }
109
107
  });
110
- if (i.body = s, i.body.guideId = n, !b.current)
108
+ if (s.body = i, s.body.guideId = n, !b.current)
111
109
  return null;
112
- m(i);
110
+ m(s);
113
111
  },
114
112
  // eslint-disable-next-line react-hooks/exhaustive-deps
115
113
  [b]
@@ -147,5 +145,5 @@ const rt = ({
147
145
  }};
148
146
  `;
149
147
  export {
150
- rt as default
148
+ et as default
151
149
  };
@@ -0,0 +1,3 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("react/jsx-runtime"),N=require("@emotion/styled"),F=require("@telia-ace/knowledge-data-client"),R=require("@telia-ace/knowledge-widget-adapters"),C=require("@telia-ace/knowledge-widget-ui"),$=require("@telia-ace/widget-forms"),z=require("@telia-ace/widget-utilities"),l=require("react"),x=require("./index-UFpIz4f_.js"),O=({contactMethodId:a,guideId:n,groupId:b,className:T})=>{var h,k,q,S,j;const[e,d]=l.useState(),c=C.useContainer(),A=C.useDispatch(),f=l.useRef(!0),y=C.useConversation();l.useEffect(()=>{const{events:t}=c.get("$widget"),m=t.subscribe("bot-provider:form-submitted",async(i,o)=>{var D;if(((D=o.form.meta)==null?void 0:D.groupId)!==b||o.id!==e.id)return;y&&(o.form.meta||(o.form.meta={}),o.form.meta.conversation=y);const p=await c.getAsync("contactMethods"),r={...e,body:{...e.body,form:o.form}},{errors:u,valid:g,errorTypes:W}=await p.validate(r);if(!g){const E=new $.FormBuilder(e.body.form);d(void 0),E.setValidationErrors(u),r.body={...r.body,form:E.get()},d({...r});return}const B=await p.submit(r);r.confirmation=B,d(r)}),s=t.subscribe("bot-provider:evaluate",async(i,o)=>{if(String(o.id)!==String(a))return;const r=await(await c.getAsync("contactMethods")).evaluate(e);let u={...e,body:{...e.body,form:r}};const g=x.updateForm(u,{submit:"Skicka",errors:{},meta:{groupId:b}});u={...u,body:g},d(u)});return()=>{m(),s()}},[c,e,d,y]);const v=(t,m,s=null)=>{if(t["ui:component"]&&t["ui:component"]==="Date")return Object.assign(t,{"ui:bot":!0,"ui:entrance":m}),t;for(const i in t)if(typeof t[i]=="object"&&t[i]!==null){const o=v(t[i],m,t);if(o!==void 0)return o}},w=l.useCallback(async t=>{const s=await(await F.DataClient.getInstance(c)).fetch(F.DataType.ContactMethod,{contactMethodId:t,guideId:n},{noCache:!0,isBot:!0}),i=x.updateForm(s,{submit:"Skicka",errors:{},meta:{groupId:b}});if(s.body=i,s.body.guideId=n,!f.current)return null;d(s)},[f]);return l.useEffect(()=>(w(a),()=>{f.current=!1}),[a,w]),e?(e.clientName==="ace.callback"&&((h=e.body)!=null&&h.entrance)&&v(e,(k=e.body)==null?void 0:k.entrance),M.jsx(U,{...e,body:{...e.body,form:e.body.form?{...e.body.form,data:(q=e.body.form)==null?void 0:q.data,layout:{...e.body.form.layout},meta:(S=e.body.form)==null?void 0:S.meta,schema:(j=e.body.form)==null?void 0:j.schema}:void 0,guideId:e.body.guideId},inline:!0,expanded:!0,dispatch:A,className:z.appendClassNames("humany-bot-contact-method",T)})):null},U=N(R.ContactMethod)`
2
+ padding: ${a=>{var n;return(n=a.theme.sizes)==null?void 0:n.normal}} ${a=>{var n;return(n=a.theme.sizes)==null?void 0:n.medium}};
3
+ `;exports.default=O;
@@ -0,0 +1,28 @@
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"),k=require("./contact-method-bGgHBWcr.js"),j=({actions:e,entryId:t,groupId:x})=>{const C=g.useDispatch(),o=g.useContainer(),[m,M]=l.useState([]),[c,b]=l.useState([]);return l.useEffect(()=>{o.getAsync("contactMethods").then(n=>{if(!n)return;const r=e.map(async i=>{var h;if(!((h=i.data)!=null&&h.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,d)=>{if(typeof s.onClick=="function"&&s.onClick(p,d),!p.defaultPrevented)if(d.inline&&!d.expanded)b([...c,d.id]);else{const{events:f}=o.get("$widget");f.dispatch("provider:open-contact-method",{entryId:t,contactMethod:d,actionKey:i.actionKey}),f.dispatch("tracking:contact-method-list-item-clicked",d)}}}});Promise.all(r).then(i=>{M(i.filter(s=>!!s))})})},[e,o,t,c]),m.length?a.jsx(S,{className:"humany-bot-contact-list",contactMethods:m,dispatch:C,itemRenderer:(n,r)=>(c.includes(n.id)||n.expanded)&&n.inline||n.clientName==="custom.link"?a.jsx(q,{contactMethodId:n.id,groupId:x,guideId:n.body.guideId}):a.jsx($,{...n,...r})}):null},S=u(y.ContactList)`
2
+ > ul > li {
3
+ a {
4
+ display: flex;
5
+ align-items: center;
6
+ outline-offset: -2px;
7
+ }
8
+
9
+ &:not(:last-child) {
10
+ ${e=>e.theme.border&&`border-bottom: ${e.theme.border};`}
11
+ }
12
+ }
13
+ `,q=u(k.default)`
14
+ i {
15
+ margin: 0 ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.medium}} 0 0;
16
+ display: flex;
17
+ justify-content: center;
18
+ align-items: center;
19
+ }
20
+ `,$=u(y.ContactMethod)`
21
+ padding: ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.medium}};
22
+ i {
23
+ margin: 0 ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.medium}} 0 0;
24
+ display: flex;
25
+ justify-content: center;
26
+ align-items: center;
27
+ }
28
+ `;exports.default=j;
@@ -1,40 +1,34 @@
1
1
  import { jsx as a } from "react/jsx-runtime";
2
- import m from "@emotion/styled";
2
+ import l 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 k } from "@telia-ace/knowledge-widget-ui";
5
5
  import { useState as f, useEffect as E } from "react";
6
- import S from "./contact-method-493fca20.mjs";
7
- import "@telia-ace/knowledge-data-client";
8
- import "@telia-ace/widget-forms";
9
- import "@telia-ace/widget-utilities";
10
- import "./index-a559356e.mjs";
11
- import "@telia-ace/widget-conversation";
12
- import "@telia-ace/widget-services";
13
- const F = ({ actions: t, entryId: e, groupId: y }) => {
14
- const g = b(), d = k(), [l, x] = f([]), [r, C] = f([]);
6
+ import S from "./contact-method-B2iMHgUU.mjs";
7
+ const P = ({ actions: t, entryId: e, groupId: y }) => {
8
+ const g = b(), d = k(), [m, x] = f([]), [c, C] = f([]);
15
9
  return E(() => {
16
- d.getAsync("contactMethods").then((i) => {
17
- if (!i)
10
+ d.getAsync("contactMethods").then((n) => {
11
+ if (!n)
18
12
  return;
19
- const c = t.map(async (n) => {
13
+ const r = t.map(async (i) => {
20
14
  var p;
21
- if (!((p = n.data) != null && p.clientName))
15
+ if (!((p = i.data) != null && p.clientName))
22
16
  return null;
23
- const o = await i.handleAdapters(n.data);
17
+ const o = await n.handleAdapters(i.data);
24
18
  return {
25
19
  ...o,
26
- ...n.data,
27
- description: n.data.description ? n.data.description : o.description,
20
+ ...i.data,
21
+ description: i.data.description ? i.data.description : o.description,
28
22
  onClick: (u, s) => {
29
23
  if (typeof o.onClick == "function" && o.onClick(u, s), !u.defaultPrevented)
30
24
  if (s.inline && !s.expanded)
31
- C([...r, s.id]);
25
+ C([...c, s.id]);
32
26
  else {
33
27
  const { events: h } = d.get("$widget");
34
28
  h.dispatch("provider:open-contact-method", {
35
29
  entryId: e,
36
30
  contactMethod: s,
37
- actionKey: n.actionKey
31
+ actionKey: i.actionKey
38
32
  }), h.dispatch(
39
33
  "tracking:contact-method-list-item-clicked",
40
34
  s
@@ -43,27 +37,27 @@ const F = ({ actions: t, entryId: e, groupId: y }) => {
43
37
  }
44
38
  };
45
39
  });
46
- Promise.all(c).then((n) => {
47
- x(n.filter((o) => !!o));
40
+ Promise.all(r).then((i) => {
41
+ x(i.filter((o) => !!o));
48
42
  });
49
43
  });
50
- }, [t, d, e, r]), l.length ? /* @__PURE__ */ a(
44
+ }, [t, d, e, c]), m.length ? /* @__PURE__ */ a(
51
45
  j,
52
46
  {
53
47
  className: "humany-bot-contact-list",
54
- contactMethods: l,
48
+ contactMethods: m,
55
49
  dispatch: g,
56
- itemRenderer: (i, c) => (r.includes(i.id) || i.expanded) && i.inline || i.clientName === "custom.link" ? /* @__PURE__ */ a(
50
+ itemRenderer: (n, r) => (c.includes(n.id) || n.expanded) && n.inline || n.clientName === "custom.link" ? /* @__PURE__ */ a(
57
51
  z,
58
52
  {
59
- contactMethodId: i.id,
53
+ contactMethodId: n.id,
60
54
  groupId: y,
61
- guideId: i.body.guideId
55
+ guideId: n.body.guideId
62
56
  }
63
- ) : /* @__PURE__ */ a(I, { ...i, ...c })
57
+ ) : /* @__PURE__ */ a(I, { ...n, ...r })
64
58
  }
65
59
  ) : null;
66
- }, j = m(M)`
60
+ }, j = l(M)`
67
61
  > ul > li {
68
62
  a {
69
63
  display: flex;
@@ -75,7 +69,7 @@ const F = ({ actions: t, entryId: e, groupId: y }) => {
75
69
  ${(t) => t.theme.border && `border-bottom: ${t.theme.border};`}
76
70
  }
77
71
  }
78
- `, z = m(S)`
72
+ `, z = l(S)`
79
73
  i {
80
74
  margin: 0 ${(t) => {
81
75
  var e;
@@ -85,7 +79,7 @@ const F = ({ actions: t, entryId: e, groupId: y }) => {
85
79
  justify-content: center;
86
80
  align-items: center;
87
81
  }
88
- `, I = m($)`
82
+ `, I = l($)`
89
83
  padding: ${(t) => {
90
84
  var e;
91
85
  return (e = t.theme.sizes) == null ? void 0 : e.medium;
@@ -101,5 +95,5 @@ const F = ({ actions: t, entryId: e, groupId: y }) => {
101
95
  }
102
96
  `;
103
97
  export {
104
- F as default
98
+ P as default
105
99
  };
@@ -0,0 +1,25 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),r=require("@emotion/styled"),o=require("@telia-ace/knowledge-widget-ui"),m=require("./styles-B0Dr69xO.js"),u=({title:e,messageId:t,actions:a})=>{const c=o.useContainer(),{events:l}=c.get("$widget"),d=o.useDispatch(),i=document.createElement("div");return i.innerHTML=e,e=i.innerText,n.jsxs(n.Fragment,{children:[n.jsx("p",{id:t,children:e}),n.jsx(h,{className:"humany-bot-feedback-list",role:"group","aria-labelledby":t,items:a,"data-direction":"vertical",renderItem:s=>n.jsx("li",{children:n.jsxs(y,{className:"humany-feedback-button",disabled:!1,"data-selected":!0,onClick:()=>{d("action",s.actionKey),l.dispatch("tracking:feedback-given-bot",{feedbackResponse:s.actionKey})},children:[n.jsx(o.Icon,{faIcon:s.actionKey==="yes"?"smile-o":"frown-o"}),n.jsx("span",{children:s.label})]})},s.actionKey)})]})},h=r(o.List)`
2
+ ${e=>o.list(e)}
3
+ ${m.messageContentPadding}
4
+ display: flex;
5
+ gap: ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.normal}};
6
+ flex-direction: ${e=>e["data-direction"]==="horizontal"?"row":"column"};
7
+ > li {
8
+ flex: 1;
9
+ margin: 0;
10
+ }
11
+ `,y=r(o.Button)`
12
+ ${o.buttonCss}
13
+ font-size: ${e=>{var t;return(t=e.theme.fonts)==null?void 0:t.normal}};
14
+ border-color: ${e=>{var t;return(t=e.theme.colors)==null?void 0:t.primary}};
15
+ font-weight: 300;
16
+ display: block;
17
+ width: 100%;
18
+
19
+ ${e=>{var t;return o.invertedHoverButton({primaryColor:`${(t=e.theme.colors)==null?void 0:t.primary}`,secondaryColor:"#FFFFFF",theme:e.theme})}}
20
+ i {
21
+ margin: 0 ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.small}} 0 0;
22
+ }
23
+ span {
24
+ }
25
+ `;exports.default=u;
@@ -1,11 +1,10 @@
1
- import { jsxs as a, Fragment as m, jsx as n } from "react/jsx-runtime";
1
+ import { jsxs as r, Fragment as m, jsx as n } from "react/jsx-runtime";
2
2
  import i from "@emotion/styled";
3
- import { useContainer as h, useDispatch as p, Icon as f, List as u, list as b, Button as y, buttonCss as g, invertedHoverButton as $ } from "@telia-ace/knowledge-widget-ui";
4
- import { m as k } from "./styles-5f6d3622.mjs";
5
- import "@emotion/react";
6
- const K = ({ title: e, messageId: t, actions: s }) => {
7
- const c = h(), { events: l } = c.get("$widget"), d = p(), r = document.createElement("div");
8
- return r.innerHTML = e, e = r.innerText, /* @__PURE__ */ a(m, { children: [
3
+ import { useContainer as h, useDispatch as f, Icon as p, list as u, List as b, buttonCss as y, invertedHoverButton as g, Button as $ } from "@telia-ace/knowledge-widget-ui";
4
+ import { m as k } from "./styles-DU_GlYeu.mjs";
5
+ const B = ({ title: e, messageId: t, actions: s }) => {
6
+ const c = h(), { events: l } = c.get("$widget"), d = f(), a = document.createElement("div");
7
+ return a.innerHTML = e, e = a.innerText, /* @__PURE__ */ r(m, { children: [
9
8
  /* @__PURE__ */ n("p", { id: t, children: e }),
10
9
  /* @__PURE__ */ n(
11
10
  F,
@@ -15,7 +14,7 @@ const K = ({ title: e, messageId: t, actions: s }) => {
15
14
  "aria-labelledby": t,
16
15
  items: s,
17
16
  "data-direction": "vertical",
18
- renderItem: (o) => /* @__PURE__ */ n("li", { children: /* @__PURE__ */ a(
17
+ renderItem: (o) => /* @__PURE__ */ n("li", { children: /* @__PURE__ */ r(
19
18
  x,
20
19
  {
21
20
  className: "humany-feedback-button",
@@ -28,7 +27,7 @@ const K = ({ title: e, messageId: t, actions: s }) => {
28
27
  },
29
28
  children: [
30
29
  /* @__PURE__ */ n(
31
- f,
30
+ p,
32
31
  {
33
32
  faIcon: o.actionKey === "yes" ? "smile-o" : "frown-o"
34
33
  }
@@ -40,8 +39,8 @@ const K = ({ title: e, messageId: t, actions: s }) => {
40
39
  }
41
40
  )
42
41
  ] });
43
- }, F = i(u)`
44
- ${(e) => b(e)}
42
+ }, F = i(b)`
43
+ ${(e) => u(e)}
45
44
  ${k}
46
45
  display: flex;
47
46
  gap: ${(e) => {
@@ -53,8 +52,8 @@ const K = ({ title: e, messageId: t, actions: s }) => {
53
52
  flex: 1;
54
53
  margin: 0;
55
54
  }
56
- `, x = i(y)`
57
- ${g}
55
+ `, x = i($)`
56
+ ${y}
58
57
  font-size: ${(e) => {
59
58
  var t;
60
59
  return (t = e.theme.fonts) == null ? void 0 : t.normal;
@@ -69,7 +68,7 @@ const K = ({ title: e, messageId: t, actions: s }) => {
69
68
 
70
69
  ${(e) => {
71
70
  var t;
72
- return $({
71
+ return g({
73
72
  primaryColor: `${(t = e.theme.colors) == null ? void 0 : t.primary}`,
74
73
  secondaryColor: "#FFFFFF",
75
74
  theme: e.theme
@@ -85,5 +84,5 @@ const K = ({ title: e, messageId: t, actions: s }) => {
85
84
  }
86
85
  `;
87
86
  export {
88
- K as default
87
+ B as default
89
88
  };
@@ -1,6 +1,6 @@
1
1
  var F = Object.defineProperty;
2
2
  var G = (s, t, e) => t in s ? F(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var f = (s, t, e) => (G(s, typeof t != "symbol" ? t + "" : t, e), e);
3
+ var f = (s, t, e) => G(s, typeof t != "symbol" ? t + "" : t, e);
4
4
  import { ConversationMessageListItemType as v, ConversationPlatform as T, registerCustomMessageComponent as N } from "@telia-ace/widget-conversation";
5
5
  import { readStorage as U, createStorageWriter as P, StorageCategory as B } from "@telia-ace/widget-services";
6
6
  import { uuid as K } from "@telia-ace/widget-utilities";
@@ -40,7 +40,7 @@ const j = (s) => {
40
40
  form: g,
41
41
  description: M
42
42
  }, w = {}) => {
43
- const { adapter: c } = n || { Adapter: {} }, {
43
+ const { adapter: c } = n || {}, {
44
44
  clientName: o = "",
45
45
  settings: h = {},
46
46
  customClientName: y = ""
@@ -741,8 +741,7 @@ class X {
741
741
  });
742
742
  }
743
743
  const n = (await this.container.getAsync("components")).components().ofType("widget-header").select();
744
- if (!n)
745
- return;
744
+ if (!n) return;
746
745
  const i = await this.container.get("settings"), a = i == null ? void 0 : i.components["widget-header"], r = (o = (c = a == null ? void 0 : a.properties) == null ? void 0 : c.actions) == null ? void 0 : o.avatar, g = (h = a == null ? void 0 : a.properties) == null ? void 0 : h.header, M = (y = a == null ? void 0 : a.properties) == null ? void 0 : y.tagline, w = {};
747
746
  !g && (t != null && t.heading) && (w.header = t.heading), !M && (t != null && t.tagline) && (w.tagline = t.tagline), !r && ((l = t == null ? void 0 : t.agent) != null && l.avatar) && (w.actions = {
748
747
  avatar: {
@@ -760,23 +759,23 @@ const it = async (s) => {
760
759
  N(
761
760
  s,
762
761
  m.ContactList,
763
- import("./contact-method-list-394c8856.mjs")
762
+ import("./contact-method-list-Beab6Xhp.mjs")
764
763
  ), N(
765
764
  s,
766
765
  m.ContactMethod,
767
- import("./contact-method-493fca20.mjs")
766
+ import("./contact-method-B2iMHgUU.mjs")
768
767
  ), N(
769
768
  s,
770
769
  m.NotificationList,
771
- import("./notification-list-3e483308.mjs")
770
+ import("./notification-list-D7mYuPM3.mjs")
772
771
  ), N(
773
772
  s,
774
773
  m.NoGoodAlternative,
775
- import("./no-good-alternative-c6825c80.mjs")
774
+ import("./no-good-alternative-DzoAFy4p.mjs")
776
775
  ), N(
777
776
  s,
778
777
  m.FeedbackList,
779
- import("./feedback-list-e2391688.mjs")
778
+ import("./feedback-list-kWYlxaOZ.mjs")
780
779
  ), t.registerProvider("ace-knowledge-bot", (e, n) => {
781
780
  const i = new X(
782
781
  s,
@@ -0,0 +1 @@
1
+ "use strict";var R=Object.defineProperty;var H=(n,t,e)=>t in n?R(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var y=(n,t,e)=>H(n,typeof t!="symbol"?t+"":t,e);const p=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=(n=>(n.ContactMethod="ace-knowledge-bot-contact-method",n.ContactList="ace-knowledge-bot-contact-list",n.FeedbackList="ace-knowledge-bot-feedback-list",n.NotificationList="ace-knowledge-bot-notification-list",n.NoGoodAlternative="ace-knowledge-bot-no-good-alternative",n))(f||{});const $=n=>{if(n){const{type:t,content:e}=n;if(t&&e)return{type:t,content:e}}},B=({isUser:n,items:t=[],meta:e={}})=>{const s=K.uuid();return{id:s,isUser:n,items:t.map(a=>({id:a.id||K.uuid(),isUser:n,groupId:s,message:a.message||[]})),meta:e}},U=({id:n,title:t,defaultIcon:e,exits:[s],exitType:i,confirmationText:a,expandFormAutomatically:c,form:h,description:E},S={})=>{const{adapter:r}=s||{},{clientName:o="",settings:g={},customClientName:v=""}=r,{validation:l}=S,d={id:n.toString(),title:t,description:E,symbol:$(e),clientName:o==="custom.adapter"?v:o,expanded:!0,inline:!0,body:{}};if(o.indexOf("phone")>-1||o.indexOf("freetext")>-1){const{displayTextBeforeClick:L,textBeforeClick:m}=g;L==="true"&&(d.expanded=!1,d.title=m),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"&&i==="custom")&&(d.body=g,d.body.confirmationFallback=a),o.indexOf("ace")>-1&&(d.body=g),h&&h.hasValueComponents&&(l?d.body.form=P.FormBuilder.fromLegacyForm(n.toString(),h,l).get():d.body.form=P.FormBuilder.fromLegacyForm(n.toString(),h).get(),c||(d.expanded=d.inline=!1),d.body=A(d,{submit:"Submit"})),S.guideId&&(d.body.guideId=S.guideId),d},G=n=>{const{localState:t}=n;return n.tags.includes("category")&&n.tags.includes("contact")?p.ConversationMessageListItemType.ItemList:n.tags.includes("suggestion")||(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching"?p.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:p.ConversationMessageListItemType.ButtonList},q=(n,t)=>{const{knowledgeBotEndpoint:e}=t.properties();if(e)return`${e}/conversations`;const{data:s}=n.get("$settings");if(!s||!s.projection)throw new Error("Missing Knowledge Bot endpoint");return`${s.projection}/conversations`},A=(n,{submit:t,errors:e,meta:s})=>{var i;if((i=n==null?void 0:n.body)!=null&&i.form){const{body:a}=n,c=new P.FormBuilder(a.form);return a.form.layout.submit||c.createComponent(P.submitButton(t,"submit")),e&&c.setValidationErrors(e),s&&c.setMeta(s),{...a,form:c.get()}}return(n==null?void 0:n.body)||{}},O=async(n,t,e)=>{(await(await n.getAsync("dataClient")).getClient()).parameters.set(t,e)},b=({messageId:n,message:t,group:e})=>({id:n,message:t,groupId:e.id,isUser:e.isUser}),V=async(n,t,e)=>{const s=(r,o,g,v={actions:[],entryId:o.id,groupId:g})=>{const l=[];return v.actions=o.content.items.map(d=>{var m;const L={label:d.title,actionKey:d.actionKey,symbol:d.symbol?d.symbol:void 0,description:d.description||void 0};if(d.data){const w=o.actions[d.actionKey];r===f.ContactList?(l.push(d.data.id),L.data=U(d.data,{guideId:(m=w==null?void 0:w.guideId)==null?void 0:m.toString()})):L.data=d.data}return L}),r===f.ContactList&&(v.contactMethodIds=l),v},i=async(r,o,g=[],v)=>{var d,L;const l=K.uuid();switch(r.type!=="List"&&r.tags.includes("guide")&&((L=(d=r.content.hints)==null?void 0:d[0])!=null&&L.id)&&await O(n,"LastGuideId",r.content.hints[0].id),r.type){case"List":{const{header:m,items:w,html:x}=r.content,M=[];let C={actions:[],entryId:r.id,groupId:o.id};if(C.tags=r.tags||null,m&&(C.header=m),(w==null?void 0:w.length)>0){const u=G(r);if(C=s(u,r,o.id,C),g.length){const I=g.find(k=>k.tags.includes("paging")),T=g.find(k=>k.tags.includes("fallback"));if(I!=null&&I.content&&(o.meta.paging={actions:I.actions,items:I.content.items,localState:I.localState},I.content.items.forEach(k=>{C.actions.push({label:k.title,actionKey:k.actionKey,data:{groupId:v?v.id:o.id}})})),T){const k=T.content.items.find(F=>F.actionKey==="help");k&&(M.push(b({messageId:l,message:[p.ConversationMessageListItemType.Separator,void 0],group:o})),M.push(b({messageId:l,message:[f.NoGoodAlternative,{body:k.title}],group:o})))}}M.unshift(b({messageId:l,message:[u,C],group:o}))}return x&&M.unshift(b({messageId:l,message:[p.ConversationMessageListItemType.HTML,{body:x}],group:o})),M}case"Text":{const m=[];if(m.push(b({messageId:l,message:[p.ConversationMessageListItemType.HTML,{body:r.content.html}],group:o})),g.length){const w=g.find(u=>{var I;return u.type==="List"&&((I=u.localState)==null?void 0:I.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"}),x=g.find(u=>u.tags.includes("dialog")),M=g.find(u=>u.tags.includes("feedback")),C=g.find(u=>u.tags.includes("contact")&&u.type==="Contact");if(C&&m.push(b({messageId:l,message:[f.ContactMethod,{contactMethodId:C.content.id,groupId:o.id,guideId:C.content.guideId}],group:o})),x&&m.push(b({messageId:l,message:[p.ConversationMessageListItemType.ButtonList,{actions:x.content.items.map(u=>({label:u.title,actionKey:u.actionKey,data:u.data}))}],group:o})),w){const u=s(f.ContactList,w,o.id);m.push(b({messageId:l,message:[p.ConversationMessageListItemType.Separator,void 0],group:o})),m.push(b({messageId:l,message:[f.ContactList,u],group:o}))}M&&m.push(b({messageId:l,group:o,message:[f.FeedbackList,{title:M.content.html,messageId:l,actions:M.content.items.map(u=>({actionKey:u.actionKey,label:u.title}))}]}))}return m}case"Contact":return[b({messageId:l,message:[f.ContactMethod,{contactMethodId:r.content.id,groupId:o.id,guideId:r.content.guideId}],group:o})];case"CategorizedNoticeList":{const m=[b({messageId:l,message:[f.NotificationList,{id:r.content.item.id.toString(),header:r.content.item.title,items:r.content.item.listNotices,symbol:r.content.item.defaultIcon}],group:o})];return(r.content.notices||[]).forEach(w=>{m.push(b({messageId:l,message:[p.ConversationMessageListItemType.HTML,{body:w.body}],group:o}))}),m}case"footerNotice":return[b({messageId:l,message:[p.ConversationMessageListItemType.HTML,{body:r.content.item.body}],group:o})];case"Error":return[b({messageId:l,message:[p.ConversationMessageListItemType.HTML,{body:r.content.message||"Something went wrong."}],group:o})];default:return[]}},a=r=>["CategorizedNoticeList","NoticeList"].includes(r.type)?(r.content.items||[]).reduce((o,g)=>(r.content.isInitialNotices&&o.push({...r,id:K.uuid(),type:g.type||r.type,content:{$type:r.content.$type,isInitialNotices:r.content.isInitialNotices,notices:g.notices,item:g}}),o),[]):r,c=new Map([["Text",1],["List",2],["Contact",3],["CategorizedNoticeList",10]]),h=[],E=t.sort((r,o)=>{const v=c.get(r.type)||20,l=c.get(o.type)||20;return v-l}).filter(r=>!r.relation).reduce((r,o)=>r.concat(a(o)),[]),S=r=>typeof r.actions.selector<"u";for(const r of E){const o=t.filter(l=>l.relation===r.id&&!S(l)),g=B({isUser:!1});(await i(r,g,o,e)).forEach(l=>{g.items.push(l)}),g.items.length&&h.push(g)}return h};class j{constructor(t,e,s,i){y(this,"globalState");y(this,"localState");y(this,"clientId");y(this,"entries");this.endpoint=t,this.events=e,this.store=s,this.container=i,this.clientId=K.uuid(),this.entries=[]}async start({silent:t}){const e=await this.store.read("globalState"),s=await this.store.read("localState"),i=await this.store.read("entries");if(this.globalState=e||this.globalState,this.localState=s||this.localState,this.entries=i||this.entries,t)return;const a=this.createInitialEnvelope();return await this.postEnvelope(a)}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(i=>{const a=t.items.findIndex(c=>c.message[0]==="link-list");return a===-1||!i?t:{...t,meta:{...t.meta,...i[0].meta},items:[...t.items.slice(0,a),{...t.items[a],message:[i[0].items[0].message[0],{...t.items[a].message[1],...i[0].items[0].message[1]}]},...t.items.slice(a+1)]}})}async showContactMethodAction(t){const e=this.entries.find(i=>i.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 i=await s.json();return this.handleResponse(i,e)}catch(s){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let i="Something went wrong";return(s.message==="Failed to fetch"||s.message==="NetworkError when attempting to fetch resource.")&&(i="Lost connection... Please try again."),this.events.dispatch("tracking:http-client-error",{message:i,error:s}),this.handleResponse({entries:[{id:K.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:i},actions:{},tags:[]}]})}}async handleResponse(t,e){this.entries=this.entries.concat(t.entries),this.store.write(this.entries,"entries");const s=t.entries.find(a=>a.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((a,c)=>c.localState?c.localState:a,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:i}=this.container.get("$widget");this.events=i,this.store=new z(t),this.agent=e.createAgent({id:"knowledge-bot-agent",name:"",avatar:void 0}),this.user=e.user;const a=q(t,s);this.httpClient=new j(a,i,this.store,this.container),this.events.subscribe("provider:widget-entry",(c,h)=>{this.onWidgetEntryReceived(h)}),this.events.subscribe("provider:open-contact-method",async(c,h)=>{const E=await this.httpClient.showContactMethodAction(h);E&&(h.contactMethod.title&&this.printUserMessage(h.contactMethod.title),this.onMessagesReceived(E))})}async initialize(){var a;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(),i=await this.httpClient.start({silent:((a=this.conversation.options)==null?void 0:a.silent)||s});i&&this.onMessagesReceived(i),t()}async onMessagesReceived(t){this.groups=this.groups.concat(t),t.forEach(e=>{const s=e.items.map(i=>i.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(i=>{var a;return i.id===((a=t.data)==null?void 0:a.groupId)});if(s){const i=await this.httpClient.nextAction(s);if(i){const a=i.items.map(c=>c.message);s.meta.paging=i==null?void 0:i.meta.paging,s.writer.update(a)}}}break;case"help":{const s=this.conversation.loading(),i=await this.httpClient.helpAction();s(),i&&this.onMessagesReceived(i)}break;default:{typeof t!="string"&&t.label&&this.printUserMessage(t.label);const s=this.conversation.loading(),i=await this.httpClient.defaultAction(e);i&&this.onMessagesReceived(i),s()}break}}printUserMessage(t){const e=B({isUser:!0,items:[{id:K.uuid(),isUser:!0,message:[p.ConversationMessageListItemType.HTML,{body:t}]}]});return this.onMessagesReceived([e]),e}async onMessageSend(t){const e=this.conversation.loading(),s=await this.httpClient.sendMessage(t);await O(this.container,"phrase",t),this.printUserMessage(t),s&&this.onMessagesReceived(s),e()}async onWidgetEntryReceived(t){var r,o,g,v,l;if(t.agent){const d={name:t.agent.name,avatar:t.agent.avatar};this.agent.update(d),(await N.createStorageWriter(this.container,"bot-provider-conversation-meta",N.StorageCategory.Necessary))({agent:d})}const s=(await this.container.getAsync("components")).components().ofType("widget-header").select();if(!s)return;const i=await this.container.get("settings"),a=i==null?void 0:i.components["widget-header"],c=(o=(r=a==null?void 0:a.properties)==null?void 0:r.actions)==null?void 0:o.avatar,h=(g=a==null?void 0:a.properties)==null?void 0:g.header,E=(v=a==null?void 0:a.properties)==null?void 0:v.tagline,S={};!h&&(t!=null&&t.heading)&&(S.header=t.heading),!E&&(t!=null&&t.tagline)&&(S.tagline=t.tagline),!c&&((l=t==null?void 0:t.agent)!=null&&l.avatar)&&(S.actions={avatar:{position:"left",symbol:{type:"Uri",content:t.agent.avatar}}}),Object.keys(S).length>0&&s.writeProperties(S)}}const _=async n=>{const t=await p.ConversationPlatform.getInstance(n);p.registerCustomMessageComponent(n,f.ContactList,Promise.resolve().then(()=>require("./contact-method-list-BI5sXyex.js"))),p.registerCustomMessageComponent(n,f.ContactMethod,Promise.resolve().then(()=>require("./contact-method-bGgHBWcr.js"))),p.registerCustomMessageComponent(n,f.NotificationList,Promise.resolve().then(()=>require("./notification-list-BG4xAMsg.js"))),p.registerCustomMessageComponent(n,f.NoGoodAlternative,Promise.resolve().then(()=>require("./no-good-alternative-_ZVxoVd9.js"))),p.registerCustomMessageComponent(n,f.FeedbackList,Promise.resolve().then(()=>require("./feedback-list-DgaoNq6f.js"))),t.registerProvider("ace-knowledge-bot",(e,s)=>{const i=new W(n,e,s);i.initialize();const a=[];return a.push(s.actions.watch("conversation.user-submit",(c,h)=>{i.onMessageSend(c.text)})),a.push(s.actions.watch("conversation.action",(c,h)=>(i.onInput(c),h(c)))),a.push(s.actions.create("evaluate",c=>{const{events:h}=n.get("$widget");h.dispatch("bot-provider:evaluate",c)})),a.push(s.actions.create("submit",c=>{const{events:h}=n.get("$widget");h.dispatch("bot-provider:form-submitted",c)})),()=>{a.forEach(c=>{c()})}})};exports.KnowledgeBotProviderPlugin=_;exports.updateForm=A;
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-dc30edd3.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-UFpIz4f_.js");exports.ConversationPlugin=e.KnowledgeBotProviderPlugin;
package/index.mjs CHANGED
@@ -1,8 +1,4 @@
1
- import { K as n } from "./index-a559356e.mjs";
2
- import "@telia-ace/widget-conversation";
3
- import "@telia-ace/widget-services";
4
- import "@telia-ace/widget-utilities";
5
- import "@telia-ace/widget-forms";
1
+ import { K as r } from "./index-BnOsK3l6.mjs";
6
2
  export {
7
- n as ConversationPlugin
3
+ r as ConversationPlugin
8
4
  };
@@ -1,12 +1,11 @@
1
- import { jsx as o, jsxs as i } from "react/jsx-runtime";
1
+ import { jsx as o, jsxs as n } from "react/jsx-runtime";
2
2
  import s from "@emotion/styled";
3
- import { useDispatch as n, SymbolBadge as r, Button as a, borderTabStyle as l } from "@telia-ace/knowledge-widget-ui";
4
- import { m } from "./styles-5f6d3622.mjs";
5
- import "@emotion/react";
6
- const y = ({ body: t }) => {
7
- const e = n();
8
- return /* @__PURE__ */ o(c, { className: "humany-bot-no-good-alternative", children: /* @__PURE__ */ i(
9
- p,
3
+ import { useDispatch as i, SymbolBadge as a, borderTabStyle as r, Button as l } from "@telia-ace/knowledge-widget-ui";
4
+ import { m } from "./styles-DU_GlYeu.mjs";
5
+ const u = ({ body: t }) => {
6
+ const e = i();
7
+ return /* @__PURE__ */ o(c, { className: "humany-bot-no-good-alternative", children: /* @__PURE__ */ n(
8
+ d,
10
9
  {
11
10
  onClick: () => {
12
11
  e("action", "help");
@@ -15,7 +14,7 @@ const y = ({ body: t }) => {
15
14
  title: t,
16
15
  children: [
17
16
  /* @__PURE__ */ o(
18
- r,
17
+ a,
19
18
  {
20
19
  size: 14,
21
20
  symbol: {
@@ -33,7 +32,7 @@ const y = ({ body: t }) => {
33
32
  align-items: center;
34
33
  justify-content: center;
35
34
  ${m}
36
- `, p = s(a)`
35
+ `, d = s(l)`
37
36
  > i,
38
37
  svg {
39
38
  margin-right: ${(t) => {
@@ -43,9 +42,9 @@ const y = ({ body: t }) => {
43
42
  }
44
43
 
45
44
  &:focus-visible {
46
- ${l}
45
+ ${r}
47
46
  }
48
47
  `;
49
48
  export {
50
- y as default
49
+ u as default
51
50
  };
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),i=require("@emotion/styled"),n=require("@telia-ace/knowledge-widget-ui"),o=require("./styles-66aa2377.js");require("@emotion/react");const r=({body:e})=>{const t=n.useDispatch();return s.jsx(l,{className:"humany-bot-no-good-alternative",children:s.jsxs(a,{onClick:()=>{t("action","help")},"aria-label":e,title:e,children:[s.jsx(n.SymbolBadge,{size:14,symbol:{type:"FontAwesome",content:"meh-o"}}),s.jsx("span",{children:e})]})})},l=i.div`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),i=require("@emotion/styled"),n=require("@telia-ace/knowledge-widget-ui"),o=require("./styles-B0Dr69xO.js"),l=({body:e})=>{const t=n.useDispatch();return s.jsx(r,{className:"humany-bot-no-good-alternative",children:s.jsxs(a,{onClick:()=>{t("action","help")},"aria-label":e,title:e,children:[s.jsx(n.SymbolBadge,{size:14,symbol:{type:"FontAwesome",content:"meh-o"}}),s.jsx("span",{children:e})]})})},r=i.div`
2
2
  display: flex;
3
3
  align-items: center;
4
4
  justify-content: center;
@@ -12,4 +12,4 @@
12
12
  &:focus-visible {
13
13
  ${n.borderTabStyle}
14
14
  }
15
- `;exports.default=r;
15
+ `;exports.default=l;
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),d=require("@emotion/styled"),c=require("@telia-ace/knowledge-widget-ui"),u=require("@telia-ace/widget-utilities"),f=require("react"),g=require("./styles-B0Dr69xO.js"),m=({id:i,header:t,items:o,symbol:s,className:r,...a})=>{const n=f.useMemo(()=>({id:i,title:t,symbol:s,defaultHeaderOptions:{visible:!0},notifications:o.map(e=>({id:e.id.toString(),title:e.title,body:e.body,modified:e.modified,expandable:!0}))}),[t,o]);return n?l.jsx(y,{className:u.appendClassNames("humany-bot-notification-list",r),showHeader:!0,notificationList:n,loading:!1,...a}):null},y=d(c.NotificationList)`
2
+ ${g.messageContentPadding}
3
+ min-width: 10em;
4
+
5
+ span {
6
+ color: ${i=>{var t;return(t=i.theme.colors)==null?void 0:t.text}};
7
+ }
8
+ `;exports.default=m;
@@ -2,10 +2,9 @@ import { jsx as m } from "react/jsx-runtime";
2
2
  import d from "@emotion/styled";
3
3
  import { NotificationList as f } from "@telia-ace/knowledge-widget-ui";
4
4
  import { appendClassNames as l } from "@telia-ace/widget-utilities";
5
- import { useMemo as p } from "react";
6
- import { m as c } from "./styles-5f6d3622.mjs";
7
- import "@emotion/react";
8
- const $ = ({
5
+ import { useMemo as c } from "react";
6
+ import { m as p } from "./styles-DU_GlYeu.mjs";
7
+ const h = ({
9
8
  id: o,
10
9
  header: t,
11
10
  items: e,
@@ -13,7 +12,7 @@ const $ = ({
13
12
  className: a,
14
13
  ...r
15
14
  }) => {
16
- const s = p(() => ({
15
+ const s = c(() => ({
17
16
  id: o,
18
17
  title: t,
19
18
  symbol: n,
@@ -39,7 +38,7 @@ const $ = ({
39
38
  }
40
39
  ) : null;
41
40
  }, u = d(f)`
42
- ${c}
41
+ ${p}
43
42
  min-width: 10em;
44
43
 
45
44
  span {
@@ -50,5 +49,5 @@ const $ = ({
50
49
  }
51
50
  `;
52
51
  export {
53
- $ as default
52
+ h as default
54
53
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/knowledge-widget-bot-provider",
3
- "version": "1.3.41-rc.1",
3
+ "version": "1.3.41-rc.2",
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.3.41-rc.1",
14
- "@telia-ace/knowledge-widget-adapters": "^1.3.41-rc.1",
15
- "@telia-ace/knowledge-widget-ui": "^1.3.41-rc.1",
16
- "@telia-ace/widget-conversation": "^1.3.41-rc.1",
17
- "@telia-ace/widget-forms": "^1.3.41-rc.1",
18
- "@telia-ace/widget-services": "^1.3.41-rc.1",
19
- "@telia-ace/widget-utilities": "^1.3.41-rc.1",
13
+ "@telia-ace/knowledge-data-client": "^1.3.41-rc.2",
14
+ "@telia-ace/knowledge-widget-adapters": "^1.3.41-rc.2",
15
+ "@telia-ace/knowledge-widget-ui": "^1.3.41-rc.2",
16
+ "@telia-ace/widget-conversation": "^1.3.41-rc.2",
17
+ "@telia-ace/widget-forms": "^1.3.41-rc.2",
18
+ "@telia-ace/widget-services": "^1.3.41-rc.2",
19
+ "@telia-ace/widget-utilities": "^1.3.41-rc.2",
20
20
  "@webprovisions/platform": "^1.1.4",
21
- "@telia-ace/knowledge-widget-core": "^1.3.41-rc.1"
21
+ "@telia-ace/knowledge-widget-core": "^1.3.41-rc.2"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@emotion/react": "11.11.1",
package/utils.d.ts CHANGED
@@ -5,10 +5,8 @@ import { CustomMessageTypes, MessageGroup, MessageGroupItem, ServerEntry } from
5
5
 
6
6
  export declare const createGroup: ({ isUser, items, meta, }: {
7
7
  isUser: boolean;
8
- items?: Partial<MessageGroupItem>[] | undefined;
9
- meta?: {
10
- [key: string]: any;
11
- } | undefined;
8
+ items?: Partial<MessageGroupItem>[];
9
+ meta?: MessageGroup["meta"];
12
10
  }) => MessageGroup;
13
11
  export declare const contactMethodFromLegacy: ({ id, title, defaultIcon, exits: [exit], exitType, confirmationText, expandFormAutomatically, form, description, }: any, options?: {
14
12
  validation?: any;
@@ -20,9 +18,9 @@ export declare const updateForm: (contactMethod: ContactMethodType, { submit, er
20
18
  submit: string;
21
19
  errors?: {
22
20
  [key: string]: string;
23
- } | undefined;
21
+ };
24
22
  meta?: {
25
23
  [key: string]: string;
26
- } | undefined;
24
+ };
27
25
  }) => any;
28
26
  export declare const setServiceClientParameter: (container: Container, key: string, value: string) => Promise<void>;
@@ -1,3 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("react/jsx-runtime"),N=require("@emotion/styled"),F=require("@telia-ace/knowledge-data-client"),R=require("@telia-ace/knowledge-widget-adapters"),C=require("@telia-ace/knowledge-widget-ui"),$=require("@telia-ace/widget-forms"),z=require("@telia-ace/widget-utilities"),l=require("react"),x=require("./index-dc30edd3.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");const O=({contactMethodId:a,guideId:n,groupId:b,className:T})=>{var h,k,q,S,j;const[e,u]=l.useState(),c=C.useContainer(),A=C.useDispatch(),f=l.useRef(!0),y=C.useConversation();l.useEffect(()=>{const{events:t}=c.get("$widget"),m=t.subscribe("bot-provider:form-submitted",async(s,o)=>{var D;if(((D=o.form.meta)==null?void 0:D.groupId)!==b||o.id!==e.id)return;y&&(o.form.meta||(o.form.meta={}),o.form.meta.conversation=y);const p=await c.getAsync("contactMethods"),r={...e,body:{...e.body,form:o.form}},{errors:d,valid:g,errorTypes:W}=await p.validate(r);if(!g){const E=new $.FormBuilder(e.body.form);u(void 0),E.setValidationErrors(d),r.body={...r.body,form:E.get()},u({...r});return}const B=await p.submit(r);r.confirmation=B,u(r)}),i=t.subscribe("bot-provider:evaluate",async(s,o)=>{if(String(o.id)!==String(a))return;const r=await(await c.getAsync("contactMethods")).evaluate(e);let d={...e,body:{...e.body,form:r}};const g=x.updateForm(d,{submit:"Skicka",errors:{},meta:{groupId:b}});d={...d,body:g},u(d)});return()=>{m(),i()}},[c,e,u,y]);const v=(t,m,i=null)=>{if(t["ui:component"]&&t["ui:component"]==="Date")return Object.assign(t,{"ui:bot":!0,"ui:entrance":m}),t;for(const s in t)if(typeof t[s]=="object"&&t[s]!==null){const o=v(t[s],m,t);if(o!==void 0)return o}},w=l.useCallback(async t=>{const i=await(await F.DataClient.getInstance(c)).fetch(F.DataType.ContactMethod,{contactMethodId:t,guideId:n},{noCache:!0,isBot:!0}),s=x.updateForm(i,{submit:"Skicka",errors:{},meta:{groupId:b}});if(i.body=s,i.body.guideId=n,!f.current)return null;u(i)},[f]);return l.useEffect(()=>(w(a),()=>{f.current=!1}),[a,w]),e?(e.clientName==="ace.callback"&&((h=e.body)!=null&&h.entrance)&&v(e,(k=e.body)==null?void 0:k.entrance),M.jsx(U,{...e,body:{...e.body,form:e.body.form?{...e.body.form,data:(q=e.body.form)==null?void 0:q.data,layout:{...e.body.form.layout},meta:(S=e.body.form)==null?void 0:S.meta,schema:(j=e.body.form)==null?void 0:j.schema}:void 0,guideId:e.body.guideId},inline:!0,expanded:!0,dispatch:A,className:z.appendClassNames("humany-bot-contact-method",T)})):null},U=N(R.ContactMethod)`
2
- padding: ${a=>{var n;return(n=a.theme.sizes)==null?void 0:n.normal}} ${a=>{var n;return(n=a.theme.sizes)==null?void 0:n.medium}};
3
- `;exports.default=O;
@@ -1,28 +0,0 @@
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-abc31fb9.js");require("@telia-ace/knowledge-data-client");require("@telia-ace/widget-forms");require("@telia-ace/widget-utilities");require("./index-dc30edd3.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");const k=({actions:e,entryId:t,groupId:x})=>{const q=g.useDispatch(),d=g.useContainer(),[m,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 h;if(!((h=i.data)!=null&&h.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]),m.length?a.jsx(j,{className:"humany-bot-contact-list",contactMethods:m,dispatch:q,itemRenderer:(n,c)=>(o.includes(n.id)||n.expanded)&&n.inline||n.clientName==="custom.link"?a.jsx(S,{contactMethodId:n.id,groupId:x,guideId:n.body.guideId}):a.jsx($,{...n,...c})}):null},j=u(y.ContactList)`
2
- > ul > li {
3
- a {
4
- display: flex;
5
- align-items: center;
6
- outline-offset: -2px;
7
- }
8
-
9
- &:not(:last-child) {
10
- ${e=>e.theme.border&&`border-bottom: ${e.theme.border};`}
11
- }
12
- }
13
- `,S=u(b.default)`
14
- i {
15
- margin: 0 ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.medium}} 0 0;
16
- display: flex;
17
- justify-content: center;
18
- align-items: center;
19
- }
20
- `,$=u(y.ContactMethod)`
21
- padding: ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.medium}};
22
- i {
23
- margin: 0 ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.medium}} 0 0;
24
- display: flex;
25
- justify-content: center;
26
- align-items: center;
27
- }
28
- `;exports.default=k;
@@ -1,25 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),r=require("@emotion/styled"),o=require("@telia-ace/knowledge-widget-ui"),u=require("./styles-66aa2377.js");require("@emotion/react");const m=({title:e,messageId:t,actions:a})=>{const c=o.useContainer(),{events:l}=c.get("$widget"),d=o.useDispatch(),i=document.createElement("div");return i.innerHTML=e,e=i.innerText,n.jsxs(n.Fragment,{children:[n.jsx("p",{id:t,children:e}),n.jsx(h,{className:"humany-bot-feedback-list",role:"group","aria-labelledby":t,items:a,"data-direction":"vertical",renderItem:s=>n.jsx("li",{children:n.jsxs(y,{className:"humany-feedback-button",disabled:!1,"data-selected":!0,onClick:()=>{d("action",s.actionKey),l.dispatch("tracking:feedback-given-bot",{feedbackResponse:s.actionKey})},children:[n.jsx(o.Icon,{faIcon:s.actionKey==="yes"?"smile-o":"frown-o"}),n.jsx("span",{children:s.label})]})},s.actionKey)})]})},h=r(o.List)`
2
- ${e=>o.list(e)}
3
- ${u.messageContentPadding}
4
- display: flex;
5
- gap: ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.normal}};
6
- flex-direction: ${e=>e["data-direction"]==="horizontal"?"row":"column"};
7
- > li {
8
- flex: 1;
9
- margin: 0;
10
- }
11
- `,y=r(o.Button)`
12
- ${o.buttonCss}
13
- font-size: ${e=>{var t;return(t=e.theme.fonts)==null?void 0:t.normal}};
14
- border-color: ${e=>{var t;return(t=e.theme.colors)==null?void 0:t.primary}};
15
- font-weight: 300;
16
- display: block;
17
- width: 100%;
18
-
19
- ${e=>{var t;return o.invertedHoverButton({primaryColor:`${(t=e.theme.colors)==null?void 0:t.primary}`,secondaryColor:"#FFFFFF",theme:e.theme})}}
20
- i {
21
- margin: 0 ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.small}} 0 0;
22
- }
23
- span {
24
- }
25
- `;exports.default=m;
package/index-dc30edd3.js DELETED
@@ -1 +0,0 @@
1
- "use strict";var R=Object.defineProperty;var H=(n,t,e)=>t in n?R(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var y=(n,t,e)=>(H(n,typeof t!="symbol"?t+"":t,e),e);const p=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=(n=>(n.ContactMethod="ace-knowledge-bot-contact-method",n.ContactList="ace-knowledge-bot-contact-list",n.FeedbackList="ace-knowledge-bot-feedback-list",n.NotificationList="ace-knowledge-bot-notification-list",n.NoGoodAlternative="ace-knowledge-bot-no-good-alternative",n))(f||{});const $=n=>{if(n){const{type:t,content:e}=n;if(t&&e)return{type:t,content:e}}},A=({isUser:n,items:t=[],meta:e={}})=>{const s=K.uuid();return{id:s,isUser:n,items:t.map(a=>({id:a.id||K.uuid(),isUser:n,groupId:s,message:a.message||[]})),meta:e}},U=({id:n,title:t,defaultIcon:e,exits:[s],exitType:i,confirmationText:a,expandFormAutomatically:c,form:h,description:E},S={})=>{const{adapter:r}=s||{Adapter:{}},{clientName:o="",settings:g={},customClientName:v=""}=r,{validation:l}=S,d={id:n.toString(),title:t,description:E,symbol:$(e),clientName:o==="custom.adapter"?v:o,expanded:!0,inline:!0,body:{}};if(o.indexOf("phone")>-1||o.indexOf("freetext")>-1){const{displayTextBeforeClick:L,textBeforeClick:m}=g;L==="true"&&(d.expanded=!1,d.title=m),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"&&i==="custom")&&(d.body=g,d.body.confirmationFallback=a),o.indexOf("ace")>-1&&(d.body=g),h&&h.hasValueComponents&&(l?d.body.form=P.FormBuilder.fromLegacyForm(n.toString(),h,l).get():d.body.form=P.FormBuilder.fromLegacyForm(n.toString(),h).get(),c||(d.expanded=d.inline=!1),d.body=B(d,{submit:"Submit"})),S.guideId&&(d.body.guideId=S.guideId),d},G=n=>{const{localState:t}=n;return n.tags.includes("category")&&n.tags.includes("contact")?p.ConversationMessageListItemType.ItemList:n.tags.includes("suggestion")||(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching"?p.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:p.ConversationMessageListItemType.ButtonList},q=(n,t)=>{const{knowledgeBotEndpoint:e}=t.properties();if(e)return`${e}/conversations`;const{data:s}=n.get("$settings");if(!s||!s.projection)throw new Error("Missing Knowledge Bot endpoint");return`${s.projection}/conversations`},B=(n,{submit:t,errors:e,meta:s})=>{var i;if((i=n==null?void 0:n.body)!=null&&i.form){const{body:a}=n,c=new P.FormBuilder(a.form);return a.form.layout.submit||c.createComponent(P.submitButton(t,"submit")),e&&c.setValidationErrors(e),s&&c.setMeta(s),{...a,form:c.get()}}return(n==null?void 0:n.body)||{}},O=async(n,t,e)=>{(await(await n.getAsync("dataClient")).getClient()).parameters.set(t,e)},b=({messageId:n,message:t,group:e})=>({id:n,message:t,groupId:e.id,isUser:e.isUser}),V=async(n,t,e)=>{const s=(r,o,g,v={actions:[],entryId:o.id,groupId:g})=>{const l=[];return v.actions=o.content.items.map(d=>{var m;const L={label:d.title,actionKey:d.actionKey,symbol:d.symbol?d.symbol:void 0,description:d.description||void 0};if(d.data){const w=o.actions[d.actionKey];r===f.ContactList?(l.push(d.data.id),L.data=U(d.data,{guideId:(m=w==null?void 0:w.guideId)==null?void 0:m.toString()})):L.data=d.data}return L}),r===f.ContactList&&(v.contactMethodIds=l),v},i=async(r,o,g=[],v)=>{var d,L;const l=K.uuid();switch(r.type!=="List"&&r.tags.includes("guide")&&((L=(d=r.content.hints)==null?void 0:d[0])!=null&&L.id)&&await O(n,"LastGuideId",r.content.hints[0].id),r.type){case"List":{const{header:m,items:w,html:x}=r.content,M=[];let C={actions:[],entryId:r.id,groupId:o.id};if(C.tags=r.tags||null,m&&(C.header=m),(w==null?void 0:w.length)>0){const u=G(r);if(C=s(u,r,o.id,C),g.length){const I=g.find(k=>k.tags.includes("paging")),T=g.find(k=>k.tags.includes("fallback"));if(I!=null&&I.content&&(o.meta.paging={actions:I.actions,items:I.content.items,localState:I.localState},I.content.items.forEach(k=>{C.actions.push({label:k.title,actionKey:k.actionKey,data:{groupId:v?v.id:o.id}})})),T){const k=T.content.items.find(F=>F.actionKey==="help");k&&(M.push(b({messageId:l,message:[p.ConversationMessageListItemType.Separator,void 0],group:o})),M.push(b({messageId:l,message:[f.NoGoodAlternative,{body:k.title}],group:o})))}}M.unshift(b({messageId:l,message:[u,C],group:o}))}return x&&M.unshift(b({messageId:l,message:[p.ConversationMessageListItemType.HTML,{body:x}],group:o})),M}case"Text":{const m=[];if(m.push(b({messageId:l,message:[p.ConversationMessageListItemType.HTML,{body:r.content.html}],group:o})),g.length){const w=g.find(u=>{var I;return u.type==="List"&&((I=u.localState)==null?void 0:I.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"}),x=g.find(u=>u.tags.includes("dialog")),M=g.find(u=>u.tags.includes("feedback")),C=g.find(u=>u.tags.includes("contact")&&u.type==="Contact");if(C&&m.push(b({messageId:l,message:[f.ContactMethod,{contactMethodId:C.content.id,groupId:o.id,guideId:C.content.guideId}],group:o})),x&&m.push(b({messageId:l,message:[p.ConversationMessageListItemType.ButtonList,{actions:x.content.items.map(u=>({label:u.title,actionKey:u.actionKey,data:u.data}))}],group:o})),w){const u=s(f.ContactList,w,o.id);m.push(b({messageId:l,message:[p.ConversationMessageListItemType.Separator,void 0],group:o})),m.push(b({messageId:l,message:[f.ContactList,u],group:o}))}M&&m.push(b({messageId:l,group:o,message:[f.FeedbackList,{title:M.content.html,messageId:l,actions:M.content.items.map(u=>({actionKey:u.actionKey,label:u.title}))}]}))}return m}case"Contact":return[b({messageId:l,message:[f.ContactMethod,{contactMethodId:r.content.id,groupId:o.id,guideId:r.content.guideId}],group:o})];case"CategorizedNoticeList":{const m=[b({messageId:l,message:[f.NotificationList,{id:r.content.item.id.toString(),header:r.content.item.title,items:r.content.item.listNotices,symbol:r.content.item.defaultIcon}],group:o})];return(r.content.notices||[]).forEach(w=>{m.push(b({messageId:l,message:[p.ConversationMessageListItemType.HTML,{body:w.body}],group:o}))}),m}case"footerNotice":return[b({messageId:l,message:[p.ConversationMessageListItemType.HTML,{body:r.content.item.body}],group:o})];case"Error":return[b({messageId:l,message:[p.ConversationMessageListItemType.HTML,{body:r.content.message||"Something went wrong."}],group:o})];default:return[]}},a=r=>["CategorizedNoticeList","NoticeList"].includes(r.type)?(r.content.items||[]).reduce((o,g)=>(r.content.isInitialNotices&&o.push({...r,id:K.uuid(),type:g.type||r.type,content:{$type:r.content.$type,isInitialNotices:r.content.isInitialNotices,notices:g.notices,item:g}}),o),[]):r,c=new Map([["Text",1],["List",2],["Contact",3],["CategorizedNoticeList",10]]),h=[],E=t.sort((r,o)=>{const v=c.get(r.type)||20,l=c.get(o.type)||20;return v-l}).filter(r=>!r.relation).reduce((r,o)=>r.concat(a(o)),[]),S=r=>typeof r.actions.selector<"u";for(const r of E){const o=t.filter(l=>l.relation===r.id&&!S(l)),g=A({isUser:!1});(await i(r,g,o,e)).forEach(l=>{g.items.push(l)}),g.items.length&&h.push(g)}return h};class j{constructor(t,e,s,i){y(this,"globalState");y(this,"localState");y(this,"clientId");y(this,"entries");this.endpoint=t,this.events=e,this.store=s,this.container=i,this.clientId=K.uuid(),this.entries=[]}async start({silent:t}){const e=await this.store.read("globalState"),s=await this.store.read("localState"),i=await this.store.read("entries");if(this.globalState=e||this.globalState,this.localState=s||this.localState,this.entries=i||this.entries,t)return;const a=this.createInitialEnvelope();return await this.postEnvelope(a)}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(i=>{const a=t.items.findIndex(c=>c.message[0]==="link-list");return a===-1||!i?t:{...t,meta:{...t.meta,...i[0].meta},items:[...t.items.slice(0,a),{...t.items[a],message:[i[0].items[0].message[0],{...t.items[a].message[1],...i[0].items[0].message[1]}]},...t.items.slice(a+1)]}})}async showContactMethodAction(t){const e=this.entries.find(i=>i.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 i=await s.json();return this.handleResponse(i,e)}catch(s){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let i="Something went wrong";return(s.message==="Failed to fetch"||s.message==="NetworkError when attempting to fetch resource.")&&(i="Lost connection... Please try again."),this.events.dispatch("tracking:http-client-error",{message:i,error:s}),this.handleResponse({entries:[{id:K.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:i},actions:{},tags:[]}]})}}async handleResponse(t,e){this.entries=this.entries.concat(t.entries),this.store.write(this.entries,"entries");const s=t.entries.find(a=>a.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((a,c)=>c.localState?c.localState:a,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:i}=this.container.get("$widget");this.events=i,this.store=new z(t),this.agent=e.createAgent({id:"knowledge-bot-agent",name:"",avatar:void 0}),this.user=e.user;const a=q(t,s);this.httpClient=new j(a,i,this.store,this.container),this.events.subscribe("provider:widget-entry",(c,h)=>{this.onWidgetEntryReceived(h)}),this.events.subscribe("provider:open-contact-method",async(c,h)=>{const E=await this.httpClient.showContactMethodAction(h);E&&(h.contactMethod.title&&this.printUserMessage(h.contactMethod.title),this.onMessagesReceived(E))})}async initialize(){var a;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(),i=await this.httpClient.start({silent:((a=this.conversation.options)==null?void 0:a.silent)||s});i&&this.onMessagesReceived(i),t()}async onMessagesReceived(t){this.groups=this.groups.concat(t),t.forEach(e=>{const s=e.items.map(i=>i.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(i=>{var a;return i.id===((a=t.data)==null?void 0:a.groupId)});if(s){const i=await this.httpClient.nextAction(s);if(i){const a=i.items.map(c=>c.message);s.meta.paging=i==null?void 0:i.meta.paging,s.writer.update(a)}}}break;case"help":{const s=this.conversation.loading(),i=await this.httpClient.helpAction();s(),i&&this.onMessagesReceived(i)}break;default:{typeof t!="string"&&t.label&&this.printUserMessage(t.label);const s=this.conversation.loading(),i=await this.httpClient.defaultAction(e);i&&this.onMessagesReceived(i),s()}break}}printUserMessage(t){const e=A({isUser:!0,items:[{id:K.uuid(),isUser:!0,message:[p.ConversationMessageListItemType.HTML,{body:t}]}]});return this.onMessagesReceived([e]),e}async onMessageSend(t){const e=this.conversation.loading(),s=await this.httpClient.sendMessage(t);await O(this.container,"phrase",t),this.printUserMessage(t),s&&this.onMessagesReceived(s),e()}async onWidgetEntryReceived(t){var r,o,g,v,l;if(t.agent){const d={name:t.agent.name,avatar:t.agent.avatar};this.agent.update(d),(await N.createStorageWriter(this.container,"bot-provider-conversation-meta",N.StorageCategory.Necessary))({agent:d})}const s=(await this.container.getAsync("components")).components().ofType("widget-header").select();if(!s)return;const i=await this.container.get("settings"),a=i==null?void 0:i.components["widget-header"],c=(o=(r=a==null?void 0:a.properties)==null?void 0:r.actions)==null?void 0:o.avatar,h=(g=a==null?void 0:a.properties)==null?void 0:g.header,E=(v=a==null?void 0:a.properties)==null?void 0:v.tagline,S={};!h&&(t!=null&&t.heading)&&(S.header=t.heading),!E&&(t!=null&&t.tagline)&&(S.tagline=t.tagline),!c&&((l=t==null?void 0:t.agent)!=null&&l.avatar)&&(S.actions={avatar:{position:"left",symbol:{type:"Uri",content:t.agent.avatar}}}),Object.keys(S).length>0&&s.writeProperties(S)}}const _=async n=>{const t=await p.ConversationPlatform.getInstance(n);p.registerCustomMessageComponent(n,f.ContactList,Promise.resolve().then(()=>require("./contact-method-list-5ba4ba0b.js"))),p.registerCustomMessageComponent(n,f.ContactMethod,Promise.resolve().then(()=>require("./contact-method-abc31fb9.js"))),p.registerCustomMessageComponent(n,f.NotificationList,Promise.resolve().then(()=>require("./notification-list-d4d9695d.js"))),p.registerCustomMessageComponent(n,f.NoGoodAlternative,Promise.resolve().then(()=>require("./no-good-alternative-0ced8ab9.js"))),p.registerCustomMessageComponent(n,f.FeedbackList,Promise.resolve().then(()=>require("./feedback-list-a27d3df3.js"))),t.registerProvider("ace-knowledge-bot",(e,s)=>{const i=new W(n,e,s);i.initialize();const a=[];return a.push(s.actions.watch("conversation.user-submit",(c,h)=>{i.onMessageSend(c.text)})),a.push(s.actions.watch("conversation.action",(c,h)=>(i.onInput(c),h(c)))),a.push(s.actions.create("evaluate",c=>{const{events:h}=n.get("$widget");h.dispatch("bot-provider:evaluate",c)})),a.push(s.actions.create("submit",c=>{const{events:h}=n.get("$widget");h.dispatch("bot-provider:form-submitted",c)})),()=>{a.forEach(c=>{c()})}})};exports.KnowledgeBotProviderPlugin=_;exports.updateForm=B;
@@ -1,8 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),d=require("@emotion/styled"),u=require("@telia-ace/knowledge-widget-ui"),c=require("@telia-ace/widget-utilities"),f=require("react"),g=require("./styles-66aa2377.js");require("@emotion/react");const m=({id:i,header:t,items:o,symbol:s,className:r,...a})=>{const n=f.useMemo(()=>({id:i,title:t,symbol:s,defaultHeaderOptions:{visible:!0},notifications:o.map(e=>({id:e.id.toString(),title:e.title,body:e.body,modified:e.modified,expandable:!0}))}),[t,o]);return n?l.jsx(y,{className:c.appendClassNames("humany-bot-notification-list",r),showHeader:!0,notificationList:n,loading:!1,...a}):null},y=d(u.NotificationList)`
2
- ${g.messageContentPadding}
3
- min-width: 10em;
4
-
5
- span {
6
- color: ${i=>{var t;return(t=i.theme.colors)==null?void 0:t.text}};
7
- }
8
- `;exports.default=m;
File without changes
File without changes