@telia-ace/knowledge-widget-bot-provider 1.1.1-rc.2 → 1.1.1-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.
- package/contact-method-37007137.mjs +135 -0
- package/contact-method-be72fba9.js +3 -0
- package/{contact-method-list-97120c25.mjs → contact-method-list-672114d0.mjs} +23 -22
- package/contact-method-list-a44fe57a.js +28 -0
- package/feedback-list-34683249.js +25 -0
- package/feedback-list-f0d5afb7.mjs +78 -0
- package/index-76cfe150.js +1 -0
- package/index-ddac8cac.mjs +777 -0
- package/index.js +1 -1
- package/index.mjs +6 -9
- package/no-good-alternative-553f1e16.js +15 -0
- package/{no-good-alternative-03d6bcb7.mjs → no-good-alternative-e3074a3d.mjs} +13 -19
- package/notification-list-2ba3e3d1.js +8 -0
- package/{notification-list-0c267dd1.mjs → notification-list-fb5099fe.mjs} +14 -17
- package/package.json +9 -9
- package/contact-method-20fd0394.mjs +0 -899
- package/contact-method-63fbd19d.js +0 -99
- package/contact-method-list-43c65663.js +0 -28
- package/feedback-list-98ceac5a.mjs +0 -84
- package/feedback-list-e263431c.js +0 -25
- package/index-01541f60.js +0 -1181
- package/index-373df3a5.js +0 -6
- package/index-5c9c2abf.mjs +0 -883
- package/index-66306883.mjs +0 -6932
- package/no-good-alternative-587beaeb.js +0 -15
- package/notification-list-0f1ef293.js +0 -8
- package/notification-list-16d93d9e.mjs +0 -1452
- package/notification-list-6c9ed67a.js +0 -546
- package/use-dispatch-21581b7b.js +0 -1
- package/use-dispatch-a4fd0411.mjs +0 -24
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { jsx as F } from "react/jsx-runtime";
|
|
2
|
+
import z from "@emotion/styled";
|
|
3
|
+
import { DataClient as A, DataType as B } from "@telia-ace/knowledge-data-client";
|
|
4
|
+
import { ContactMethod as N } from "@telia-ace/knowledge-widget-adapters";
|
|
5
|
+
import { useContainer as R, useDispatch as T, useConversation as _ } from "@telia-ace/knowledge-widget-ui";
|
|
6
|
+
import { FormBuilder as j } from "@telia-ace/widget-forms";
|
|
7
|
+
import { appendClassNames as k } from "@telia-ace/widget-utilities";
|
|
8
|
+
import { useState as G, useRef as I, useEffect as S, useCallback as V } from "react";
|
|
9
|
+
import { u as $ } from "./index-ddac8cac.mjs";
|
|
10
|
+
import "@telia-ace/widget-conversation";
|
|
11
|
+
import "@telia-ace/widget-services";
|
|
12
|
+
const tt = ({
|
|
13
|
+
contactMethodId: a,
|
|
14
|
+
guideId: e,
|
|
15
|
+
groupId: c,
|
|
16
|
+
className: x
|
|
17
|
+
}) => {
|
|
18
|
+
var h, C, v;
|
|
19
|
+
const [t, n] = G(), i = R(), D = T(), u = I(!0), f = _();
|
|
20
|
+
S(() => {
|
|
21
|
+
const { events: d } = i.get("$widget"), M = d.subscribe(
|
|
22
|
+
"bot-provider:form-submitted",
|
|
23
|
+
async (b, r) => {
|
|
24
|
+
var w;
|
|
25
|
+
if (((w = r.form.meta) == null ? void 0 : w.groupId) !== c || r.id !== t.id)
|
|
26
|
+
return;
|
|
27
|
+
f && (r.form.meta || (r.form.meta = {}), r.form.meta.conversation = f);
|
|
28
|
+
const y = await i.getAsync(
|
|
29
|
+
"contactMethods"
|
|
30
|
+
), o = {
|
|
31
|
+
...t,
|
|
32
|
+
body: {
|
|
33
|
+
...t.body,
|
|
34
|
+
form: r.form
|
|
35
|
+
}
|
|
36
|
+
}, { errors: m, valid: l, errorTypes: H } = await y.validate(
|
|
37
|
+
o
|
|
38
|
+
);
|
|
39
|
+
if (!l) {
|
|
40
|
+
const g = new j(t.body.form);
|
|
41
|
+
n(void 0), g.setValidationErrors(m), o.body = {
|
|
42
|
+
...o.body,
|
|
43
|
+
form: g.get()
|
|
44
|
+
}, n({ ...o });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const E = await y.submit(o);
|
|
48
|
+
o.confirmation = E, n(o);
|
|
49
|
+
}
|
|
50
|
+
), s = d.subscribe(
|
|
51
|
+
"bot-provider:evaluate",
|
|
52
|
+
async (b, r) => {
|
|
53
|
+
if (r.id !== a)
|
|
54
|
+
return;
|
|
55
|
+
const o = await (await i.getAsync(
|
|
56
|
+
"contactMethods"
|
|
57
|
+
)).evaluate(t);
|
|
58
|
+
let m = {
|
|
59
|
+
...t,
|
|
60
|
+
body: {
|
|
61
|
+
...t.body,
|
|
62
|
+
form: o
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const l = $(m, {
|
|
66
|
+
submit: "Submit",
|
|
67
|
+
errors: {},
|
|
68
|
+
meta: { groupId: c }
|
|
69
|
+
});
|
|
70
|
+
m = {
|
|
71
|
+
...m,
|
|
72
|
+
body: l
|
|
73
|
+
}, n(m);
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
return () => {
|
|
77
|
+
M(), s();
|
|
78
|
+
};
|
|
79
|
+
}, [i, t, n, f]);
|
|
80
|
+
const p = V(
|
|
81
|
+
async (d) => {
|
|
82
|
+
const s = await (await A.getInstance(i)).fetch(
|
|
83
|
+
B.ContactMethod,
|
|
84
|
+
{
|
|
85
|
+
contactMethodId: d,
|
|
86
|
+
guideId: e
|
|
87
|
+
},
|
|
88
|
+
{ noCache: !0 }
|
|
89
|
+
), b = $(s, {
|
|
90
|
+
submit: "Submit",
|
|
91
|
+
errors: {},
|
|
92
|
+
meta: { groupId: c }
|
|
93
|
+
});
|
|
94
|
+
if (s.body = b, s.body.guideId = e, !u.current)
|
|
95
|
+
return null;
|
|
96
|
+
n(s);
|
|
97
|
+
},
|
|
98
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
99
|
+
[u]
|
|
100
|
+
);
|
|
101
|
+
return S(() => (p(a), () => {
|
|
102
|
+
u.current = !1;
|
|
103
|
+
}), [a, p]), t ? /* @__PURE__ */ F(
|
|
104
|
+
q,
|
|
105
|
+
{
|
|
106
|
+
...t,
|
|
107
|
+
body: {
|
|
108
|
+
...t.body,
|
|
109
|
+
form: t.body.form ? {
|
|
110
|
+
...t.body.form,
|
|
111
|
+
data: (h = t.body.form) == null ? void 0 : h.data,
|
|
112
|
+
layout: { ...t.body.form.layout },
|
|
113
|
+
meta: (C = t.body.form) == null ? void 0 : C.meta,
|
|
114
|
+
schema: (v = t.body.form) == null ? void 0 : v.schema
|
|
115
|
+
} : void 0,
|
|
116
|
+
guideId: t.body.guideId
|
|
117
|
+
},
|
|
118
|
+
inline: !0,
|
|
119
|
+
expanded: !0,
|
|
120
|
+
dispatch: D,
|
|
121
|
+
className: k("humany-bot-contact-method", x)
|
|
122
|
+
}
|
|
123
|
+
) : null;
|
|
124
|
+
}, q = z(N)`
|
|
125
|
+
padding: ${(a) => {
|
|
126
|
+
var e;
|
|
127
|
+
return (e = a.theme.sizes) == null ? void 0 : e.normal;
|
|
128
|
+
}} ${(a) => {
|
|
129
|
+
var e;
|
|
130
|
+
return (e = a.theme.sizes) == null ? void 0 : e.medium;
|
|
131
|
+
}};
|
|
132
|
+
`;
|
|
133
|
+
export {
|
|
134
|
+
tt as default
|
|
135
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react/jsx-runtime"),A=require("@emotion/styled"),F=require("@telia-ace/knowledge-data-client"),R=require("@telia-ace/knowledge-widget-adapters"),p=require("@telia-ace/knowledge-widget-ui"),T=require("@telia-ace/widget-forms"),$=require("@telia-ace/widget-utilities"),c=require("react"),k=require("./index-76cfe150.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");const z=({contactMethodId:n,guideId:o,groupId:m,className:x})=>{var C,v,w;const[t,s]=c.useState(),d=p.useContainer(),D=p.useDispatch(),b=c.useRef(!0),l=p.useConversation();c.useEffect(()=>{const{events:u}=d.get("$widget"),q=u.subscribe("bot-provider:form-submitted",async(f,r)=>{var M;if(((M=r.form.meta)==null?void 0:M.groupId)!==m||r.id!==t.id)return;l&&(r.form.meta||(r.form.meta={}),r.form.meta.conversation=l);const y=await d.getAsync("contactMethods"),e={...t,body:{...t.body,form:r.form}},{errors:i,valid:h,errorTypes:N}=await y.validate(e);if(!h){const S=new T.FormBuilder(t.body.form);s(void 0),S.setValidationErrors(i),e.body={...e.body,form:S.get()},s({...e});return}const E=await y.submit(e);e.confirmation=E,s(e)}),a=u.subscribe("bot-provider:evaluate",async(f,r)=>{if(r.id!==n)return;const e=await(await d.getAsync("contactMethods")).evaluate(t);let i={...t,body:{...t.body,form:e}};const h=k.updateForm(i,{submit:"Submit",errors:{},meta:{groupId:m}});i={...i,body:h},s(i)});return()=>{q(),a()}},[d,t,s,l]);const g=c.useCallback(async u=>{const a=await(await F.DataClient.getInstance(d)).fetch(F.DataType.ContactMethod,{contactMethodId:u,guideId:o},{noCache:!0}),f=k.updateForm(a,{submit:"Submit",errors:{},meta:{groupId:m}});if(a.body=f,a.body.guideId=o,!b.current)return null;s(a)},[b]);return c.useEffect(()=>(g(n),()=>{b.current=!1}),[n,g]),t?j.jsx(B,{...t,body:{...t.body,form:t.body.form?{...t.body.form,data:(C=t.body.form)==null?void 0:C.data,layout:{...t.body.form.layout},meta:(v=t.body.form)==null?void 0:v.meta,schema:(w=t.body.form)==null?void 0:w.schema}:void 0,guideId:t.body.guideId},inline:!0,expanded:!0,dispatch:D,className:$.appendClassNames("humany-bot-contact-method",x)}):null},B=A(R.ContactMethod)`
|
|
2
|
+
padding: ${n=>{var o;return(o=n.theme.sizes)==null?void 0:o.normal}} ${n=>{var o;return(o=n.theme.sizes)==null?void 0:o.medium}};
|
|
3
|
+
`;exports.default=z;
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as a } from "react/jsx-runtime";
|
|
2
2
|
import m from "@emotion/styled";
|
|
3
|
-
import {
|
|
4
|
-
import "@
|
|
5
|
-
import { useState as f, useEffect as
|
|
6
|
-
import "
|
|
7
|
-
import "
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import "./
|
|
11
|
-
import "
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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-37007137.mjs";
|
|
7
|
+
import "@telia-ace/knowledge-data-client";
|
|
8
|
+
import "@telia-ace/widget-forms";
|
|
9
|
+
import "@telia-ace/widget-utilities";
|
|
10
|
+
import "./index-ddac8cac.mjs";
|
|
11
|
+
import "@telia-ace/widget-conversation";
|
|
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(() => {
|
|
15
16
|
d.getAsync("contactMethods").then((n) => {
|
|
16
17
|
if (!n)
|
|
17
18
|
return;
|
|
18
|
-
const
|
|
19
|
+
const c = t.map(async (i) => {
|
|
19
20
|
var p;
|
|
20
21
|
if (!((p = i.data) != null && p.clientName))
|
|
21
22
|
return null;
|
|
@@ -39,27 +40,27 @@ const B = ({ actions: t, entryId: e, groupId: h }) => {
|
|
|
39
40
|
}
|
|
40
41
|
};
|
|
41
42
|
});
|
|
42
|
-
Promise.all(
|
|
43
|
+
Promise.all(c).then((i) => {
|
|
43
44
|
g(i.filter((o) => !!o));
|
|
44
45
|
});
|
|
45
46
|
});
|
|
46
|
-
}, [t, d, e, r]), l.length ? /* @__PURE__ */
|
|
47
|
+
}, [t, d, e, r]), l.length ? /* @__PURE__ */ a(
|
|
47
48
|
k,
|
|
48
49
|
{
|
|
49
50
|
className: "humany-bot-contact-list",
|
|
50
51
|
contactMethods: l,
|
|
51
52
|
dispatch: y,
|
|
52
|
-
itemRenderer: (n,
|
|
53
|
+
itemRenderer: (n, c) => (r.includes(n.id) || n.expanded) && n.inline ? /* @__PURE__ */ a(
|
|
53
54
|
z,
|
|
54
55
|
{
|
|
55
56
|
contactMethodId: n.id,
|
|
56
57
|
groupId: h,
|
|
57
58
|
guideId: n.body.guideId
|
|
58
59
|
}
|
|
59
|
-
) : /* @__PURE__ */
|
|
60
|
+
) : /* @__PURE__ */ a(I, { ...n, ...c })
|
|
60
61
|
}
|
|
61
62
|
) : null;
|
|
62
|
-
}, k = m(
|
|
63
|
+
}, k = m(M)`
|
|
63
64
|
> ul > li {
|
|
64
65
|
a {
|
|
65
66
|
display: flex;
|
|
@@ -71,7 +72,7 @@ const B = ({ actions: t, entryId: e, groupId: h }) => {
|
|
|
71
72
|
${(t) => t.theme.border && `border-bottom: ${t.theme.border};`}
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
|
-
`, z = m(
|
|
75
|
+
`, z = m(j)`
|
|
75
76
|
i {
|
|
76
77
|
margin: 0 ${(t) => {
|
|
77
78
|
var e;
|
|
@@ -81,7 +82,7 @@ const B = ({ actions: t, entryId: e, groupId: h }) => {
|
|
|
81
82
|
justify-content: center;
|
|
82
83
|
align-items: center;
|
|
83
84
|
}
|
|
84
|
-
`, I = m(
|
|
85
|
+
`, I = m($)`
|
|
85
86
|
padding: ${(t) => {
|
|
86
87
|
var e;
|
|
87
88
|
return (e = t.theme.sizes) == null ? void 0 : e.medium;
|
|
@@ -97,5 +98,5 @@ const B = ({ actions: t, entryId: e, groupId: h }) => {
|
|
|
97
98
|
}
|
|
98
99
|
`;
|
|
99
100
|
export {
|
|
100
|
-
|
|
101
|
+
F as default
|
|
101
102
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
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-be72fba9.js");require("@telia-ace/knowledge-data-client");require("@telia-ace/widget-forms");require("@telia-ace/widget-utilities");require("./index-76cfe150.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");const j=({actions:e,entryId:t,groupId:y})=>{const x=f.useDispatch(),d=f.useContainer(),[h,q]=u.useState([]),[o,C]=u.useState([]);return u.useEffect(()=>{d.getAsync("contactMethods").then(n=>{if(!n)return;const c=e.map(async i=>{var m;if(!((m=i.data)!=null&&m.clientName))return null;const s=await n.handleAdapters(i.data);return{...s,...i.data,description:i.data.description?i.data.description:s.description,onClick:(p,r)=>{if(typeof s.onClick=="function"&&s.onClick(p,r),!p.defaultPrevented)if(r.inline&&!r.expanded)C([...o,r.id]);else{const{events:M}=d.get("$widget");M.dispatch("provider:open-contact-method",{entryId:t,contactMethod:r,actionKey:i.actionKey})}}}});Promise.all(c).then(i=>{q(i.filter(s=>!!s))})})},[e,d,t,o]),h.length?a.jsx(S,{className:"humany-bot-contact-list",contactMethods:h,dispatch:x,itemRenderer:(n,c)=>(o.includes(n.id)||n.expanded)&&n.inline?a.jsx($,{contactMethodId:n.id,groupId:y,guideId:n.body.guideId}):a.jsx(k,{...n,...c})}):null},S=l(g.ContactList)`
|
|
2
|
+
> 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
|
+
`,$=l(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
|
+
`,k=l(g.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;
|
|
@@ -0,0 +1,25 @@
|
|
|
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-094b07e5.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)`
|
|
2
|
+
${e=>s.list(e)}
|
|
3
|
+
${i.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
|
+
`,c=n(s.Button)`
|
|
12
|
+
${s.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 s.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=a;
|
|
@@ -0,0 +1,78 @@
|
|
|
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-95d5aa50.mjs";
|
|
5
|
+
import "@emotion/react";
|
|
6
|
+
const k = ({ actions: e }) => {
|
|
7
|
+
const t = i();
|
|
8
|
+
return /* @__PURE__ */ r(
|
|
9
|
+
p,
|
|
10
|
+
{
|
|
11
|
+
className: "humany-bot-feedback-list",
|
|
12
|
+
items: e,
|
|
13
|
+
"data-direction": "vertical",
|
|
14
|
+
renderItem: (o) => /* @__PURE__ */ r("li", { children: /* @__PURE__ */ s(
|
|
15
|
+
u,
|
|
16
|
+
{
|
|
17
|
+
className: "humany-feedback-button",
|
|
18
|
+
disabled: !1,
|
|
19
|
+
"aria-pressed": !0,
|
|
20
|
+
"data-selected": !0,
|
|
21
|
+
onClick: () => {
|
|
22
|
+
t("action", o.actionKey);
|
|
23
|
+
},
|
|
24
|
+
children: [
|
|
25
|
+
/* @__PURE__ */ r(n, { faIcon: o.actionKey === "yes" ? "smile-o" : "frown-o" }),
|
|
26
|
+
/* @__PURE__ */ r("span", { children: o.label })
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
) }, o.actionKey)
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
}, p = a(l)`
|
|
33
|
+
${(e) => c(e)}
|
|
34
|
+
${f}
|
|
35
|
+
display: flex;
|
|
36
|
+
gap: ${(e) => {
|
|
37
|
+
var t;
|
|
38
|
+
return (t = e.theme.sizes) == null ? void 0 : t.normal;
|
|
39
|
+
}};
|
|
40
|
+
flex-direction: ${(e) => e["data-direction"] === "horizontal" ? "row" : "column"};
|
|
41
|
+
> li {
|
|
42
|
+
flex: 1;
|
|
43
|
+
margin: 0;
|
|
44
|
+
}
|
|
45
|
+
`, u = a(m)`
|
|
46
|
+
${d}
|
|
47
|
+
font-size: ${(e) => {
|
|
48
|
+
var t;
|
|
49
|
+
return (t = e.theme.fonts) == null ? void 0 : t.normal;
|
|
50
|
+
}};
|
|
51
|
+
border-color: ${(e) => {
|
|
52
|
+
var t;
|
|
53
|
+
return (t = e.theme.colors) == null ? void 0 : t.primary;
|
|
54
|
+
}};
|
|
55
|
+
font-weight: 300;
|
|
56
|
+
display: block;
|
|
57
|
+
width: 100%;
|
|
58
|
+
|
|
59
|
+
${(e) => {
|
|
60
|
+
var t;
|
|
61
|
+
return h({
|
|
62
|
+
primaryColor: `${(t = e.theme.colors) == null ? void 0 : t.primary}`,
|
|
63
|
+
secondaryColor: "#FFFFFF",
|
|
64
|
+
theme: e.theme
|
|
65
|
+
});
|
|
66
|
+
}}
|
|
67
|
+
i {
|
|
68
|
+
margin: 0 ${(e) => {
|
|
69
|
+
var t;
|
|
70
|
+
return (t = e.theme.sizes) == null ? void 0 : t.small;
|
|
71
|
+
}} 0 0;
|
|
72
|
+
}
|
|
73
|
+
span {
|
|
74
|
+
}
|
|
75
|
+
`;
|
|
76
|
+
export {
|
|
77
|
+
k as default
|
|
78
|
+
};
|
|
@@ -0,0 +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:h,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),h&&h.hasValueComponents&&(l?d.body.form=P.FormBuilder.fromLegacyForm(i.toString(),h,l).get():d.body.form=P.FormBuilder.fromLegacyForm(i.toString(),h).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 u=U(a);if(I=s(u,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:[u,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(u=>{var C;return u.type==="List"&&((C=u.localState)==null?void 0:C.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"}),x=g.find(u=>u.tags.includes("dialog")),w=g.find(u=>u.tags.includes("feedback")),I=g.find(u=>u.tags.includes("contact")&&u.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(u=>({label:u.title,actionKey:u.actionKey}))}],group:o})),v){const u=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,u],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(u=>({actionKey:u.actionKey,label:u.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]]),h=[],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&&h.push(g)}return h};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,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 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-a44fe57a.js"))),m.registerCustomMessageComponent(i,f.ContactMethod,Promise.resolve().then(()=>require("./contact-method-be72fba9.js"))),m.registerCustomMessageComponent(i,f.NotificationList,Promise.resolve().then(()=>require("./notification-list-2ba3e3d1.js"))),m.registerCustomMessageComponent(i,f.NoGoodAlternative,Promise.resolve().then(()=>require("./no-good-alternative-553f1e16.js"))),m.registerCustomMessageComponent(i,f.FeedbackList,Promise.resolve().then(()=>require("./feedback-list-34683249.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,h)=>{n.onMessageSend(c.text)})),r.push(s.actions.watch("conversation.action",(c,h)=>(n.onInput(c),h(c)))),r.push(s.actions.create("evaluate",c=>{const{events:h}=i.get("$widget");h.dispatch("bot-provider:evaluate",c)})),r.push(s.actions.create("submit",c=>{const{events:h}=i.get("$widget");h.dispatch("bot-provider:form-submitted",c)})),()=>{r.forEach(c=>{c()})}})};exports.KnowledgeBotProviderPlugin=_;exports.updateForm=B;
|