@telia-ace/knowledge-widget-bot-provider 1.1.2-rc.0 → 1.1.2-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.
- package/{contact-method-5b71554e.mjs → contact-method-09938f6d.mjs} +1 -1
- package/{contact-method-46dd96f8.js → contact-method-35f483b1.js} +1 -1
- package/{contact-method-list-e487c035.mjs → contact-method-list-1ae2809b.mjs} +24 -24
- package/{contact-method-list-93f20ff3.js → contact-method-list-52fb36fb.js} +23 -23
- package/{feedback-list-f0d5afb7.mjs → feedback-list-1eef6ff2.mjs} +1 -1
- package/{feedback-list-34683249.js → feedback-list-6f877c77.js} +1 -1
- package/{index-ff32882c.mjs → index-40a1afe2.mjs} +43 -12
- package/{index-e264a8f9.js → index-b33b8ed1.js} +1 -1
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/{no-good-alternative-553f1e16.js → no-good-alternative-0ced8ab9.js} +12 -12
- package/{no-good-alternative-e3074a3d.mjs → no-good-alternative-c6825c80.mjs} +12 -12
- package/{notification-list-fb5099fe.mjs → notification-list-3e483308.mjs} +1 -1
- package/{notification-list-2ba3e3d1.js → notification-list-d4d9695d.js} +1 -1
- package/package.json +9 -9
- package/styles-5f6d3622.mjs +11 -0
- package/styles-66aa2377.js +4 -0
- package/styles-094b07e5.js +0 -4
- package/styles-95d5aa50.mjs +0 -11
|
@@ -6,7 +6,7 @@ import { useContainer as R, useDispatch as T, useConversation as _ } from "@teli
|
|
|
6
6
|
import { FormBuilder as j } from "@telia-ace/widget-forms";
|
|
7
7
|
import { appendClassNames as k } from "@telia-ace/widget-utilities";
|
|
8
8
|
import { useState as G, useRef as I, useEffect as S, useCallback as V } from "react";
|
|
9
|
-
import { u as $ } from "./index-
|
|
9
|
+
import { u as $ } from "./index-40a1afe2.mjs";
|
|
10
10
|
import "@telia-ace/widget-conversation";
|
|
11
11
|
import "@telia-ace/widget-services";
|
|
12
12
|
const tt = ({
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react/jsx-runtime"),A=require("@emotion/styled"),F=require("@telia-ace/knowledge-data-client"),R=require("@telia-ace/knowledge-widget-adapters"),p=require("@telia-ace/knowledge-widget-ui"),T=require("@telia-ace/widget-forms"),$=require("@telia-ace/widget-utilities"),c=require("react"),k=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react/jsx-runtime"),A=require("@emotion/styled"),F=require("@telia-ace/knowledge-data-client"),R=require("@telia-ace/knowledge-widget-adapters"),p=require("@telia-ace/knowledge-widget-ui"),T=require("@telia-ace/widget-forms"),$=require("@telia-ace/widget-utilities"),c=require("react"),k=require("./index-b33b8ed1.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");const z=({contactMethodId:n,guideId:o,groupId:m,className:x})=>{var C,v,w;const[t,s]=c.useState(),d=p.useContainer(),D=p.useDispatch(),b=c.useRef(!0),l=p.useConversation();c.useEffect(()=>{const{events:u}=d.get("$widget"),q=u.subscribe("bot-provider:form-submitted",async(f,r)=>{var M;if(((M=r.form.meta)==null?void 0:M.groupId)!==m||r.id!==t.id)return;l&&(r.form.meta||(r.form.meta={}),r.form.meta.conversation=l);const y=await d.getAsync("contactMethods"),e={...t,body:{...t.body,form:r.form}},{errors:i,valid:h,errorTypes:N}=await y.validate(e);if(!h){const S=new T.FormBuilder(t.body.form);s(void 0),S.setValidationErrors(i),e.body={...e.body,form:S.get()},s({...e});return}const E=await y.submit(e);e.confirmation=E,s(e)}),a=u.subscribe("bot-provider:evaluate",async(f,r)=>{if(r.id!==n)return;const e=await(await d.getAsync("contactMethods")).evaluate(t);let i={...t,body:{...t.body,form:e}};const h=k.updateForm(i,{submit:"Submit",errors:{},meta:{groupId:m}});i={...i,body:h},s(i)});return()=>{q(),a()}},[d,t,s,l]);const g=c.useCallback(async u=>{const a=await(await F.DataClient.getInstance(d)).fetch(F.DataType.ContactMethod,{contactMethodId:u,guideId:o},{noCache:!0}),f=k.updateForm(a,{submit:"Submit",errors:{},meta:{groupId:m}});if(a.body=f,a.body.guideId=o,!b.current)return null;s(a)},[b]);return c.useEffect(()=>(g(n),()=>{b.current=!1}),[n,g]),t?j.jsx(B,{...t,body:{...t.body,form:t.body.form?{...t.body.form,data:(C=t.body.form)==null?void 0:C.data,layout:{...t.body.form.layout},meta:(v=t.body.form)==null?void 0:v.meta,schema:(w=t.body.form)==null?void 0:w.schema}:void 0,guideId:t.body.guideId},inline:!0,expanded:!0,dispatch:D,className:$.appendClassNames("humany-bot-contact-method",x)}):null},B=A(R.ContactMethod)`
|
|
2
2
|
padding: ${n=>{var o;return(o=n.theme.sizes)==null?void 0:o.normal}} ${n=>{var o;return(o=n.theme.sizes)==null?void 0:o.medium}};
|
|
3
3
|
`;exports.default=z;
|
|
@@ -3,11 +3,11 @@ import m from "@emotion/styled";
|
|
|
3
3
|
import { ContactList as M, ContactMethod as $ } from "@telia-ace/knowledge-widget-adapters";
|
|
4
4
|
import { useDispatch as b, useContainer as E } from "@telia-ace/knowledge-widget-ui";
|
|
5
5
|
import { useState as f, useEffect as S } from "react";
|
|
6
|
-
import j from "./contact-method-
|
|
6
|
+
import j from "./contact-method-09938f6d.mjs";
|
|
7
7
|
import "@telia-ace/knowledge-data-client";
|
|
8
8
|
import "@telia-ace/widget-forms";
|
|
9
9
|
import "@telia-ace/widget-utilities";
|
|
10
|
-
import "./index-
|
|
10
|
+
import "./index-40a1afe2.mjs";
|
|
11
11
|
import "@telia-ace/widget-conversation";
|
|
12
12
|
import "@telia-ace/widget-services";
|
|
13
13
|
const F = ({ actions: t, entryId: e, groupId: h }) => {
|
|
@@ -61,41 +61,41 @@ const F = ({ actions: t, entryId: e, groupId: h }) => {
|
|
|
61
61
|
}
|
|
62
62
|
) : null;
|
|
63
63
|
}, k = m(M)`
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
> ul > li {
|
|
65
|
+
a {
|
|
66
|
+
display: flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
outline-offset: -2px;
|
|
69
|
+
}
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
71
|
+
&:not(:last-child) {
|
|
72
|
+
${(t) => t.theme.border && `border-bottom: ${t.theme.border};`}
|
|
74
73
|
}
|
|
74
|
+
}
|
|
75
75
|
`, z = m(j)`
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
i {
|
|
77
|
+
margin: 0 ${(t) => {
|
|
78
78
|
var e;
|
|
79
79
|
return (e = t.theme.sizes) == null ? void 0 : e.medium;
|
|
80
80
|
}} 0 0;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
display: flex;
|
|
82
|
+
justify-content: center;
|
|
83
|
+
align-items: center;
|
|
84
|
+
}
|
|
85
85
|
`, I = m($)`
|
|
86
|
-
|
|
86
|
+
padding: ${(t) => {
|
|
87
87
|
var e;
|
|
88
88
|
return (e = t.theme.sizes) == null ? void 0 : e.medium;
|
|
89
89
|
}};
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
i {
|
|
91
|
+
margin: 0 ${(t) => {
|
|
92
92
|
var e;
|
|
93
93
|
return (e = t.theme.sizes) == null ? void 0 : e.medium;
|
|
94
94
|
}} 0 0;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
display: flex;
|
|
96
|
+
justify-content: center;
|
|
97
|
+
align-items: center;
|
|
98
|
+
}
|
|
99
99
|
`;
|
|
100
100
|
export {
|
|
101
101
|
F as default
|
|
@@ -1,28 +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-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),l=require("@emotion/styled"),g=require("@telia-ace/knowledge-widget-adapters"),f=require("@telia-ace/knowledge-widget-ui"),u=require("react"),b=require("./contact-method-35f483b1.js");require("@telia-ace/knowledge-data-client");require("@telia-ace/widget-forms");require("@telia-ace/widget-utilities");require("./index-b33b8ed1.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");const j=({actions:e,entryId:t,groupId:y})=>{const x=f.useDispatch(),d=f.useContainer(),[h,q]=u.useState([]),[o,C]=u.useState([]);return u.useEffect(()=>{d.getAsync("contactMethods").then(n=>{if(!n)return;const c=e.map(async i=>{var m;if(!((m=i.data)!=null&&m.clientName))return null;const s=await n.handleAdapters(i.data);return{...s,...i.data,description:i.data.description?i.data.description:s.description,onClick:(p,r)=>{if(typeof s.onClick=="function"&&s.onClick(p,r),!p.defaultPrevented)if(r.inline&&!r.expanded)C([...o,r.id]);else{const{events:M}=d.get("$widget");M.dispatch("provider:open-contact-method",{entryId:t,contactMethod:r,actionKey:i.actionKey})}}}});Promise.all(c).then(i=>{q(i.filter(s=>!!s))})})},[e,d,t,o]),h.length?a.jsx(S,{className:"humany-bot-contact-list",contactMethods:h,dispatch:x,itemRenderer:(n,c)=>(o.includes(n.id)||n.expanded)&&n.inline?a.jsx($,{contactMethodId:n.id,groupId:y,guideId:n.body.guideId}):a.jsx(k,{...n,...c})}):null},S=l(g.ContactList)`
|
|
2
|
+
> ul > li {
|
|
3
|
+
a {
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
outline-offset: -2px;
|
|
7
|
+
}
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
9
|
+
&:not(:last-child) {
|
|
10
|
+
${e=>e.theme.border&&`border-bottom: ${e.theme.border};`}
|
|
12
11
|
}
|
|
12
|
+
}
|
|
13
13
|
`,$=l(b.default)`
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
20
|
`,k=l(g.ContactMethod)`
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
28
|
`;exports.default=j;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as r, jsxs as s } from "react/jsx-runtime";
|
|
2
2
|
import a from "@emotion/styled";
|
|
3
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-
|
|
4
|
+
import { m as f } from "./styles-5f6d3622.mjs";
|
|
5
5
|
import "@emotion/react";
|
|
6
6
|
const k = ({ actions: e }) => {
|
|
7
7
|
const t = i();
|
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),n=require("@emotion/styled"),s=require("@telia-ace/knowledge-widget-ui"),i=require("./styles-66aa2377.js");require("@emotion/react");const a=({actions:e})=>{const t=s.useDispatch();return o.jsx(l,{className:"humany-bot-feedback-list",items:e,"data-direction":"vertical",renderItem:r=>o.jsx("li",{children:o.jsxs(c,{className:"humany-feedback-button",disabled:!1,"aria-pressed":!0,"data-selected":!0,onClick:()=>{t("action",r.actionKey)},children:[o.jsx(s.Icon,{faIcon:r.actionKey==="yes"?"smile-o":"frown-o"}),o.jsx("span",{children:r.label})]})},r.actionKey)})},l=n(s.List)`
|
|
2
2
|
${e=>s.list(e)}
|
|
3
3
|
${i.messageContentPadding}
|
|
4
4
|
display: flex;
|
|
@@ -40,7 +40,11 @@ const j = (s) => {
|
|
|
40
40
|
form: u,
|
|
41
41
|
description: M
|
|
42
42
|
}, K = {}) => {
|
|
43
|
-
const { adapter: a } = i || { Adapter: {} }, {
|
|
43
|
+
const { adapter: a } = i || { Adapter: {} }, {
|
|
44
|
+
clientName: o = "",
|
|
45
|
+
settings: h = {},
|
|
46
|
+
customClientName: S = ""
|
|
47
|
+
} = a, { validation: l } = K, d = {
|
|
44
48
|
id: s.toString(),
|
|
45
49
|
title: t,
|
|
46
50
|
description: M,
|
|
@@ -54,7 +58,14 @@ const j = (s) => {
|
|
|
54
58
|
const { displayTextBeforeClick: k, textBeforeClick: m } = h;
|
|
55
59
|
k === "true" && (d.expanded = !1, d.title = m), o.indexOf("phone.text") > -1 ? d.body.phoneNumber = h.phoneNumber : d.body.freetext = h.freetext;
|
|
56
60
|
}
|
|
57
|
-
return (o.indexOf("chat.popup") > -1 || o.indexOf("link") > -1 || o === "custom.adapter" && n === "custom") && (d.body = h, d.body.confirmationFallback = c), o.indexOf("ace") > -1 && (d.body = h), u && u.hasValueComponents && (l ? d.body.form = H.fromLegacyForm(
|
|
61
|
+
return (o.indexOf("chat.popup") > -1 || o.indexOf("link") > -1 || o === "custom.adapter" && n === "custom") && (d.body = h, d.body.confirmationFallback = c), o.indexOf("ace") > -1 && (d.body = h), u && u.hasValueComponents && (l ? d.body.form = H.fromLegacyForm(
|
|
62
|
+
s.toString(),
|
|
63
|
+
u,
|
|
64
|
+
l
|
|
65
|
+
).get() : d.body.form = H.fromLegacyForm(
|
|
66
|
+
s.toString(),
|
|
67
|
+
u
|
|
68
|
+
).get(), r || (d.expanded = d.inline = !1), d.body = D(d, { submit: "Submit" })), K.guideId && (d.body.guideId = K.guideId), d;
|
|
58
69
|
}, W = (s) => {
|
|
59
70
|
const { localState: t } = s;
|
|
60
71
|
return s.tags.includes("category") && s.tags.includes("contact") ? y.ItemList : s.tags.includes("suggestion") ? y.LinkList : (t == null ? void 0 : t.$type) === "Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching" ? y.LinkList : (t == null ? void 0 : t.$type) === "Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching" ? p.FeedbackList : (t == null ? void 0 : t.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching" ? p.ContactList : y.ButtonList;
|
|
@@ -454,7 +465,9 @@ class q {
|
|
|
454
465
|
},
|
|
455
466
|
t
|
|
456
467
|
).then((n) => {
|
|
457
|
-
const c = t.items.findIndex(
|
|
468
|
+
const c = t.items.findIndex(
|
|
469
|
+
(r) => r.message[0] === "link-list"
|
|
470
|
+
);
|
|
458
471
|
return c === -1 || !n ? t : {
|
|
459
472
|
...t,
|
|
460
473
|
meta: {
|
|
@@ -514,7 +527,10 @@ class q {
|
|
|
514
527
|
}
|
|
515
528
|
async postEnvelope(t, e) {
|
|
516
529
|
try {
|
|
517
|
-
const i = await fetch(
|
|
530
|
+
const i = await fetch(
|
|
531
|
+
this.endpoint,
|
|
532
|
+
this.getHttpOptions(t)
|
|
533
|
+
);
|
|
518
534
|
if (!i.ok)
|
|
519
535
|
throw i;
|
|
520
536
|
const n = await i.json();
|
|
@@ -541,7 +557,14 @@ class q {
|
|
|
541
557
|
async handleResponse(t, e) {
|
|
542
558
|
this.entries = this.entries.concat(t.entries), this.store.write(this.entries, "entries");
|
|
543
559
|
const i = t.entries.find((c) => c.type === "Widget");
|
|
544
|
-
return i && this.events.dispatch("provider:widget-entry", i.content), t.globalState && (this.globalState = t.globalState, this.store.write(t.globalState, "globalState")), this.localState = t.entries.reduce(
|
|
560
|
+
return i && this.events.dispatch("provider:widget-entry", i.content), t.globalState && (this.globalState = t.globalState, this.store.write(t.globalState, "globalState")), this.localState = t.entries.reduce(
|
|
561
|
+
(c, r) => r.localState ? r.localState : c,
|
|
562
|
+
void 0
|
|
563
|
+
), this.store.write(this.localState, "localState"), await J(
|
|
564
|
+
this.container,
|
|
565
|
+
t.entries,
|
|
566
|
+
e
|
|
567
|
+
);
|
|
545
568
|
}
|
|
546
569
|
getHttpOptions(t) {
|
|
547
570
|
const e = {
|
|
@@ -597,7 +620,11 @@ class Q {
|
|
|
597
620
|
const i = this.getKey(e);
|
|
598
621
|
if (!this.enabled || !i)
|
|
599
622
|
return;
|
|
600
|
-
(await O(
|
|
623
|
+
(await O(
|
|
624
|
+
this.container,
|
|
625
|
+
i,
|
|
626
|
+
B.Necessary
|
|
627
|
+
))(t);
|
|
601
628
|
}
|
|
602
629
|
}
|
|
603
630
|
class X {
|
|
@@ -728,25 +755,29 @@ const st = async (s) => {
|
|
|
728
755
|
N(
|
|
729
756
|
s,
|
|
730
757
|
p.ContactList,
|
|
731
|
-
import("./contact-method-list-
|
|
758
|
+
import("./contact-method-list-1ae2809b.mjs")
|
|
732
759
|
), N(
|
|
733
760
|
s,
|
|
734
761
|
p.ContactMethod,
|
|
735
|
-
import("./contact-method-
|
|
762
|
+
import("./contact-method-09938f6d.mjs")
|
|
736
763
|
), N(
|
|
737
764
|
s,
|
|
738
765
|
p.NotificationList,
|
|
739
|
-
import("./notification-list-
|
|
766
|
+
import("./notification-list-3e483308.mjs")
|
|
740
767
|
), N(
|
|
741
768
|
s,
|
|
742
769
|
p.NoGoodAlternative,
|
|
743
|
-
import("./no-good-alternative-
|
|
770
|
+
import("./no-good-alternative-c6825c80.mjs")
|
|
744
771
|
), N(
|
|
745
772
|
s,
|
|
746
773
|
p.FeedbackList,
|
|
747
|
-
import("./feedback-list-
|
|
774
|
+
import("./feedback-list-1eef6ff2.mjs")
|
|
748
775
|
), t.registerProvider("ace-knowledge-bot", (e, i) => {
|
|
749
|
-
const n = new X(
|
|
776
|
+
const n = new X(
|
|
777
|
+
s,
|
|
778
|
+
e,
|
|
779
|
+
i
|
|
780
|
+
);
|
|
750
781
|
n.initialize();
|
|
751
782
|
const c = [];
|
|
752
783
|
return c.push(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var F=Object.defineProperty;var R=(i,t,e)=>t in i?F(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var y=(i,t,e)=>(R(i,typeof t!="symbol"?t+"":t,e),e);const m=require("@telia-ace/widget-conversation"),N=require("@telia-ace/widget-services"),k=require("@telia-ace/widget-utilities"),P=require("@telia-ace/widget-forms");var f=(i=>(i.ContactMethod="ace-knowledge-bot-contact-method",i.ContactList="ace-knowledge-bot-contact-list",i.FeedbackList="ace-knowledge-bot-feedback-list",i.NotificationList="ace-knowledge-bot-notification-list",i.NoGoodAlternative="ace-knowledge-bot-no-good-alternative",i))(f||{});const $=i=>{if(i){const{type:t,content:e}=i;if(t&&e)return{type:t,content:e}}},H=({isUser:i,items:t=[],meta:e={}})=>{const s=k.uuid();return{id:s,isUser:i,items:t.map(r=>({id:r.id||k.uuid(),isUser:i,groupId:s,message:r.message||[]})),meta:e}},G=({id:i,title:t,defaultIcon:e,exits:[s],exitType:n,confirmationText:r,expandFormAutomatically:c,form:u,description:E},K={})=>{const{adapter:a}=s||{Adapter:{}},{clientName:o="",settings:g={},customClientName:S=""}=a,{validation:l}=K,d={id:i.toString(),title:t,description:E,symbol:$(e),clientName:o==="custom.adapter"?S:o,expanded:!0,inline:!0,body:{}};if(o.indexOf("phone")>-1||o.indexOf("freetext")>-1){const{displayTextBeforeClick:M,textBeforeClick:p}=g;M==="true"&&(d.expanded=!1,d.title=p),o.indexOf("phone.text")>-1?d.body.phoneNumber=g.phoneNumber:d.body.freetext=g.freetext}return(o.indexOf("chat.popup")>-1||o.indexOf("link")>-1||o==="custom.adapter"&&n==="custom")&&(d.body=g,d.body.confirmationFallback=r),o.indexOf("ace")>-1&&(d.body=g),u&&u.hasValueComponents&&(l?d.body.form=P.FormBuilder.fromLegacyForm(i.toString(),u,l).get():d.body.form=P.FormBuilder.fromLegacyForm(i.toString(),u).get(),c||(d.expanded=d.inline=!1),d.body=B(d,{submit:"Submit"})),K.guideId&&(d.body.guideId=K.guideId),d},U=i=>{const{localState:t}=i;return i.tags.includes("category")&&i.tags.includes("contact")?m.ConversationMessageListItemType.ItemList:i.tags.includes("suggestion")||(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching"?m.ConversationMessageListItemType.LinkList:(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching"?f.FeedbackList:(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"?f.ContactList:m.ConversationMessageListItemType.ButtonList},q=(i,t)=>{const{knowledgeBotEndpoint:e}=t.properties();if(e)return`${e}/conversations`;const{data:s}=i.get("$settings");if(!s||!s.projection)throw new Error("Missing Knowledge Bot endpoint");return`${s.projection}/conversations`},B=(i,{submit:t,errors:e,meta:s})=>{var n;if((n=i==null?void 0:i.body)!=null&&n.form){const{body:r}=i,c=new P.FormBuilder(r.form);return r.form.layout.submit||c.createComponent(P.submitButton(t,"submit")),e&&c.setValidationErrors(e),s&&c.setMeta(s),{...r,form:c.get()}}return(i==null?void 0:i.body)||{}},A=async(i,t,e)=>{(await(await i.getAsync("dataClient")).getClient()).parameters.set(t,e)},b=({messageId:i,message:t,group:e})=>({id:i,message:t,groupId:e.id,isUser:e.isUser}),V=async(i,t,e)=>{const s=(a,o,g,S={actions:[],entryId:o.id,groupId:g})=>{const l=[];return S.actions=o.content.items.map(d=>{var p;const M={label:d.title,actionKey:d.actionKey,symbol:d.symbol?d.symbol:void 0,description:d.description||void 0};if(d.data){const v=o.actions[d.actionKey];a===f.ContactList?(l.push(d.data.id),M.data=G(d.data,{guideId:(p=v==null?void 0:v.guideId)==null?void 0:p.toString()})):M.data=d.data}return M}),a===f.ContactList&&(S.contactMethodIds=l),S},n=async(a,o,g=[],S)=>{var d,M;const l=k.uuid();switch(a.type!=="List"&&a.tags.includes("guide")&&((M=(d=a.content.hints)==null?void 0:d[0])!=null&&M.id)&&await A(i,"LastGuideId",a.content.hints[0].id),a.type){case"List":{const{header:p,items:v,html:x}=a.content,w=[];let I={actions:[],entryId:a.id,groupId:o.id};if(p&&(I.header=p),(v==null?void 0:v.length)>0){const h=U(a);if(I=s(h,a,o.id,I),g.length){const C=g.find(L=>L.tags.includes("paging")),T=g.find(L=>L.tags.includes("fallback"));if(C!=null&&C.content&&(o.meta.paging={actions:C.actions,items:C.content.items,localState:C.localState},C.content.items.forEach(L=>{I.actions.push({label:L.title,actionKey:L.actionKey,data:{groupId:S?S.id:o.id}})})),T){const L=T.content.items.find(O=>O.actionKey==="help");L&&(w.push(b({messageId:l,message:[m.ConversationMessageListItemType.Separator,void 0],group:o})),w.push(b({messageId:l,message:[f.NoGoodAlternative,{body:L.title}],group:o})))}}w.unshift(b({messageId:l,message:[h,I],group:o}))}return x&&w.unshift(b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:x}],group:o})),w}case"Text":{const p=[];if(p.push(b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:a.content.html}],group:o})),g.length){const v=g.find(h=>{var C;return h.type==="List"&&((C=h.localState)==null?void 0:C.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"}),x=g.find(h=>h.tags.includes("dialog")),w=g.find(h=>h.tags.includes("feedback")),I=g.find(h=>h.tags.includes("contact")&&h.type==="Contact");if(I&&p.push(b({messageId:l,message:[f.ContactMethod,{contactMethodId:I.content.id,groupId:o.id,guideId:I.content.guideId}],group:o})),x&&p.push(b({messageId:l,message:[m.ConversationMessageListItemType.ButtonList,{actions:x.content.items.map(h=>({label:h.title,actionKey:h.actionKey,data:h.data}))}],group:o})),v){const h=s(f.ContactList,v,o.id);p.push(b({messageId:l,message:[m.ConversationMessageListItemType.Separator,void 0],group:o})),p.push(b({messageId:l,message:[f.ContactList,h],group:o}))}w&&(w.content.html&&p.push(b({messageId:l,group:o,message:[m.ConversationMessageListItemType.HTML,{body:w.content.html}]})),p.push(b({messageId:l,group:o,message:[f.FeedbackList,{actions:w.content.items.map(h=>({actionKey:h.actionKey,label:h.title}))}]})))}return p}case"Contact":return[b({messageId:l,message:[f.ContactMethod,{contactMethodId:a.content.id,groupId:o.id,guideId:a.content.guideId}],group:o})];case"CategorizedNoticeList":{const p=[b({messageId:l,message:[f.NotificationList,{id:a.content.item.id.toString(),header:a.content.item.title,items:a.content.item.listNotices,symbol:a.content.item.defaultIcon}],group:o})];return(a.content.notices||[]).forEach(v=>{p.push(b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:v.body}],group:o}))}),p}case"footerNotice":return[b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:a.content.item.body}],group:o})];case"Error":return[b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:a.content.message||"Something went wrong."}],group:o})];default:return[]}},r=a=>["CategorizedNoticeList","NoticeList"].includes(a.type)?(a.content.items||[]).reduce((o,g)=>(a.content.isInitialNotices&&o.push({...a,id:k.uuid(),type:g.type||a.type,content:{$type:a.content.$type,isInitialNotices:a.content.isInitialNotices,notices:g.notices,item:g}}),o),[]):a,c=new Map([["Text",1],["List",2],["Contact",3],["CategorizedNoticeList",10]]),u=[],E=t.sort((a,o)=>{const S=c.get(a.type)||20,l=c.get(o.type)||20;return S-l}).filter(a=>!a.relation).reduce((a,o)=>a.concat(r(o)),[]),K=a=>typeof a.actions.selector<"u";for(const a of E){const o=t.filter(l=>l.relation===a.id&&!K(l)),g=H({isUser:!1});(await n(a,g,o,e)).forEach(l=>{g.items.push(l)}),g.items.length&&u.push(g)}return u};class j{constructor(t,e,s,n){y(this,"globalState");y(this,"localState");y(this,"clientId");y(this,"entries");this.endpoint=t,this.events=e,this.store=s,this.container=n,this.clientId=k.uuid(),this.entries=[]}async start({silent:t}){const e=await this.store.read("globalState"),s=await this.store.read("localState"),n=await this.store.read("entries");if(this.globalState=e||this.globalState,this.localState=s||this.localState,this.entries=n||this.entries,t)return;const r=this.createInitialEnvelope();return await this.postEnvelope(r)}async sendMessage(t){const e={command:{phrase:t},globalState:this.globalState,clientId:this.clientId};return await this.postEnvelope(e)}async helpAction(){return this.postEnvelope({action:{key:"help",content:{$type:"Humany.Matching.Bots.Conversations.Actions.Help, Humany.Matching"}},globalState:this.globalState,clientId:this.clientId})}async nextAction(t){var s;const{paging:e}=t.meta;if((s=e.actions)!=null&&s.next)return this.postEnvelope({action:{key:"next",content:e.actions.next},localState:e.localState,globalState:this.globalState,clientId:this.clientId},t).then(n=>{const r=t.items.findIndex(c=>c.message[0]==="link-list");return r===-1||!n?t:{...t,meta:{...t.meta,...n[0].meta},items:[...t.items.slice(0,r),{...t.items[r],message:[n[0].items[0].message[0],{...t.items[r].message[1],...n[0].items[0].message[1]}]},...t.items.slice(r+1)]}})}async showContactMethodAction(t){const e=this.entries.find(n=>n.id===t.entryId),s=e==null?void 0:e.actions[t.actionKey];if(s)return this.postEnvelope({action:{key:t.actionKey,content:s},localState:e.localState,globalState:this.globalState,clientId:this.clientId})}async defaultAction(t){const e=this.getEntryOfAction(t);if(e)return this.postEnvelope({action:{key:t,content:e.actions[t]},localState:e.localState,globalState:this.globalState,clientId:this.clientId})}createInitialEnvelope(){return{command:{site:this.endpoint},clientId:this.clientId,globalState:{},funnel:this.container.get("$widget").name}}async postEnvelope(t,e){try{const s=await fetch(this.endpoint,this.getHttpOptions(t));if(!s.ok)throw s;const n=await s.json();return this.handleResponse(n,e)}catch(s){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let n="Something went wrong";return(s.message==="Failed to fetch"||s.message==="NetworkError when attempting to fetch resource.")&&(n="Lost connection... Please try again."),this.handleResponse({entries:[{id:k.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:n},actions:{},tags:[]}]})}}async handleResponse(t,e){this.entries=this.entries.concat(t.entries),this.store.write(this.entries,"entries");const s=t.entries.find(r=>r.type==="Widget");return s&&this.events.dispatch("provider:widget-entry",s.content),t.globalState&&(this.globalState=t.globalState,this.store.write(t.globalState,"globalState")),this.localState=t.entries.reduce((r,c)=>c.localState?c.localState:r,void 0),this.store.write(this.localState,"localState"),await V(this.container,t.entries,e)}getHttpOptions(t){const e={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"}};return t.funnel=this.container.get("$widget").name,t.localState=t.localState||this.localState,Object.assign({},e,{body:JSON.stringify(t),credentials:"same-origin"})}getEntryOfAction(t){return this.entries.find(e=>!!e.actions[t])}}class z{constructor(t){y(this,"enabled",!0);y(this,"botProviderGlobalStateKey","bot-provider-global-state");y(this,"botProviderLocalStateKey","bot-provider-local-state");y(this,"botProviderEntriesKey","bot-provider-entries");y(this,"botProviderMetaStateKey","bot-provider-conversation-meta");this.container=t}getKey(t){let e;switch(t){case"localState":e=this.botProviderLocalStateKey;break;case"globalState":e=this.botProviderGlobalStateKey;break;case"entries":e=this.botProviderEntriesKey;break;case"meta":e=this.botProviderMetaStateKey;break}return e}async read(t){const e=this.getKey(t);if(!(!this.enabled||!e))return N.readStorage(this.container,e)}async write(t,e){const s=this.getKey(e);if(!this.enabled||!s)return;(await N.createStorageWriter(this.container,s,N.StorageCategory.Necessary))(t)}}class W{constructor(t,e,s){y(this,"agent");y(this,"user");y(this,"httpClient");y(this,"events");y(this,"groups",[]);y(this,"store");this.container=t,this.conversation=e;const{events:n}=this.container.get("$widget");this.events=n,this.store=new z(t),this.agent=e.createAgent({id:"knowledge-bot-agent",name:"",avatar:void 0}),this.user=e.user;const r=q(t,s);this.httpClient=new j(r,n,this.store,this.container),this.events.subscribe("provider:widget-entry",(c,u)=>{this.onWidgetEntryReceived(u)}),this.events.subscribe("provider:open-contact-method",async(c,u)=>{const E=await this.httpClient.showContactMethodAction(u);E&&(u.contactMethod.title&&this.printUserMessage(u.contactMethod.title),this.onMessagesReceived(E))})}async initialize(){var r;const t=this.conversation.loading(),e=await this.store.read("meta");e!=null&&e.agent&&this.agent.update({name:e.agent.name,avatar:e.agent.avatar});const s=await this.conversation.isRehydrated(),n=await this.httpClient.start({silent:((r=this.conversation.options)==null?void 0:r.silent)||s});n&&this.onMessagesReceived(n),t()}async onMessagesReceived(t){this.groups=this.groups.concat(t),t.forEach(e=>{const s=e.items.map(n=>n.message);e.isUser?e.writer=this.user.print(s):e.writer=this.agent.print(s)})}async onInput(t){const e=typeof t=="string"?t:t.actionKey;switch(e){case"next":{if(typeof t=="string")return;const s=this.groups.find(n=>{var r;return n.id===((r=t.data)==null?void 0:r.groupId)});if(s){const n=await this.httpClient.nextAction(s);if(n){const r=n.items.map(c=>c.message);s.meta.paging=n==null?void 0:n.meta.paging,s.writer.update(r)}}}break;case"help":{const s=this.conversation.loading(),n=await this.httpClient.helpAction();s(),n&&this.onMessagesReceived(n)}break;default:{typeof t!="string"&&t.label&&this.printUserMessage(t.label);const s=this.conversation.loading(),n=await this.httpClient.defaultAction(e);n&&this.onMessagesReceived(n),s()}break}}printUserMessage(t){const e=H({isUser:!0,items:[{id:k.uuid(),isUser:!0,message:[m.ConversationMessageListItemType.HTML,{body:t}]}]});return this.onMessagesReceived([e]),e}async onMessageSend(t){const e=this.conversation.loading(),s=await this.httpClient.sendMessage(t);await A(this.container,"phrase",t),this.printUserMessage(t),s&&this.onMessagesReceived(s),e()}async onWidgetEntryReceived(t){if(t.agent){const e={name:t.agent.name,avatar:t.agent.avatar};this.agent.update(e),(await N.createStorageWriter(this.container,"bot-provider-conversation-meta",N.StorageCategory.Necessary))({agent:e})}}}const _=async i=>{const t=await m.ConversationPlatform.getInstance(i);m.registerCustomMessageComponent(i,f.ContactList,Promise.resolve().then(()=>require("./contact-method-list-93f20ff3.js"))),m.registerCustomMessageComponent(i,f.ContactMethod,Promise.resolve().then(()=>require("./contact-method-46dd96f8.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,u)=>{n.onMessageSend(c.text)})),r.push(s.actions.watch("conversation.action",(c,u)=>(n.onInput(c),u(c)))),r.push(s.actions.create("evaluate",c=>{const{events:u}=i.get("$widget");u.dispatch("bot-provider:evaluate",c)})),r.push(s.actions.create("submit",c=>{const{events:u}=i.get("$widget");u.dispatch("bot-provider:form-submitted",c)})),()=>{r.forEach(c=>{c()})}})};exports.KnowledgeBotProviderPlugin=_;exports.updateForm=B;
|
|
1
|
+
"use strict";var F=Object.defineProperty;var R=(i,t,e)=>t in i?F(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var y=(i,t,e)=>(R(i,typeof t!="symbol"?t+"":t,e),e);const m=require("@telia-ace/widget-conversation"),N=require("@telia-ace/widget-services"),k=require("@telia-ace/widget-utilities"),P=require("@telia-ace/widget-forms");var f=(i=>(i.ContactMethod="ace-knowledge-bot-contact-method",i.ContactList="ace-knowledge-bot-contact-list",i.FeedbackList="ace-knowledge-bot-feedback-list",i.NotificationList="ace-knowledge-bot-notification-list",i.NoGoodAlternative="ace-knowledge-bot-no-good-alternative",i))(f||{});const $=i=>{if(i){const{type:t,content:e}=i;if(t&&e)return{type:t,content:e}}},H=({isUser:i,items:t=[],meta:e={}})=>{const s=k.uuid();return{id:s,isUser:i,items:t.map(r=>({id:r.id||k.uuid(),isUser:i,groupId:s,message:r.message||[]})),meta:e}},G=({id:i,title:t,defaultIcon:e,exits:[s],exitType:n,confirmationText:r,expandFormAutomatically:c,form:u,description:E},K={})=>{const{adapter:a}=s||{Adapter:{}},{clientName:o="",settings:g={},customClientName:S=""}=a,{validation:l}=K,d={id:i.toString(),title:t,description:E,symbol:$(e),clientName:o==="custom.adapter"?S:o,expanded:!0,inline:!0,body:{}};if(o.indexOf("phone")>-1||o.indexOf("freetext")>-1){const{displayTextBeforeClick:M,textBeforeClick:p}=g;M==="true"&&(d.expanded=!1,d.title=p),o.indexOf("phone.text")>-1?d.body.phoneNumber=g.phoneNumber:d.body.freetext=g.freetext}return(o.indexOf("chat.popup")>-1||o.indexOf("link")>-1||o==="custom.adapter"&&n==="custom")&&(d.body=g,d.body.confirmationFallback=r),o.indexOf("ace")>-1&&(d.body=g),u&&u.hasValueComponents&&(l?d.body.form=P.FormBuilder.fromLegacyForm(i.toString(),u,l).get():d.body.form=P.FormBuilder.fromLegacyForm(i.toString(),u).get(),c||(d.expanded=d.inline=!1),d.body=B(d,{submit:"Submit"})),K.guideId&&(d.body.guideId=K.guideId),d},U=i=>{const{localState:t}=i;return i.tags.includes("category")&&i.tags.includes("contact")?m.ConversationMessageListItemType.ItemList:i.tags.includes("suggestion")||(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching"?m.ConversationMessageListItemType.LinkList:(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching"?f.FeedbackList:(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"?f.ContactList:m.ConversationMessageListItemType.ButtonList},q=(i,t)=>{const{knowledgeBotEndpoint:e}=t.properties();if(e)return`${e}/conversations`;const{data:s}=i.get("$settings");if(!s||!s.projection)throw new Error("Missing Knowledge Bot endpoint");return`${s.projection}/conversations`},B=(i,{submit:t,errors:e,meta:s})=>{var n;if((n=i==null?void 0:i.body)!=null&&n.form){const{body:r}=i,c=new P.FormBuilder(r.form);return r.form.layout.submit||c.createComponent(P.submitButton(t,"submit")),e&&c.setValidationErrors(e),s&&c.setMeta(s),{...r,form:c.get()}}return(i==null?void 0:i.body)||{}},A=async(i,t,e)=>{(await(await i.getAsync("dataClient")).getClient()).parameters.set(t,e)},b=({messageId:i,message:t,group:e})=>({id:i,message:t,groupId:e.id,isUser:e.isUser}),V=async(i,t,e)=>{const s=(a,o,g,S={actions:[],entryId:o.id,groupId:g})=>{const l=[];return S.actions=o.content.items.map(d=>{var p;const M={label:d.title,actionKey:d.actionKey,symbol:d.symbol?d.symbol:void 0,description:d.description||void 0};if(d.data){const v=o.actions[d.actionKey];a===f.ContactList?(l.push(d.data.id),M.data=G(d.data,{guideId:(p=v==null?void 0:v.guideId)==null?void 0:p.toString()})):M.data=d.data}return M}),a===f.ContactList&&(S.contactMethodIds=l),S},n=async(a,o,g=[],S)=>{var d,M;const l=k.uuid();switch(a.type!=="List"&&a.tags.includes("guide")&&((M=(d=a.content.hints)==null?void 0:d[0])!=null&&M.id)&&await A(i,"LastGuideId",a.content.hints[0].id),a.type){case"List":{const{header:p,items:v,html:x}=a.content,w=[];let I={actions:[],entryId:a.id,groupId:o.id};if(p&&(I.header=p),(v==null?void 0:v.length)>0){const h=U(a);if(I=s(h,a,o.id,I),g.length){const C=g.find(L=>L.tags.includes("paging")),T=g.find(L=>L.tags.includes("fallback"));if(C!=null&&C.content&&(o.meta.paging={actions:C.actions,items:C.content.items,localState:C.localState},C.content.items.forEach(L=>{I.actions.push({label:L.title,actionKey:L.actionKey,data:{groupId:S?S.id:o.id}})})),T){const L=T.content.items.find(O=>O.actionKey==="help");L&&(w.push(b({messageId:l,message:[m.ConversationMessageListItemType.Separator,void 0],group:o})),w.push(b({messageId:l,message:[f.NoGoodAlternative,{body:L.title}],group:o})))}}w.unshift(b({messageId:l,message:[h,I],group:o}))}return x&&w.unshift(b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:x}],group:o})),w}case"Text":{const p=[];if(p.push(b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:a.content.html}],group:o})),g.length){const v=g.find(h=>{var C;return h.type==="List"&&((C=h.localState)==null?void 0:C.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"}),x=g.find(h=>h.tags.includes("dialog")),w=g.find(h=>h.tags.includes("feedback")),I=g.find(h=>h.tags.includes("contact")&&h.type==="Contact");if(I&&p.push(b({messageId:l,message:[f.ContactMethod,{contactMethodId:I.content.id,groupId:o.id,guideId:I.content.guideId}],group:o})),x&&p.push(b({messageId:l,message:[m.ConversationMessageListItemType.ButtonList,{actions:x.content.items.map(h=>({label:h.title,actionKey:h.actionKey,data:h.data}))}],group:o})),v){const h=s(f.ContactList,v,o.id);p.push(b({messageId:l,message:[m.ConversationMessageListItemType.Separator,void 0],group:o})),p.push(b({messageId:l,message:[f.ContactList,h],group:o}))}w&&(w.content.html&&p.push(b({messageId:l,group:o,message:[m.ConversationMessageListItemType.HTML,{body:w.content.html}]})),p.push(b({messageId:l,group:o,message:[f.FeedbackList,{actions:w.content.items.map(h=>({actionKey:h.actionKey,label:h.title}))}]})))}return p}case"Contact":return[b({messageId:l,message:[f.ContactMethod,{contactMethodId:a.content.id,groupId:o.id,guideId:a.content.guideId}],group:o})];case"CategorizedNoticeList":{const p=[b({messageId:l,message:[f.NotificationList,{id:a.content.item.id.toString(),header:a.content.item.title,items:a.content.item.listNotices,symbol:a.content.item.defaultIcon}],group:o})];return(a.content.notices||[]).forEach(v=>{p.push(b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:v.body}],group:o}))}),p}case"footerNotice":return[b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:a.content.item.body}],group:o})];case"Error":return[b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:a.content.message||"Something went wrong."}],group:o})];default:return[]}},r=a=>["CategorizedNoticeList","NoticeList"].includes(a.type)?(a.content.items||[]).reduce((o,g)=>(a.content.isInitialNotices&&o.push({...a,id:k.uuid(),type:g.type||a.type,content:{$type:a.content.$type,isInitialNotices:a.content.isInitialNotices,notices:g.notices,item:g}}),o),[]):a,c=new Map([["Text",1],["List",2],["Contact",3],["CategorizedNoticeList",10]]),u=[],E=t.sort((a,o)=>{const S=c.get(a.type)||20,l=c.get(o.type)||20;return S-l}).filter(a=>!a.relation).reduce((a,o)=>a.concat(r(o)),[]),K=a=>typeof a.actions.selector<"u";for(const a of E){const o=t.filter(l=>l.relation===a.id&&!K(l)),g=H({isUser:!1});(await n(a,g,o,e)).forEach(l=>{g.items.push(l)}),g.items.length&&u.push(g)}return u};class j{constructor(t,e,s,n){y(this,"globalState");y(this,"localState");y(this,"clientId");y(this,"entries");this.endpoint=t,this.events=e,this.store=s,this.container=n,this.clientId=k.uuid(),this.entries=[]}async start({silent:t}){const e=await this.store.read("globalState"),s=await this.store.read("localState"),n=await this.store.read("entries");if(this.globalState=e||this.globalState,this.localState=s||this.localState,this.entries=n||this.entries,t)return;const r=this.createInitialEnvelope();return await this.postEnvelope(r)}async sendMessage(t){const e={command:{phrase:t},globalState:this.globalState,clientId:this.clientId};return await this.postEnvelope(e)}async helpAction(){return this.postEnvelope({action:{key:"help",content:{$type:"Humany.Matching.Bots.Conversations.Actions.Help, Humany.Matching"}},globalState:this.globalState,clientId:this.clientId})}async nextAction(t){var s;const{paging:e}=t.meta;if((s=e.actions)!=null&&s.next)return this.postEnvelope({action:{key:"next",content:e.actions.next},localState:e.localState,globalState:this.globalState,clientId:this.clientId},t).then(n=>{const r=t.items.findIndex(c=>c.message[0]==="link-list");return r===-1||!n?t:{...t,meta:{...t.meta,...n[0].meta},items:[...t.items.slice(0,r),{...t.items[r],message:[n[0].items[0].message[0],{...t.items[r].message[1],...n[0].items[0].message[1]}]},...t.items.slice(r+1)]}})}async showContactMethodAction(t){const e=this.entries.find(n=>n.id===t.entryId),s=e==null?void 0:e.actions[t.actionKey];if(s)return this.postEnvelope({action:{key:t.actionKey,content:s},localState:e.localState,globalState:this.globalState,clientId:this.clientId})}async defaultAction(t){const e=this.getEntryOfAction(t);if(e)return this.postEnvelope({action:{key:t,content:e.actions[t]},localState:e.localState,globalState:this.globalState,clientId:this.clientId})}createInitialEnvelope(){return{command:{site:this.endpoint},clientId:this.clientId,globalState:{},funnel:this.container.get("$widget").name}}async postEnvelope(t,e){try{const s=await fetch(this.endpoint,this.getHttpOptions(t));if(!s.ok)throw s;const n=await s.json();return this.handleResponse(n,e)}catch(s){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let n="Something went wrong";return(s.message==="Failed to fetch"||s.message==="NetworkError when attempting to fetch resource.")&&(n="Lost connection... Please try again."),this.handleResponse({entries:[{id:k.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:n},actions:{},tags:[]}]})}}async handleResponse(t,e){this.entries=this.entries.concat(t.entries),this.store.write(this.entries,"entries");const s=t.entries.find(r=>r.type==="Widget");return s&&this.events.dispatch("provider:widget-entry",s.content),t.globalState&&(this.globalState=t.globalState,this.store.write(t.globalState,"globalState")),this.localState=t.entries.reduce((r,c)=>c.localState?c.localState:r,void 0),this.store.write(this.localState,"localState"),await V(this.container,t.entries,e)}getHttpOptions(t){const e={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"}};return t.funnel=this.container.get("$widget").name,t.localState=t.localState||this.localState,Object.assign({},e,{body:JSON.stringify(t),credentials:"same-origin"})}getEntryOfAction(t){return this.entries.find(e=>!!e.actions[t])}}class z{constructor(t){y(this,"enabled",!0);y(this,"botProviderGlobalStateKey","bot-provider-global-state");y(this,"botProviderLocalStateKey","bot-provider-local-state");y(this,"botProviderEntriesKey","bot-provider-entries");y(this,"botProviderMetaStateKey","bot-provider-conversation-meta");this.container=t}getKey(t){let e;switch(t){case"localState":e=this.botProviderLocalStateKey;break;case"globalState":e=this.botProviderGlobalStateKey;break;case"entries":e=this.botProviderEntriesKey;break;case"meta":e=this.botProviderMetaStateKey;break}return e}async read(t){const e=this.getKey(t);if(!(!this.enabled||!e))return N.readStorage(this.container,e)}async write(t,e){const s=this.getKey(e);if(!this.enabled||!s)return;(await N.createStorageWriter(this.container,s,N.StorageCategory.Necessary))(t)}}class W{constructor(t,e,s){y(this,"agent");y(this,"user");y(this,"httpClient");y(this,"events");y(this,"groups",[]);y(this,"store");this.container=t,this.conversation=e;const{events:n}=this.container.get("$widget");this.events=n,this.store=new z(t),this.agent=e.createAgent({id:"knowledge-bot-agent",name:"",avatar:void 0}),this.user=e.user;const r=q(t,s);this.httpClient=new j(r,n,this.store,this.container),this.events.subscribe("provider:widget-entry",(c,u)=>{this.onWidgetEntryReceived(u)}),this.events.subscribe("provider:open-contact-method",async(c,u)=>{const E=await this.httpClient.showContactMethodAction(u);E&&(u.contactMethod.title&&this.printUserMessage(u.contactMethod.title),this.onMessagesReceived(E))})}async initialize(){var r;const t=this.conversation.loading(),e=await this.store.read("meta");e!=null&&e.agent&&this.agent.update({name:e.agent.name,avatar:e.agent.avatar});const s=await this.conversation.isRehydrated(),n=await this.httpClient.start({silent:((r=this.conversation.options)==null?void 0:r.silent)||s});n&&this.onMessagesReceived(n),t()}async onMessagesReceived(t){this.groups=this.groups.concat(t),t.forEach(e=>{const s=e.items.map(n=>n.message);e.isUser?e.writer=this.user.print(s):e.writer=this.agent.print(s)})}async onInput(t){const e=typeof t=="string"?t:t.actionKey;switch(e){case"next":{if(typeof t=="string")return;const s=this.groups.find(n=>{var r;return n.id===((r=t.data)==null?void 0:r.groupId)});if(s){const n=await this.httpClient.nextAction(s);if(n){const r=n.items.map(c=>c.message);s.meta.paging=n==null?void 0:n.meta.paging,s.writer.update(r)}}}break;case"help":{const s=this.conversation.loading(),n=await this.httpClient.helpAction();s(),n&&this.onMessagesReceived(n)}break;default:{typeof t!="string"&&t.label&&this.printUserMessage(t.label);const s=this.conversation.loading(),n=await this.httpClient.defaultAction(e);n&&this.onMessagesReceived(n),s()}break}}printUserMessage(t){const e=H({isUser:!0,items:[{id:k.uuid(),isUser:!0,message:[m.ConversationMessageListItemType.HTML,{body:t}]}]});return this.onMessagesReceived([e]),e}async onMessageSend(t){const e=this.conversation.loading(),s=await this.httpClient.sendMessage(t);await A(this.container,"phrase",t),this.printUserMessage(t),s&&this.onMessagesReceived(s),e()}async onWidgetEntryReceived(t){if(t.agent){const e={name:t.agent.name,avatar:t.agent.avatar};this.agent.update(e),(await N.createStorageWriter(this.container,"bot-provider-conversation-meta",N.StorageCategory.Necessary))({agent:e})}}}const _=async i=>{const t=await m.ConversationPlatform.getInstance(i);m.registerCustomMessageComponent(i,f.ContactList,Promise.resolve().then(()=>require("./contact-method-list-52fb36fb.js"))),m.registerCustomMessageComponent(i,f.ContactMethod,Promise.resolve().then(()=>require("./contact-method-35f483b1.js"))),m.registerCustomMessageComponent(i,f.NotificationList,Promise.resolve().then(()=>require("./notification-list-d4d9695d.js"))),m.registerCustomMessageComponent(i,f.NoGoodAlternative,Promise.resolve().then(()=>require("./no-good-alternative-0ced8ab9.js"))),m.registerCustomMessageComponent(i,f.FeedbackList,Promise.resolve().then(()=>require("./feedback-list-6f877c77.js"))),t.registerProvider("ace-knowledge-bot",(e,s)=>{const n=new W(i,e,s);n.initialize();const r=[];return r.push(s.actions.watch("conversation.user-submit",(c,u)=>{n.onMessageSend(c.text)})),r.push(s.actions.watch("conversation.action",(c,u)=>(n.onInput(c),u(c)))),r.push(s.actions.create("evaluate",c=>{const{events:u}=i.get("$widget");u.dispatch("bot-provider:evaluate",c)})),r.push(s.actions.create("submit",c=>{const{events:u}=i.get("$widget");u.dispatch("bot-provider:form-submitted",c)})),()=>{r.forEach(c=>{c()})}})};exports.KnowledgeBotProviderPlugin=_;exports.updateForm=B;
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-b33b8ed1.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");require("@telia-ace/widget-utilities");require("@telia-ace/widget-forms");exports.ConversationPlugin=e.KnowledgeBotProviderPlugin;
|
package/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
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-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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`
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: center;
|
|
5
|
+
${o.messageContentPadding}
|
|
6
6
|
`,a=i(n.Button)`
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
> i,
|
|
8
|
+
svg {
|
|
9
|
+
margin-right: ${e=>{var t;return(t=e.theme.sizes)==null?void 0:t.small}};
|
|
10
|
+
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
&:focus-visible {
|
|
13
|
+
${n.borderTabStyle}
|
|
14
|
+
}
|
|
15
15
|
`;exports.default=r;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as o, jsxs as i } from "react/jsx-runtime";
|
|
2
2
|
import s from "@emotion/styled";
|
|
3
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-
|
|
4
|
+
import { m } from "./styles-5f6d3622.mjs";
|
|
5
5
|
import "@emotion/react";
|
|
6
6
|
const y = ({ body: t }) => {
|
|
7
7
|
const e = n();
|
|
@@ -29,22 +29,22 @@ const y = ({ body: t }) => {
|
|
|
29
29
|
}
|
|
30
30
|
) });
|
|
31
31
|
}, c = s.div`
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
display: flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
justify-content: center;
|
|
35
|
+
${m}
|
|
36
36
|
`, p = s(a)`
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
> i,
|
|
38
|
+
svg {
|
|
39
|
+
margin-right: ${(t) => {
|
|
40
40
|
var e;
|
|
41
41
|
return (e = t.theme.sizes) == null ? void 0 : e.small;
|
|
42
42
|
}};
|
|
43
|
-
|
|
43
|
+
}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
&:focus-visible {
|
|
46
|
+
${l}
|
|
47
|
+
}
|
|
48
48
|
`;
|
|
49
49
|
export {
|
|
50
50
|
y as default
|
|
@@ -3,7 +3,7 @@ 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
5
|
import { useMemo as p } from "react";
|
|
6
|
-
import { m as c } from "./styles-
|
|
6
|
+
import { m as c } from "./styles-5f6d3622.mjs";
|
|
7
7
|
import "@emotion/react";
|
|
8
8
|
const $ = ({
|
|
9
9
|
id: o,
|
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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
2
|
${g.messageContentPadding}
|
|
3
3
|
min-width: 10em;
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/knowledge-widget-bot-provider",
|
|
3
|
-
"version": "1.1.2-rc.
|
|
3
|
+
"version": "1.1.2-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.1.2-rc.
|
|
14
|
-
"@telia-ace/knowledge-widget-adapters": "^1.1.2-rc.
|
|
15
|
-
"@telia-ace/knowledge-widget-ui": "^1.1.2-rc.
|
|
16
|
-
"@telia-ace/widget-conversation": "^1.1.2-rc.
|
|
17
|
-
"@telia-ace/widget-forms": "^1.1.2-rc.
|
|
18
|
-
"@telia-ace/widget-services": "^1.1.2-rc.
|
|
19
|
-
"@telia-ace/widget-utilities": "^1.1.2-rc.
|
|
13
|
+
"@telia-ace/knowledge-data-client": "^1.1.2-rc.2",
|
|
14
|
+
"@telia-ace/knowledge-widget-adapters": "^1.1.2-rc.2",
|
|
15
|
+
"@telia-ace/knowledge-widget-ui": "^1.1.2-rc.2",
|
|
16
|
+
"@telia-ace/widget-conversation": "^1.1.2-rc.2",
|
|
17
|
+
"@telia-ace/widget-forms": "^1.1.2-rc.2",
|
|
18
|
+
"@telia-ace/widget-services": "^1.1.2-rc.2",
|
|
19
|
+
"@telia-ace/widget-utilities": "^1.1.2-rc.2",
|
|
20
20
|
"@webprovisions/platform": "^1.1.4",
|
|
21
|
-
"@telia-ace/knowledge-widget-core": "^1.1.2-rc.
|
|
21
|
+
"@telia-ace/knowledge-widget-core": "^1.1.2-rc.2"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@emotion/react": "11.11.1",
|
package/styles-094b07e5.js
DELETED
package/styles-95d5aa50.mjs
DELETED