@telia-ace/conversational-hub-bot-provider 1.3.41-rc.1 → 1.3.41
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-D9OmD693.js +3 -0
- package/{contact-method-ea565b1e.mjs → contact-method-ZLVXep1Y.mjs} +15 -18
- package/contact-method-list-BzAGHFFX.js +28 -0
- package/{contact-method-list-1d76af88.mjs → contact-method-list-CbAeYLrS.mjs} +25 -32
- package/{index-cd2b9c3e.mjs → index-CGyJXK5J.mjs} +126 -154
- package/index-DnKKEE-w.js +1 -0
- package/index.js +1 -1
- package/index.mjs +3 -8
- package/package.json +10 -10
- package/utils.d.ts +4 -6
- package/contact-method-bd8934cb.js +0 -3
- package/contact-method-list-bf5e35d0.js +0 -28
- package/index-059f1922.js +0 -1
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("react/jsx-runtime"),R=require("@emotion/styled"),F=require("@telia-ace/knowledge-data-client"),$=require("@telia-ace/knowledge-widget-adapters"),v=require("@telia-ace/knowledge-widget-ui"),z=require("@telia-ace/widget-forms"),O=require("@telia-ace/widget-utilities"),l=require("react"),x=require("./index-DnKKEE-w.js"),U=({contactMethodId:s,guideId:n,groupId:b,className:T})=>{var h,q,k,S,j;const[e,u]=l.useState(),c=v.useContainer(),A=v.useDispatch(),f=l.useRef(!0),y=v.useConversation();l.useEffect(()=>{const{events:t}=c.get("$widget"),m=t.subscribe("conversational-hub-provider:form-submitted",async(i,o)=>{var D;if(((D=o.form.meta)==null?void 0:D.groupId)!==b||o.id!==(e==null?void 0: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:_}=await p.validate(r);if(!g){const E=new z.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)}),a=t.subscribe("conversational-hub-provider:evaluate",async(i,o)=>{if(String(o.id)!==String(s))return;const r=await(await c.getAsync("contactMethods")).evaluate(e);let d={...e,body:{...e.body,form:r}};const g=x.updateForm(d,{submit:"Submit",errors:{},meta:{groupId:b}});d={...d,body:g},u(d)});return()=>{m(),a()}},[c,e,u,y]);const C=(t,m,a=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=C(t[i],m,t);if(o!==void 0)return o}},w=l.useCallback(async t=>{const a=await(await F.DataClient.getInstance(c)).fetch(F.DataType.ContactMethod,{contactMethodId:t,guideId:n},{noCache:!0,isBot:!0}),i=x.updateForm(a,{submit:"Submit",errors:{},meta:{groupId:b}});if(a.body=i,a.body.guideId=n,!f.current)return null;u(a)},[f]);return l.useEffect(()=>(w(s),()=>{f.current=!1}),[s,w]),e?(e.clientName==="ace.callback"&&((h=e.body)!=null&&h.entrance)&&C(e,(q=e.body)==null?void 0:q.entrance),N.jsx(W,{...e,body:{...e.body,form:e.body.form?{...e.body.form,data:(k=e.body.form)==null?void 0:k.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:O.appendClassNames("humany-bot-contact-method",T)})):null},W=R($.ContactMethod)`
|
|
2
|
+
padding: ${s=>{var n;return(n=s.theme.sizes)==null?void 0:n.normal}} ${s=>{var n;return(n=s.theme.sizes)==null?void 0:n.medium}};
|
|
3
|
+
`;exports.default=U;
|
|
@@ -6,11 +6,8 @@ import { useContainer as _, useDispatch as G, useConversation as I } from "@teli
|
|
|
6
6
|
import { FormBuilder as M } 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-
|
|
10
|
-
|
|
11
|
-
import "@telia-ace/widget-services";
|
|
12
|
-
import "@webprovisions/platform";
|
|
13
|
-
const nt = ({
|
|
9
|
+
import { u as j } from "./index-CGyJXK5J.mjs";
|
|
10
|
+
const et = ({
|
|
14
11
|
contactMethodId: a,
|
|
15
12
|
guideId: n,
|
|
16
13
|
groupId: f,
|
|
@@ -21,7 +18,7 @@ const nt = ({
|
|
|
21
18
|
$(() => {
|
|
22
19
|
const { events: e } = d.get("$widget"), c = e.subscribe(
|
|
23
20
|
"conversational-hub-provider:form-submitted",
|
|
24
|
-
async (
|
|
21
|
+
async (i, o) => {
|
|
25
22
|
var D;
|
|
26
23
|
if (((D = o.form.meta) == null ? void 0 : D.groupId) !== f || o.id !== (t == null ? void 0 : t.id))
|
|
27
24
|
return;
|
|
@@ -48,9 +45,9 @@ const nt = ({
|
|
|
48
45
|
const F = await y.submit(r);
|
|
49
46
|
r.confirmation = F, m(r);
|
|
50
47
|
}
|
|
51
|
-
),
|
|
48
|
+
), s = e.subscribe(
|
|
52
49
|
"conversational-hub-provider:evaluate",
|
|
53
|
-
async (
|
|
50
|
+
async (i, o) => {
|
|
54
51
|
if (String(o.id) !== String(a))
|
|
55
52
|
return;
|
|
56
53
|
const r = await (await d.getAsync(
|
|
@@ -75,19 +72,19 @@ const nt = ({
|
|
|
75
72
|
}
|
|
76
73
|
);
|
|
77
74
|
return () => {
|
|
78
|
-
c(),
|
|
75
|
+
c(), s();
|
|
79
76
|
};
|
|
80
77
|
}, [d, t, m, l]);
|
|
81
|
-
const C = (e, c,
|
|
78
|
+
const C = (e, c, s = null) => {
|
|
82
79
|
if (e["ui:component"] && e["ui:component"] === "Date")
|
|
83
80
|
return Object.assign(e, {
|
|
84
81
|
"ui:bot": !0,
|
|
85
82
|
"ui:entrance": c
|
|
86
83
|
}), e;
|
|
87
|
-
for (const
|
|
88
|
-
if (typeof e[
|
|
84
|
+
for (const i in e)
|
|
85
|
+
if (typeof e[i] == "object" && e[i] !== null) {
|
|
89
86
|
const o = C(
|
|
90
|
-
e[
|
|
87
|
+
e[i],
|
|
91
88
|
c,
|
|
92
89
|
e
|
|
93
90
|
);
|
|
@@ -96,21 +93,21 @@ const nt = ({
|
|
|
96
93
|
}
|
|
97
94
|
}, v = H(
|
|
98
95
|
async (e) => {
|
|
99
|
-
const
|
|
96
|
+
const s = await (await z.getInstance(d)).fetch(
|
|
100
97
|
A.ContactMethod,
|
|
101
98
|
{
|
|
102
99
|
contactMethodId: e,
|
|
103
100
|
guideId: n
|
|
104
101
|
},
|
|
105
102
|
{ noCache: !0, isBot: !0 }
|
|
106
|
-
),
|
|
103
|
+
), i = j(s, {
|
|
107
104
|
submit: "Submit",
|
|
108
105
|
errors: {},
|
|
109
106
|
meta: { groupId: f }
|
|
110
107
|
});
|
|
111
|
-
if (
|
|
108
|
+
if (s.body = i, s.body.guideId = n, !b.current)
|
|
112
109
|
return null;
|
|
113
|
-
m(
|
|
110
|
+
m(s);
|
|
114
111
|
},
|
|
115
112
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
116
113
|
[b]
|
|
@@ -148,5 +145,5 @@ const nt = ({
|
|
|
148
145
|
}};
|
|
149
146
|
`;
|
|
150
147
|
export {
|
|
151
|
-
|
|
148
|
+
et as default
|
|
152
149
|
};
|
|
@@ -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-D9OmD693.js"),j=({actions:e,entryId:t,groupId:x})=>{const C=g.useDispatch(),d=g.useContainer(),[h,M]=l.useState([]),[c,b]=l.useState([]);return l.useEffect(()=>{d.getAsync("contactMethods").then(n=>{if(!n)return;const r=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,o)=>{if(typeof s.onClick=="function"&&s.onClick(p,o),!p.defaultPrevented)if(o.inline&&!o.expanded)b([...c,o.id]);else{const{events:f}=d.get("$widget");f.dispatch("conversational-hub-provider:open-contact-method",{entryId:t,contactMethod:o,actionKey:i.actionKey}),f.dispatch("tracking:contact-method-list-item-clicked",o)}}}});Promise.all(r).then(i=>{M(i.filter(s=>!!s))})})},[e,d,t,c]),h.length?a.jsx(S,{className:"humany-bot-contact-list",contactMethods:h,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,35 +1,28 @@
|
|
|
1
1
|
import { jsx as a } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import l from "@emotion/styled";
|
|
3
3
|
import { ContactList as M, ContactMethod as b } from "@telia-ace/knowledge-widget-adapters";
|
|
4
4
|
import { useDispatch as $, 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-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import "@telia-ace/widget-utilities";
|
|
10
|
-
import "./index-cd2b9c3e.mjs";
|
|
11
|
-
import "@telia-ace/widget-conversation";
|
|
12
|
-
import "@telia-ace/widget-services";
|
|
13
|
-
import "@webprovisions/platform";
|
|
14
|
-
const H = ({ actions: t, entryId: e, groupId: y }) => {
|
|
15
|
-
const g = $(), d = k(), [l, x] = f([]), [r, C] = f([]);
|
|
6
|
+
import S from "./contact-method-ZLVXep1Y.mjs";
|
|
7
|
+
const P = ({ actions: t, entryId: e, groupId: y }) => {
|
|
8
|
+
const g = $(), d = k(), [m, x] = f([]), [c, C] = f([]);
|
|
16
9
|
return E(() => {
|
|
17
|
-
d.getAsync("contactMethods").then((
|
|
18
|
-
if (!
|
|
10
|
+
d.getAsync("contactMethods").then((n) => {
|
|
11
|
+
if (!n)
|
|
19
12
|
return;
|
|
20
|
-
const
|
|
13
|
+
const r = t.map(async (i) => {
|
|
21
14
|
var p;
|
|
22
|
-
if (!((p =
|
|
15
|
+
if (!((p = i.data) != null && p.clientName))
|
|
23
16
|
return null;
|
|
24
|
-
const o = await
|
|
17
|
+
const o = await n.handleAdapters(i.data);
|
|
25
18
|
return {
|
|
26
19
|
...o,
|
|
27
|
-
...
|
|
28
|
-
description:
|
|
20
|
+
...i.data,
|
|
21
|
+
description: i.data.description ? i.data.description : o.description,
|
|
29
22
|
onClick: (u, s) => {
|
|
30
23
|
if (typeof o.onClick == "function" && o.onClick(u, s), !u.defaultPrevented)
|
|
31
24
|
if (s.inline && !s.expanded)
|
|
32
|
-
C([...
|
|
25
|
+
C([...c, s.id]);
|
|
33
26
|
else {
|
|
34
27
|
const { events: h } = d.get("$widget");
|
|
35
28
|
h.dispatch(
|
|
@@ -37,7 +30,7 @@ const H = ({ actions: t, entryId: e, groupId: y }) => {
|
|
|
37
30
|
{
|
|
38
31
|
entryId: e,
|
|
39
32
|
contactMethod: s,
|
|
40
|
-
actionKey:
|
|
33
|
+
actionKey: i.actionKey
|
|
41
34
|
}
|
|
42
35
|
), h.dispatch(
|
|
43
36
|
"tracking:contact-method-list-item-clicked",
|
|
@@ -47,27 +40,27 @@ const H = ({ actions: t, entryId: e, groupId: y }) => {
|
|
|
47
40
|
}
|
|
48
41
|
};
|
|
49
42
|
});
|
|
50
|
-
Promise.all(
|
|
51
|
-
x(
|
|
43
|
+
Promise.all(r).then((i) => {
|
|
44
|
+
x(i.filter((o) => !!o));
|
|
52
45
|
});
|
|
53
46
|
});
|
|
54
|
-
}, [t, d, e,
|
|
47
|
+
}, [t, d, e, c]), m.length ? /* @__PURE__ */ a(
|
|
55
48
|
j,
|
|
56
49
|
{
|
|
57
50
|
className: "humany-bot-contact-list",
|
|
58
|
-
contactMethods:
|
|
51
|
+
contactMethods: m,
|
|
59
52
|
dispatch: g,
|
|
60
|
-
itemRenderer: (
|
|
53
|
+
itemRenderer: (n, r) => (c.includes(n.id) || n.expanded) && n.inline || n.clientName === "custom.link" ? /* @__PURE__ */ a(
|
|
61
54
|
v,
|
|
62
55
|
{
|
|
63
|
-
contactMethodId:
|
|
56
|
+
contactMethodId: n.id,
|
|
64
57
|
groupId: y,
|
|
65
|
-
guideId:
|
|
58
|
+
guideId: n.body.guideId
|
|
66
59
|
}
|
|
67
|
-
) : /* @__PURE__ */ a(z, { ...
|
|
60
|
+
) : /* @__PURE__ */ a(z, { ...n, ...r })
|
|
68
61
|
}
|
|
69
62
|
) : null;
|
|
70
|
-
}, j =
|
|
63
|
+
}, j = l(M)`
|
|
71
64
|
> ul > li {
|
|
72
65
|
a {
|
|
73
66
|
display: flex;
|
|
@@ -79,7 +72,7 @@ const H = ({ actions: t, entryId: e, groupId: y }) => {
|
|
|
79
72
|
${(t) => t.theme.border && `border-bottom: ${t.theme.border};`}
|
|
80
73
|
}
|
|
81
74
|
}
|
|
82
|
-
`, v =
|
|
75
|
+
`, v = l(S)`
|
|
83
76
|
i {
|
|
84
77
|
margin: 0 ${(t) => {
|
|
85
78
|
var e;
|
|
@@ -89,7 +82,7 @@ const H = ({ actions: t, entryId: e, groupId: y }) => {
|
|
|
89
82
|
justify-content: center;
|
|
90
83
|
align-items: center;
|
|
91
84
|
}
|
|
92
|
-
`, z =
|
|
85
|
+
`, z = l(b)`
|
|
93
86
|
padding: ${(t) => {
|
|
94
87
|
var e;
|
|
95
88
|
return (e = t.theme.sizes) == null ? void 0 : e.medium;
|
|
@@ -105,5 +98,5 @@ const H = ({ actions: t, entryId: e, groupId: y }) => {
|
|
|
105
98
|
}
|
|
106
99
|
`;
|
|
107
100
|
export {
|
|
108
|
-
|
|
101
|
+
P as default
|
|
109
102
|
};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
var tt = Object.defineProperty;
|
|
2
2
|
var et = (n, e, i) => e in n ? tt(n, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : n[e] = i;
|
|
3
|
-
var
|
|
4
|
-
import { ConversationMessageListItemType as A, registerCustomMessageComponent as
|
|
5
|
-
import { readStorage as
|
|
6
|
-
import { uuid as
|
|
7
|
-
import { FormBuilder as
|
|
3
|
+
var $ = (n, e, i) => et(n, typeof e != "symbol" ? e + "" : e, i);
|
|
4
|
+
import { ConversationMessageListItemType as A, registerCustomMessageComponent as W, ConversationPlatform as nt } from "@telia-ace/widget-conversation";
|
|
5
|
+
import { readStorage as q, createStorageWriter as Q, StorageCategory as X } from "@telia-ace/widget-services";
|
|
6
|
+
import { uuid as _, Logger as G } from "@telia-ace/widget-utilities";
|
|
7
|
+
import { FormBuilder as J, submitButton as it } from "@telia-ace/widget-forms";
|
|
8
8
|
import { createConfigurationApi as ot } from "@webprovisions/platform";
|
|
9
9
|
class st {
|
|
10
10
|
constructor(e) {
|
|
11
|
-
|
|
11
|
+
$(this, "enabled", !0);
|
|
12
12
|
// set whether or not to store data
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
$(this, "botProviderGlobalStateKey", "bot-provider-global-state");
|
|
14
|
+
$(this, "botProviderLocalStateKey", "bot-provider-local-state");
|
|
15
|
+
$(this, "botProviderEntriesKey", "bot-provider-entries");
|
|
16
|
+
$(this, "botProviderMetaStateKey", "bot-provider-conversation-meta");
|
|
17
17
|
this.container = e;
|
|
18
18
|
}
|
|
19
19
|
getKey(e) {
|
|
@@ -37,7 +37,7 @@ class st {
|
|
|
37
37
|
async read(e) {
|
|
38
38
|
const i = this.getKey(e);
|
|
39
39
|
if (!(!this.enabled || !i))
|
|
40
|
-
return
|
|
40
|
+
return q(this.container, i);
|
|
41
41
|
}
|
|
42
42
|
async write(e, i) {
|
|
43
43
|
const t = this.getKey(i);
|
|
@@ -50,7 +50,7 @@ class st {
|
|
|
50
50
|
))(e);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
var
|
|
53
|
+
var k = /* @__PURE__ */ ((n) => (n.ContactMethod = "ace-conversational-hub-contact-method", n.ContactList = "ace-conversational-hub-contact-list", n))(k || {});
|
|
54
54
|
const at = (n) => {
|
|
55
55
|
if (n) {
|
|
56
56
|
const { type: e, content: i } = n;
|
|
@@ -62,12 +62,12 @@ const at = (n) => {
|
|
|
62
62
|
items: e = [],
|
|
63
63
|
meta: i = {}
|
|
64
64
|
}) => {
|
|
65
|
-
const t =
|
|
65
|
+
const t = _();
|
|
66
66
|
return {
|
|
67
67
|
id: t,
|
|
68
68
|
isUser: n,
|
|
69
69
|
items: e.map((y) => ({
|
|
70
|
-
id: y.id ||
|
|
70
|
+
id: y.id || _(),
|
|
71
71
|
isUser: n,
|
|
72
72
|
groupId: t,
|
|
73
73
|
message: y.message || []
|
|
@@ -82,17 +82,17 @@ const at = (n) => {
|
|
|
82
82
|
exitType: d,
|
|
83
83
|
confirmationText: y,
|
|
84
84
|
expandFormAutomatically: f,
|
|
85
|
-
form:
|
|
86
|
-
description:
|
|
85
|
+
form: P,
|
|
86
|
+
description: O
|
|
87
87
|
}, a = {}) => {
|
|
88
|
-
const { adapter: l } = t || {
|
|
88
|
+
const { adapter: l } = t || {}, {
|
|
89
89
|
clientName: u = "",
|
|
90
90
|
settings: v = {},
|
|
91
91
|
customClientName: m = ""
|
|
92
|
-
} = l, { validation:
|
|
92
|
+
} = l, { validation: S } = a, g = {
|
|
93
93
|
id: n.toString(),
|
|
94
94
|
title: e,
|
|
95
|
-
description:
|
|
95
|
+
description: O,
|
|
96
96
|
symbol: at(i),
|
|
97
97
|
clientName: u === "custom.adapter" ? m : u,
|
|
98
98
|
expanded: !0,
|
|
@@ -100,20 +100,20 @@ const at = (n) => {
|
|
|
100
100
|
body: {}
|
|
101
101
|
};
|
|
102
102
|
if (u.indexOf("phone") > -1 || u.indexOf("freetext") > -1) {
|
|
103
|
-
const { displayTextBeforeClick:
|
|
104
|
-
|
|
103
|
+
const { displayTextBeforeClick: h, textBeforeClick: x } = v;
|
|
104
|
+
h === "true" && (g.expanded = !1, g.title = x), u.indexOf("phone.text") > -1 ? g.body.phoneNumber = v.phoneNumber : g.body.freetext = v.freetext;
|
|
105
105
|
}
|
|
106
|
-
return (u.indexOf("chat.popup") > -1 || u.indexOf("link") > -1 || u === "custom.adapter" && d === "custom") && (g.body = v, g.body.confirmationFallback = y), u.indexOf("ace") > -1 && (g.body = v),
|
|
106
|
+
return (u.indexOf("chat.popup") > -1 || u.indexOf("link") > -1 || u === "custom.adapter" && d === "custom") && (g.body = v, g.body.confirmationFallback = y), u.indexOf("ace") > -1 && (g.body = v), P && P.hasValueComponents && (S ? g.body.form = J.fromLegacyForm(
|
|
107
107
|
n.toString(),
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
).get() : g.body.form =
|
|
108
|
+
P,
|
|
109
|
+
S
|
|
110
|
+
).get() : g.body.form = J.fromLegacyForm(
|
|
111
111
|
n.toString(),
|
|
112
|
-
|
|
112
|
+
P
|
|
113
113
|
).get(), f || (g.expanded = g.inline = !1), g.body = dt(g, { submit: "Submit" })), a.guideId && (g.body.guideId = a.guideId), g;
|
|
114
114
|
}, lt = (n) => {
|
|
115
115
|
const { localState: e } = n;
|
|
116
|
-
return n.tags.includes("category") && n.tags.includes("contact") ? A.ItemList : n.tags.includes("suggestion") ? A.LinkList : (e == null ? void 0 : e.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching" ?
|
|
116
|
+
return n.tags.includes("category") && n.tags.includes("contact") ? A.ItemList : n.tags.includes("suggestion") ? A.LinkList : (e == null ? void 0 : e.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching" ? k.ContactList : A.ButtonList;
|
|
117
117
|
}, dt = (n, {
|
|
118
118
|
submit: e,
|
|
119
119
|
errors: i,
|
|
@@ -121,7 +121,7 @@ const at = (n) => {
|
|
|
121
121
|
}) => {
|
|
122
122
|
var d;
|
|
123
123
|
if ((d = n == null ? void 0 : n.body) != null && d.form) {
|
|
124
|
-
const { body: y } = n, f = new
|
|
124
|
+
const { body: y } = n, f = new J(y.form);
|
|
125
125
|
return y.form.layout.submit || f.createComponent(it(e, "submit")), i && f.setValidationErrors(i), t && f.setMeta(t), {
|
|
126
126
|
...y,
|
|
127
127
|
form: f.get()
|
|
@@ -146,40 +146,39 @@ const at = (n) => {
|
|
|
146
146
|
groupId: u
|
|
147
147
|
}) => {
|
|
148
148
|
const m = [];
|
|
149
|
-
return v.actions = l.content.items.map((
|
|
150
|
-
var
|
|
149
|
+
return v.actions = l.content.items.map((S) => {
|
|
150
|
+
var h;
|
|
151
151
|
const g = {
|
|
152
|
-
label:
|
|
153
|
-
actionKey:
|
|
154
|
-
symbol:
|
|
155
|
-
description:
|
|
152
|
+
label: S.title,
|
|
153
|
+
actionKey: S.actionKey,
|
|
154
|
+
symbol: S.symbol ? S.symbol : void 0,
|
|
155
|
+
description: S.description || void 0
|
|
156
156
|
};
|
|
157
|
-
if (
|
|
158
|
-
const x = l.actions[
|
|
159
|
-
a ===
|
|
160
|
-
guideId: (
|
|
161
|
-
})) : g.data =
|
|
157
|
+
if (S.data) {
|
|
158
|
+
const x = l.actions[S.actionKey];
|
|
159
|
+
a === k.ContactList ? (m.push(S.data.id), g.data = ct(S.data, {
|
|
160
|
+
guideId: (h = x == null ? void 0 : x.guideId) == null ? void 0 : h.toString()
|
|
161
|
+
})) : g.data = S.data;
|
|
162
162
|
}
|
|
163
163
|
return g;
|
|
164
|
-
}), a ===
|
|
164
|
+
}), a === k.ContactList && (v.contactMethodIds = m), v;
|
|
165
165
|
}, d = async (a, l, u = [], v) => {
|
|
166
|
-
var
|
|
167
|
-
const m =
|
|
168
|
-
switch (a.type !== "List" && a.tags.includes("guide") && ((g = (
|
|
166
|
+
var S, g;
|
|
167
|
+
const m = _();
|
|
168
|
+
switch (a.type !== "List" && a.tags.includes("guide") && ((g = (S = a.content.hints) == null ? void 0 : S[0]) != null && g.id) && await ut(
|
|
169
169
|
n,
|
|
170
170
|
"LastGuideId",
|
|
171
171
|
a.content.hints[0].id
|
|
172
172
|
), a.type) {
|
|
173
173
|
case "List": {
|
|
174
|
-
if (!a.content)
|
|
175
|
-
|
|
176
|
-
const { items: p, html: x } = a.content, O = [];
|
|
174
|
+
if (!a.content) return [];
|
|
175
|
+
const { items: h, html: x } = a.content, M = [];
|
|
177
176
|
let I = {
|
|
178
177
|
actions: [],
|
|
179
178
|
entryId: a.id,
|
|
180
179
|
groupId: l.id
|
|
181
180
|
};
|
|
182
|
-
if ((
|
|
181
|
+
if ((h == null ? void 0 : h.length) > 0) {
|
|
183
182
|
const N = lt(a);
|
|
184
183
|
if (I = t(
|
|
185
184
|
N,
|
|
@@ -204,7 +203,7 @@ const at = (n) => {
|
|
|
204
203
|
});
|
|
205
204
|
}));
|
|
206
205
|
}
|
|
207
|
-
|
|
206
|
+
M.unshift(
|
|
208
207
|
K({
|
|
209
208
|
messageId: m,
|
|
210
209
|
message: [N, I],
|
|
@@ -212,17 +211,17 @@ const at = (n) => {
|
|
|
212
211
|
})
|
|
213
212
|
);
|
|
214
213
|
}
|
|
215
|
-
return x &&
|
|
214
|
+
return x && M.unshift(
|
|
216
215
|
K({
|
|
217
216
|
messageId: m,
|
|
218
217
|
message: [A.HTML, { body: x }],
|
|
219
218
|
group: l
|
|
220
219
|
})
|
|
221
|
-
),
|
|
220
|
+
), M;
|
|
222
221
|
}
|
|
223
222
|
case "Text": {
|
|
224
|
-
const
|
|
225
|
-
if (
|
|
223
|
+
const h = [];
|
|
224
|
+
if (h.push(
|
|
226
225
|
K({
|
|
227
226
|
messageId: m,
|
|
228
227
|
message: [
|
|
@@ -237,29 +236,29 @@ const at = (n) => {
|
|
|
237
236
|
var N;
|
|
238
237
|
return I.type === "List" && ((N = I.localState) == null ? void 0 : N.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching";
|
|
239
238
|
}
|
|
240
|
-
),
|
|
239
|
+
), M = u.find(
|
|
241
240
|
(I) => I.tags.includes("contact") && I.type === "Contact"
|
|
242
241
|
);
|
|
243
|
-
if (
|
|
242
|
+
if (M && h.push(
|
|
244
243
|
K({
|
|
245
244
|
messageId: m,
|
|
246
245
|
message: [
|
|
247
|
-
|
|
246
|
+
k.ContactMethod,
|
|
248
247
|
{
|
|
249
|
-
contactMethodId:
|
|
248
|
+
contactMethodId: M.content.id,
|
|
250
249
|
groupId: l.id,
|
|
251
|
-
guideId:
|
|
250
|
+
guideId: M.content.guideId
|
|
252
251
|
}
|
|
253
252
|
],
|
|
254
253
|
group: l
|
|
255
254
|
})
|
|
256
255
|
), x) {
|
|
257
256
|
const I = t(
|
|
258
|
-
|
|
257
|
+
k.ContactList,
|
|
259
258
|
x,
|
|
260
259
|
l.id
|
|
261
260
|
);
|
|
262
|
-
|
|
261
|
+
h.push(
|
|
263
262
|
K({
|
|
264
263
|
messageId: m,
|
|
265
264
|
message: [
|
|
@@ -268,23 +267,23 @@ const at = (n) => {
|
|
|
268
267
|
],
|
|
269
268
|
group: l
|
|
270
269
|
})
|
|
271
|
-
),
|
|
270
|
+
), h.push(
|
|
272
271
|
K({
|
|
273
272
|
messageId: m,
|
|
274
|
-
message: [
|
|
273
|
+
message: [k.ContactList, I],
|
|
275
274
|
group: l
|
|
276
275
|
})
|
|
277
276
|
);
|
|
278
277
|
}
|
|
279
278
|
}
|
|
280
|
-
return
|
|
279
|
+
return h;
|
|
281
280
|
}
|
|
282
281
|
case "Contact":
|
|
283
282
|
return [
|
|
284
283
|
K({
|
|
285
284
|
messageId: m,
|
|
286
285
|
message: [
|
|
287
|
-
|
|
286
|
+
k.ContactMethod,
|
|
288
287
|
{
|
|
289
288
|
contactMethodId: a.content.id,
|
|
290
289
|
groupId: l.id,
|
|
@@ -314,13 +313,13 @@ const at = (n) => {
|
|
|
314
313
|
["Text", 1],
|
|
315
314
|
["List", 2],
|
|
316
315
|
["Contact", 3]
|
|
317
|
-
]), f = [],
|
|
316
|
+
]), f = [], P = e.sort((a, l) => {
|
|
318
317
|
const v = y.get(a.type) || 20, m = y.get(l.type) || 20;
|
|
319
318
|
return v - m;
|
|
320
|
-
}).filter((a) => !a.relation).reduce((a, l) => a.concat(l), []),
|
|
321
|
-
for (const a of
|
|
319
|
+
}).filter((a) => !a.relation).reduce((a, l) => a.concat(l), []), O = (a) => typeof a.actions.selector < "u";
|
|
320
|
+
for (const a of P) {
|
|
322
321
|
const l = e.filter(
|
|
323
|
-
(m) => m.relation === a.id && !
|
|
322
|
+
(m) => m.relation === a.id && !O(m)
|
|
324
323
|
), u = rt({ isUser: !1 });
|
|
325
324
|
(await d(a, u, l, i)).forEach((m) => {
|
|
326
325
|
u.items.push(m);
|
|
@@ -330,11 +329,11 @@ const at = (n) => {
|
|
|
330
329
|
};
|
|
331
330
|
class mt {
|
|
332
331
|
constructor(e, i, t, d) {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
this.endpoint = e, this.events = i, this.store = t, this.container = d, this.clientId =
|
|
332
|
+
$(this, "globalState");
|
|
333
|
+
$(this, "localState");
|
|
334
|
+
$(this, "clientId");
|
|
335
|
+
$(this, "entries");
|
|
336
|
+
this.endpoint = e, this.events = i, this.store = t, this.container = d, this.clientId = _(), this.entries = [];
|
|
338
337
|
}
|
|
339
338
|
async fetchGuide(e) {
|
|
340
339
|
const i = {
|
|
@@ -360,7 +359,7 @@ class mt {
|
|
|
360
359
|
return (t.message === "Failed to fetch" || t.message === "NetworkError when attempting to fetch resource.") && (d = "Lost connection... Please try again."), this.events.dispatch("tracking:http-client-error", { message: d, error: t }), this.handleResponse({
|
|
361
360
|
entries: [
|
|
362
361
|
{
|
|
363
|
-
id:
|
|
362
|
+
id: _(),
|
|
364
363
|
type: "Error",
|
|
365
364
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
366
365
|
content: {
|
|
@@ -399,46 +398,21 @@ class mt {
|
|
|
399
398
|
});
|
|
400
399
|
}
|
|
401
400
|
}
|
|
402
|
-
const ft = "@telia-ace/conversational-hub-bot-provider",
|
|
403
|
-
".": {
|
|
404
|
-
import: "./index.mjs",
|
|
405
|
-
require: "./index.js"
|
|
406
|
-
}
|
|
407
|
-
}, vt = {
|
|
408
|
-
"@telia-ace/widget-conversation": "*",
|
|
409
|
-
"@webprovisions/platform": "^1.1.4",
|
|
410
|
-
"@telia-ace/knowledge-widget-core": "*",
|
|
411
|
-
"@telia-ace/widget-utilities": "*",
|
|
412
|
-
"@telia-ace/widget-services": "*",
|
|
413
|
-
"@telia-ace/widget-core": "*",
|
|
414
|
-
"@telia-ace/knowledge-data-client": "*",
|
|
415
|
-
"@telia-ace/knowledge-widget-adapters": "*",
|
|
416
|
-
"@telia-ace/knowledge-widget-ui": "*",
|
|
417
|
-
"@telia-ace/widget-forms": "*"
|
|
418
|
-
}, wt = {
|
|
419
|
-
"@emotion/react": "11.11.1",
|
|
420
|
-
"@emotion/styled": "11.11.0",
|
|
421
|
-
react: "18.2.0"
|
|
422
|
-
}, H = {
|
|
401
|
+
const ft = "@telia-ace/conversational-hub-bot-provider", ht = "0.0.16", H = {
|
|
423
402
|
name: ft,
|
|
424
|
-
version:
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}, kt = async (n) => {
|
|
431
|
-
var J, U, D, R, z;
|
|
432
|
-
const e = "chub-plugin", i = n.get("$widget"), t = (z = (R = (D = (U = (J = i == null ? void 0 : i.container) == null ? void 0 : J.get("$settings")) == null ? void 0 : U.components) == null ? void 0 : D.conversation) == null ? void 0 : R.properties) == null ? void 0 : z.conversationalHubPluginSettings;
|
|
433
|
-
let d, y, f, k = (t == null ? void 0 : t.connectionAttempts) ?? 5, P, a, l;
|
|
434
|
-
V.info((H == null ? void 0 : H.name) + " version: " + (H == null ? void 0 : H.version)), q(
|
|
403
|
+
version: ht
|
|
404
|
+
}, Ct = async (n) => {
|
|
405
|
+
var j, U, R, z, F;
|
|
406
|
+
const e = "chub-plugin", i = n.get("$widget"), t = (F = (z = (R = (U = (j = i == null ? void 0 : i.container) == null ? void 0 : j.get("$settings")) == null ? void 0 : U.components) == null ? void 0 : R.conversation) == null ? void 0 : z.properties) == null ? void 0 : F.conversationalHubPluginSettings;
|
|
407
|
+
let d, y, f, P = (t == null ? void 0 : t.connectionAttempts) ?? 5, O, a, l;
|
|
408
|
+
G.info((H == null ? void 0 : H.name) + " version: " + (H == null ? void 0 : H.version)), W(
|
|
435
409
|
n,
|
|
436
|
-
|
|
437
|
-
import("./contact-method-
|
|
438
|
-
),
|
|
410
|
+
k.ContactMethod,
|
|
411
|
+
import("./contact-method-ZLVXep1Y.mjs")
|
|
412
|
+
), W(
|
|
439
413
|
n,
|
|
440
|
-
|
|
441
|
-
import("./contact-method-list-
|
|
414
|
+
k.ContactList,
|
|
415
|
+
import("./contact-method-list-CbAeYLrS.mjs")
|
|
442
416
|
);
|
|
443
417
|
const u = await Q(
|
|
444
418
|
n,
|
|
@@ -472,30 +446,28 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
472
446
|
avatar: t == null ? void 0 : t.avatar
|
|
473
447
|
}), l = v(n, s);
|
|
474
448
|
const { events: o } = n.get("$widget"), c = new st(n);
|
|
475
|
-
a = new mt(l, o, c, n),
|
|
476
|
-
const [
|
|
477
|
-
|
|
449
|
+
a = new mt(l, o, c, n), M();
|
|
450
|
+
const [p] = n.get("widgetDOMElements");
|
|
451
|
+
p.querySelectorAll(".humany-bot-contact-method").forEach((w) => {
|
|
478
452
|
var b;
|
|
479
|
-
(b =
|
|
480
|
-
}),
|
|
453
|
+
(b = w.closest(".humany-conversation-entry")) == null || b.remove();
|
|
454
|
+
}), p.removeEventListener("click", m), p.addEventListener("click", m);
|
|
481
455
|
const C = () => y.providers.includes(e);
|
|
482
|
-
s.actions.create("submit", (
|
|
456
|
+
s.actions.create("submit", (w) => {
|
|
483
457
|
const { events: b } = n.get("$widget");
|
|
484
|
-
b.dispatch("conversational-hub-provider:form-submitted",
|
|
485
|
-
}), s.actions.create("evaluate", (
|
|
458
|
+
b.dispatch("conversational-hub-provider:form-submitted", w);
|
|
459
|
+
}), s.actions.create("evaluate", (w) => {
|
|
486
460
|
const { events: b } = n.get("$widget");
|
|
487
|
-
b.dispatch("conversational-hub-provider:evaluate",
|
|
488
|
-
}), s.actions.watch("conversation.action", (
|
|
489
|
-
if (!C())
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
S.text.replace(/</g, "<").replace(/>/g, ">")
|
|
461
|
+
b.dispatch("conversational-hub-provider:evaluate", w);
|
|
462
|
+
}), s.actions.watch("conversation.action", (w, b) => (C() && I(w), b(w))), s.actions.watch("conversation.user-submit", (w, b) => {
|
|
463
|
+
if (!C()) return b(w);
|
|
464
|
+
N(w.text), d.user.print(
|
|
465
|
+
w.text.replace(/</g, "<").replace(/>/g, ">")
|
|
493
466
|
);
|
|
494
467
|
}), i.events.subscribe(
|
|
495
468
|
"conversational-hub-provider:fetch-guide",
|
|
496
|
-
async (
|
|
497
|
-
if (!(b != null && b.guideId))
|
|
498
|
-
return;
|
|
469
|
+
async (w, b) => {
|
|
470
|
+
if (!(b != null && b.guideId)) return;
|
|
499
471
|
const B = await a.fetchGuide(parseInt(b.guideId));
|
|
500
472
|
B && g(B);
|
|
501
473
|
}
|
|
@@ -507,7 +479,7 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
507
479
|
s.writer = f.print(o);
|
|
508
480
|
});
|
|
509
481
|
}
|
|
510
|
-
const
|
|
482
|
+
const h = sessionStorage.getItem(
|
|
511
483
|
`humany_${x(
|
|
512
484
|
i.implementation.tenant + i.implementation.name + i.name
|
|
513
485
|
)}`
|
|
@@ -522,19 +494,19 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
522
494
|
}
|
|
523
495
|
return s.toString();
|
|
524
496
|
}
|
|
525
|
-
async function
|
|
526
|
-
const s = await
|
|
497
|
+
async function M(r = !0) {
|
|
498
|
+
const s = await q(
|
|
527
499
|
n,
|
|
528
500
|
"conversational-hub-session"
|
|
529
501
|
), o = n.get("dialogflowSettings");
|
|
530
502
|
if (o != null && o.silentStart)
|
|
531
503
|
delete o.silentStart, i.events.dispatch("conversational-hub-provider:started", {});
|
|
532
504
|
else if (s != null && s.sessionId && r)
|
|
533
|
-
|
|
505
|
+
O = s == null ? void 0 : s.sessionId;
|
|
534
506
|
else if (t != null && t.welcomeMessage) {
|
|
535
|
-
if (!(
|
|
536
|
-
const
|
|
537
|
-
f.print(
|
|
507
|
+
if (!(h != null && h.length ? JSON.parse(h) : {})["conversation-conversation"]) {
|
|
508
|
+
const p = t.welcomeMessage.replaceAll("$lt;", "<").replaceAll("$gt;", ">");
|
|
509
|
+
f.print(p);
|
|
538
510
|
}
|
|
539
511
|
} else {
|
|
540
512
|
const c = {
|
|
@@ -556,13 +528,13 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
556
528
|
}
|
|
557
529
|
async function I(r) {
|
|
558
530
|
await L(
|
|
559
|
-
`${t.baseUrl}/input/${
|
|
531
|
+
`${t.baseUrl}/input/${O}`,
|
|
560
532
|
`{"type":"button_click","language":"${t.language}","content":{"button_text":"${r.label}","value":"${r.actionKey}"}}`
|
|
561
533
|
);
|
|
562
534
|
}
|
|
563
535
|
async function N(r) {
|
|
564
536
|
const s = { text: r };
|
|
565
|
-
if (!
|
|
537
|
+
if (!O) {
|
|
566
538
|
const o = {
|
|
567
539
|
extension: t.extension
|
|
568
540
|
}, c = n.get("dialogflowSettings");
|
|
@@ -580,39 +552,39 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
580
552
|
);
|
|
581
553
|
}
|
|
582
554
|
await L(
|
|
583
|
-
`${t.baseUrl}/input/${
|
|
555
|
+
`${t.baseUrl}/input/${O}`,
|
|
584
556
|
`{"type":"text","language":"${t.language}","content":${JSON.stringify(s)}}`
|
|
585
557
|
);
|
|
586
558
|
}
|
|
587
559
|
async function L(r, s, o = !0) {
|
|
588
|
-
var
|
|
560
|
+
var w, b, B, D;
|
|
589
561
|
const c = d.loading();
|
|
590
|
-
let
|
|
562
|
+
let p, C;
|
|
591
563
|
try {
|
|
592
|
-
|
|
564
|
+
p = await fetch(r, {
|
|
593
565
|
method: "POST",
|
|
594
566
|
body: s
|
|
595
|
-
}), C = await (
|
|
596
|
-
} catch (
|
|
597
|
-
|
|
567
|
+
}), C = await (p == null ? void 0 : p.json());
|
|
568
|
+
} catch (V) {
|
|
569
|
+
V instanceof SyntaxError ? G.error("Incorrect JSON format.", V) : G.error("Network error: check connection or baseUrl.", V), c(), f.print(t.errorMessage || "An error occurred");
|
|
598
570
|
return;
|
|
599
571
|
}
|
|
600
|
-
if (!(
|
|
601
|
-
if (
|
|
572
|
+
if (!(p != null && p.ok)) {
|
|
573
|
+
if (G.error(`HTTP ${p == null ? void 0 : p.status}.`, JSON.stringify(C)), c(), !!((w = C == null ? void 0 : C.errors) != null && w.filter(
|
|
602
574
|
(E) => E.code === "1003"
|
|
603
|
-
).length) &&
|
|
604
|
-
|
|
575
|
+
).length) && P > 0) {
|
|
576
|
+
P--, await new Promise((Z) => setTimeout(Z, 500)), await M(!1);
|
|
605
577
|
const E = JSON.parse(s);
|
|
606
|
-
(b = E == null ? void 0 : E.content) != null && b.text ? await N(E.content.text) : (B = E == null ? void 0 : E.content) != null && B.action && await I((
|
|
578
|
+
(b = E == null ? void 0 : E.content) != null && b.text ? await N(E.content.text) : (B = E == null ? void 0 : E.content) != null && B.action && await I((D = E == null ? void 0 : E.content) == null ? void 0 : D.action);
|
|
607
579
|
} else
|
|
608
580
|
f.print(t.errorMessage || "An error occurred");
|
|
609
581
|
return;
|
|
610
582
|
}
|
|
611
|
-
c(),
|
|
583
|
+
c(), P = (t == null ? void 0 : t.connectionAttempts) ?? 5, C != null && C.action_payload && T(C.action_payload), O = C == null ? void 0 : C.session_id, u({ sessionId: O }), o && Y(C);
|
|
612
584
|
}
|
|
613
585
|
async function T(r) {
|
|
614
|
-
var
|
|
615
|
-
const s = (
|
|
586
|
+
var p;
|
|
587
|
+
const s = (p = r == null ? void 0 : r.transfer_parameters) == null ? void 0 : p.contactGuide, o = d.loading(), c = await a.fetchGuide(parseInt(s));
|
|
616
588
|
o(), c && g(c);
|
|
617
589
|
}
|
|
618
590
|
function Y(r) {
|
|
@@ -636,7 +608,7 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
636
608
|
}
|
|
637
609
|
]);
|
|
638
610
|
}
|
|
639
|
-
},
|
|
611
|
+
}, It = ot((n) => {
|
|
640
612
|
n.createCommand(
|
|
641
613
|
"dialogflow",
|
|
642
614
|
(e) => (i) => {
|
|
@@ -648,7 +620,7 @@ const ft = "@telia-ace/conversational-hub-bot-provider", pt = "0.0.16", ht = "./
|
|
|
648
620
|
);
|
|
649
621
|
});
|
|
650
622
|
export {
|
|
651
|
-
|
|
652
|
-
|
|
623
|
+
Ct as C,
|
|
624
|
+
It as d,
|
|
653
625
|
dt as u
|
|
654
626
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var X=Object.defineProperty;var Y=(n,e,i)=>e in n?X(n,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):n[e]=i;var $=(n,e,i)=>Y(n,typeof e!="symbol"?e+"":e,i);const N=require("@telia-ace/widget-conversation"),_=require("@telia-ace/widget-services"),K=require("@telia-ace/widget-utilities"),q=require("@telia-ace/widget-forms"),Z=require("@webprovisions/platform");class tt{constructor(e){$(this,"enabled",!0);$(this,"botProviderGlobalStateKey","bot-provider-global-state");$(this,"botProviderLocalStateKey","bot-provider-local-state");$(this,"botProviderEntriesKey","bot-provider-entries");$(this,"botProviderMetaStateKey","bot-provider-conversation-meta");this.container=e}getKey(e){let i;switch(e){case"localState":i=this.botProviderLocalStateKey;break;case"globalState":i=this.botProviderGlobalStateKey;break;case"entries":i=this.botProviderEntriesKey;break;case"meta":i=this.botProviderMetaStateKey;break}return i}async read(e){const i=this.getKey(e);if(!(!this.enabled||!i))return _.readStorage(this.container,i)}async write(e,i){const t=this.getKey(i);if(!this.enabled||!t)return;(await _.createStorageWriter(this.container,t,_.StorageCategory.Necessary))(e)}}var k=(n=>(n.ContactMethod="ace-conversational-hub-contact-method",n.ContactList="ace-conversational-hub-contact-list",n))(k||{});const et=n=>{if(n){const{type:e,content:i}=n;if(e&&i)return{type:e,content:i}}},nt=({isUser:n,items:e=[],meta:i={}})=>{const t=K.uuid();return{id:t,isUser:n,items:e.map(b=>({id:b.id||K.uuid(),isUser:n,groupId:t,message:b.message||[]})),meta:i}},it=({id:n,title:e,defaultIcon:i,exits:[t],exitType:d,confirmationText:b,expandFormAutomatically:f,form:M,description:P},a={})=>{const{adapter:l}=t||{},{clientName:u="",settings:y={},customClientName:m=""}=l,{validation:w}=a,g={id:n.toString(),title:e,description:P,symbol:et(i),clientName:u==="custom.adapter"?m:u,expanded:!0,inline:!0,body:{}};if(u.indexOf("phone")>-1||u.indexOf("freetext")>-1){const{displayTextBeforeClick:h,textBeforeClick:L}=y;h==="true"&&(g.expanded=!1,g.title=L),u.indexOf("phone.text")>-1?g.body.phoneNumber=y.phoneNumber:g.body.freetext=y.freetext}return(u.indexOf("chat.popup")>-1||u.indexOf("link")>-1||u==="custom.adapter"&&d==="custom")&&(g.body=y,g.body.confirmationFallback=b),u.indexOf("ace")>-1&&(g.body=y),M&&M.hasValueComponents&&(w?g.body.form=q.FormBuilder.fromLegacyForm(n.toString(),M,w).get():g.body.form=q.FormBuilder.fromLegacyForm(n.toString(),M).get(),f||(g.expanded=g.inline=!1),g.body=D(g,{submit:"Submit"})),a.guideId&&(g.body.guideId=a.guideId),g},ot=n=>{const{localState:e}=n;return n.tags.includes("category")&&n.tags.includes("contact")?N.ConversationMessageListItemType.ItemList:n.tags.includes("suggestion")?N.ConversationMessageListItemType.LinkList:(e==null?void 0:e.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"?k.ContactList:N.ConversationMessageListItemType.ButtonList},D=(n,{submit:e,errors:i,meta:t})=>{var d;if((d=n==null?void 0:n.body)!=null&&d.form){const{body:b}=n,f=new q.FormBuilder(b.form);return b.form.layout.submit||f.createComponent(q.submitButton(e,"submit")),i&&f.setValidationErrors(i),t&&f.setMeta(t),{...b,form:f.get()}}return(n==null?void 0:n.body)||{}},st=async(n,e,i)=>{(await(await n.getAsync("dataClient")).getClient()).parameters.set(e,i)},A=({messageId:n,message:e,group:i})=>({id:n,message:e,groupId:i.id,isUser:i.isUser}),at=async(n,e,i)=>{const t=(a,l,u,y={actions:[],entryId:l.id,groupId:u})=>{const m=[];return y.actions=l.content.items.map(w=>{var h;const g={label:w.title,actionKey:w.actionKey,symbol:w.symbol?w.symbol:void 0,description:w.description||void 0};if(w.data){const L=l.actions[w.actionKey];a===k.ContactList?(m.push(w.data.id),g.data=it(w.data,{guideId:(h=L==null?void 0:L.guideId)==null?void 0:h.toString()})):g.data=w.data}return g}),a===k.ContactList&&(y.contactMethodIds=m),y},d=async(a,l,u=[],y)=>{var w,g;const m=K.uuid();switch(a.type!=="List"&&a.tags.includes("guide")&&((g=(w=a.content.hints)==null?void 0:w[0])!=null&&g.id)&&await st(n,"LastGuideId",a.content.hints[0].id),a.type){case"List":{if(!a.content)return[];const{items:h,html:L}=a.content,O=[];let I={actions:[],entryId:a.id,groupId:l.id};if((h==null?void 0:h.length)>0){const T=ot(a);if(I=t(T,a,l.id,I),u.length){const x=u.find(H=>H.tags.includes("paging"));x!=null&&x.content&&(l.meta.paging={actions:x.actions,items:x.content.items,localState:x.localState},x.content.items.forEach(H=>{I.actions.push({label:H.title,actionKey:H.actionKey,data:{groupId:y?y.id:l.id}})}))}O.unshift(A({messageId:m,message:[T,I],group:l}))}return L&&O.unshift(A({messageId:m,message:[N.ConversationMessageListItemType.HTML,{body:L}],group:l})),O}case"Text":{const h=[];if(h.push(A({messageId:m,message:[N.ConversationMessageListItemType.HTML,{body:a.content.html}],group:l})),u.length){const L=u.find(I=>{var T;return I.type==="List"&&((T=I.localState)==null?void 0:T.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"}),O=u.find(I=>I.tags.includes("contact")&&I.type==="Contact");if(O&&h.push(A({messageId:m,message:[k.ContactMethod,{contactMethodId:O.content.id,groupId:l.id,guideId:O.content.guideId}],group:l})),L){const I=t(k.ContactList,L,l.id);h.push(A({messageId:m,message:[N.ConversationMessageListItemType.Separator,void 0],group:l})),h.push(A({messageId:m,message:[k.ContactList,I],group:l}))}}return h}case"Contact":return[A({messageId:m,message:[k.ContactMethod,{contactMethodId:a.content.id,groupId:l.id,guideId:a.content.guideId}],group:l})];case"Error":return[A({messageId:m,message:[N.ConversationMessageListItemType.HTML,{body:a.content.message||"Something went wrong."}],group:l})];default:return[]}},b=new Map([["Text",1],["List",2],["Contact",3]]),f=[],M=e.sort((a,l)=>{const y=b.get(a.type)||20,m=b.get(l.type)||20;return y-m}).filter(a=>!a.relation).reduce((a,l)=>a.concat(l),[]),P=a=>typeof a.actions.selector<"u";for(const a of M){const l=e.filter(m=>m.relation===a.id&&!P(m)),u=nt({isUser:!1});(await d(a,u,l,i)).forEach(m=>{u.items.push(m)}),u.items.length&&f.push(u)}return f};class rt{constructor(e,i,t,d){$(this,"globalState");$(this,"localState");$(this,"clientId");$(this,"entries");this.endpoint=e,this.events=i,this.store=t,this.container=d,this.clientId=K.uuid(),this.entries=[]}async fetchGuide(e){const i={command:{guide:{id:e}},globalState:this.globalState,clientId:this.clientId};return await this.postEnvelope(i)}async postEnvelope(e,i){try{const t=await fetch(this.endpoint,this.getHttpOptions(e));if(!t.ok)throw t;const d=await t.json();return this.handleResponse(d,i)}catch(t){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let d="Something went wrong";return(t.message==="Failed to fetch"||t.message==="NetworkError when attempting to fetch resource.")&&(d="Lost connection... Please try again."),this.events.dispatch("tracking:http-client-error",{message:d,error:t}),this.handleResponse({entries:[{id:K.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:d},actions:{},tags:[]}]})}}async handleResponse(e,i){this.entries=this.entries.concat(e.entries),this.store.write(this.entries,"entries");const t=e.entries.find(b=>b.type==="Widget");return t&&this.events.dispatch("provider:widget-entry",t.content),e.globalState&&(this.globalState=e.globalState,this.store.write(e.globalState,"globalState")),this.localState=e.entries.reduce((b,f)=>f.localState?f.localState:b,void 0),this.store.write(this.localState,"localState"),await at(this.container,e.entries,i)}getHttpOptions(e){const i={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"}};return e.funnel=this.container.get("$widget").name,e.localState=e.localState||this.localState,Object.assign({},i,{body:JSON.stringify(e),credentials:"same-origin"})}}const ct="@telia-ace/conversational-hub-bot-provider",lt="0.0.16",B={name:ct,version:lt},dt=async n=>{var G,J,U,j,R;const e="chub-plugin",i=n.get("$widget"),t=(R=(j=(U=(J=(G=i==null?void 0:i.container)==null?void 0:G.get("$settings"))==null?void 0:J.components)==null?void 0:U.conversation)==null?void 0:j.properties)==null?void 0:R.conversationalHubPluginSettings;let d,b,f,M=(t==null?void 0:t.connectionAttempts)??5,P,a,l;K.Logger.info((B==null?void 0:B.name)+" version: "+(B==null?void 0:B.version)),N.registerCustomMessageComponent(n,k.ContactMethod,Promise.resolve().then(()=>require("./contact-method-D9OmD693.js"))),N.registerCustomMessageComponent(n,k.ContactList,Promise.resolve().then(()=>require("./contact-method-list-BzAGHFFX.js")));const u=await _.createStorageWriter(n,"conversational-hub-session",_.StorageCategory.Necessary),y=(r,s)=>{const{knowledgeBotEndpoint:o}=s.properties();if(o)return`${o}/conversations`;const{data:c}=r.get("$settings");if(!c||!c.projection)throw new Error("Missing Knowledge Bot endpoint");return`${c.projection}/conversations`},m=r=>{var s;if(r.target instanceof HTMLButtonElement){const o=r.target;if((s=o.getAttribute("class"))!=null&&s.includes("dialog-option-cx")){const c=o.getAttribute("value");T(c),d.user.print(c.replace(/</g,"<").replace(/>/g,">"))}}};(await N.ConversationPlatform.getInstance(n)).registerProvider(e,(r,s)=>{d=r,b=d.controller,f=d.createAgent({name:t==null?void 0:t.botName,avatar:t==null?void 0:t.avatar}),l=y(n,s);const{events:o}=n.get("$widget"),c=new tt(n);a=new rt(l,o,c,n),O();const[p]=n.get("widgetDOMElements");p.querySelectorAll(".humany-bot-contact-method").forEach(S=>{var v;(v=S.closest(".humany-conversation-entry"))==null||v.remove()}),p.removeEventListener("click",m),p.addEventListener("click",m);const C=()=>b.providers.includes(e);s.actions.create("submit",S=>{const{events:v}=n.get("$widget");v.dispatch("conversational-hub-provider:form-submitted",S)}),s.actions.create("evaluate",S=>{const{events:v}=n.get("$widget");v.dispatch("conversational-hub-provider:evaluate",S)}),s.actions.watch("conversation.action",(S,v)=>(C()&&I(S),v(S))),s.actions.watch("conversation.user-submit",(S,v)=>{if(!C())return v(S);T(S.text),d.user.print(S.text.replace(/</g,"<").replace(/>/g,">"))}),i.events.subscribe("conversational-hub-provider:fetch-guide",async(S,v)=>{if(!(v!=null&&v.guideId))return;const F=await a.fetchGuide(parseInt(v.guideId));F&&g(F)})});async function g(r){r.forEach(s=>{const o=s.items.map(c=>c.message);s.writer=f.print(o)})}const h=sessionStorage.getItem(`humany_${L(i.implementation.tenant+i.implementation.name+i.name)}`);function L(r){let s=0;if(r.length===0)return s.toString();for(let o=0;o<r.length;o++){const c=r.charCodeAt(o);s=(s<<5)-s+c,s=s&s}return s.toString()}async function O(r=!0){const s=await _.readStorage(n,"conversational-hub-session"),o=n.get("dialogflowSettings");if(o!=null&&o.silentStart)delete o.silentStart,i.events.dispatch("conversational-hub-provider:started",{});else if(s!=null&&s.sessionId&&r)P=s==null?void 0:s.sessionId;else if(t!=null&&t.welcomeMessage){if(!(h!=null&&h.length?JSON.parse(h):{})["conversation-conversation"]){const p=t.welcomeMessage.replaceAll("$lt;","<").replaceAll("$gt;",">");f.print(p)}}else{const c={extension:t.extension};o!=null&&o.initCommand&&(c.input={type:"event",language:t.language,content:{name:o.initCommand,parameters:o.initParameters||{}}}),await x(t.baseUrl+"/initialize",JSON.stringify(c),r)}}async function I(r){await x(`${t.baseUrl}/input/${P}`,`{"type":"button_click","language":"${t.language}","content":{"button_text":"${r.label}","value":"${r.actionKey}"}}`)}async function T(r){const s={text:r};if(!P){const o={extension:t.extension},c=n.get("dialogflowSettings");c!=null&&c.initCommand&&(o.input={type:"event",language:t.language,content:{name:c.initCommand,parameters:c.initParameters||{}}}),await x(t.baseUrl+"/initialize",JSON.stringify(o),!1)}await x(`${t.baseUrl}/input/${P}`,`{"type":"text","language":"${t.language}","content":${JSON.stringify(s)}}`)}async function x(r,s,o=!0){var S,v,F,z;const c=d.loading();let p,C;try{p=await fetch(r,{method:"POST",body:s}),C=await(p==null?void 0:p.json())}catch(V){V instanceof SyntaxError?K.Logger.error("Incorrect JSON format.",V):K.Logger.error("Network error: check connection or baseUrl.",V),c(),f.print(t.errorMessage||"An error occurred");return}if(!(p!=null&&p.ok)){if(K.Logger.error(`HTTP ${p==null?void 0:p.status}.`,JSON.stringify(C)),c(),!!((S=C==null?void 0:C.errors)!=null&&S.filter(E=>E.code==="1003").length)&&M>0){M--,await new Promise(Q=>setTimeout(Q,500)),await O(!1);const E=JSON.parse(s);(v=E==null?void 0:E.content)!=null&&v.text?await T(E.content.text):(F=E==null?void 0:E.content)!=null&&F.action&&await I((z=E==null?void 0:E.content)==null?void 0:z.action)}else f.print(t.errorMessage||"An error occurred");return}c(),M=(t==null?void 0:t.connectionAttempts)??5,C!=null&&C.action_payload&&H(C.action_payload),P=C==null?void 0:C.session_id,u({sessionId:P}),o&&W(C)}async function H(r){var p;const s=(p=r==null?void 0:r.transfer_parameters)==null?void 0:p.contactGuide,o=d.loading(),c=await a.fetchGuide(parseInt(s));o(),c&&g(c)}function W(r){var s;r==null||r.agent_response.forEach(o=>{f.print(o.payload.text)}),(s=r==null?void 0:r.prompt)!=null&&s.items&&f.print(["button-list",{actions:r.prompt.items.map(o=>{let c;return o.type==="button"&&(c={actionKey:o.value,label:o.text}),o.type==="link"&&(c={actionKey:o.value,label:o.text,data:{href:o.url,target:(t==null?void 0:t.linkTarget)??"_blank"}}),c})}])}},ut=Z.createConfigurationApi(n=>{n.createCommand("dialogflow",e=>i=>{const t={initCommand:i.initCommand};i.initParameters&&(t.initParameters=i.initParameters),i.silentStart&&(t.silentStart=i.silentStart),e.container.register("dialogflowSettings",t)})});exports.ConversationalHubPlugin=dt;exports.dialogflowConfigurationApi=ut;exports.updateForm=D;
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index-DnKKEE-w.js");exports.ConversationalHubPlugin=i.ConversationalHubPlugin;exports.dialogflowConfigurationApi=i.dialogflowConfigurationApi;
|
package/index.mjs
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import "@telia-ace/widget-conversation";
|
|
3
|
-
import "@telia-ace/widget-services";
|
|
4
|
-
import "@telia-ace/widget-utilities";
|
|
5
|
-
import "@telia-ace/widget-forms";
|
|
6
|
-
import "@webprovisions/platform";
|
|
1
|
+
import { C as i, d as n } from "./index-CGyJXK5J.mjs";
|
|
7
2
|
export {
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
i as ConversationalHubPlugin,
|
|
4
|
+
n as dialogflowConfigurationApi
|
|
10
5
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/conversational-hub-bot-provider",
|
|
3
|
-
"version": "1.3.41
|
|
3
|
+
"version": "1.3.41",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@telia-ace/widget-conversation": "^1.3.41
|
|
13
|
+
"@telia-ace/widget-conversation": "^1.3.41",
|
|
14
14
|
"@webprovisions/platform": "^1.1.4",
|
|
15
|
-
"@telia-ace/knowledge-widget-core": "^1.3.41
|
|
16
|
-
"@telia-ace/widget-utilities": "^1.3.41
|
|
17
|
-
"@telia-ace/widget-services": "^1.3.41
|
|
18
|
-
"@telia-ace/widget-core": "^1.3.41
|
|
19
|
-
"@telia-ace/knowledge-data-client": "^1.3.41
|
|
20
|
-
"@telia-ace/knowledge-widget-adapters": "^1.3.41
|
|
21
|
-
"@telia-ace/knowledge-widget-ui": "^1.3.41
|
|
22
|
-
"@telia-ace/widget-forms": "^1.3.41
|
|
15
|
+
"@telia-ace/knowledge-widget-core": "^1.3.41",
|
|
16
|
+
"@telia-ace/widget-utilities": "^1.3.41",
|
|
17
|
+
"@telia-ace/widget-services": "^1.3.41",
|
|
18
|
+
"@telia-ace/widget-core": "^1.3.41",
|
|
19
|
+
"@telia-ace/knowledge-data-client": "^1.3.41",
|
|
20
|
+
"@telia-ace/knowledge-widget-adapters": "^1.3.41",
|
|
21
|
+
"@telia-ace/knowledge-widget-ui": "^1.3.41",
|
|
22
|
+
"@telia-ace/widget-forms": "^1.3.41"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@emotion/react": "11.11.1",
|
package/utils.d.ts
CHANGED
|
@@ -6,10 +6,8 @@ import { CustomMessageTypes, MessageGroup, MessageGroupItem, ServerEntry } from
|
|
|
6
6
|
|
|
7
7
|
export declare const createGroup: ({ isUser, items, meta, }: {
|
|
8
8
|
isUser: boolean;
|
|
9
|
-
items?: Partial<MessageGroupItem>[]
|
|
10
|
-
meta?:
|
|
11
|
-
[key: string]: any;
|
|
12
|
-
} | undefined;
|
|
9
|
+
items?: Partial<MessageGroupItem>[];
|
|
10
|
+
meta?: MessageGroup["meta"];
|
|
13
11
|
}) => MessageGroup;
|
|
14
12
|
export declare const contactMethodFromLegacy: ({ id, title, defaultIcon, exits: [exit], exitType, confirmationText, expandFormAutomatically, form, description, }: any, options?: {
|
|
15
13
|
validation?: any;
|
|
@@ -21,9 +19,9 @@ export declare const updateForm: (contactMethod: ContactMethodType, { submit, er
|
|
|
21
19
|
submit: string;
|
|
22
20
|
errors?: {
|
|
23
21
|
[key: string]: string;
|
|
24
|
-
}
|
|
22
|
+
};
|
|
25
23
|
meta?: {
|
|
26
24
|
[key: string]: string;
|
|
27
|
-
}
|
|
25
|
+
};
|
|
28
26
|
}) => any;
|
|
29
27
|
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 N=require("react/jsx-runtime"),R=require("@emotion/styled"),F=require("@telia-ace/knowledge-data-client"),$=require("@telia-ace/knowledge-widget-adapters"),v=require("@telia-ace/knowledge-widget-ui"),z=require("@telia-ace/widget-forms"),O=require("@telia-ace/widget-utilities"),l=require("react"),x=require("./index-059f1922.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");require("@webprovisions/platform");const U=({contactMethodId:i,guideId:n,groupId:b,className:T})=>{var h,q,k,S,j;const[e,u]=l.useState(),c=v.useContainer(),A=v.useDispatch(),f=l.useRef(!0),y=v.useConversation();l.useEffect(()=>{const{events:t}=c.get("$widget"),m=t.subscribe("conversational-hub-provider:form-submitted",async(a,r)=>{var D;if(((D=r.form.meta)==null?void 0:D.groupId)!==b||r.id!==(e==null?void 0:e.id))return;y&&(r.form.meta||(r.form.meta={}),r.form.meta.conversation=y);const p=await c.getAsync("contactMethods"),o={...e,body:{...e.body,form:r.form}},{errors:d,valid:g,errorTypes:_}=await p.validate(o);if(!g){const E=new z.FormBuilder(e.body.form);u(void 0),E.setValidationErrors(d),o.body={...o.body,form:E.get()},u({...o});return}const B=await p.submit(o);o.confirmation=B,u(o)}),s=t.subscribe("conversational-hub-provider:evaluate",async(a,r)=>{if(String(r.id)!==String(i))return;const o=await(await c.getAsync("contactMethods")).evaluate(e);let d={...e,body:{...e.body,form:o}};const g=x.updateForm(d,{submit:"Submit",errors:{},meta:{groupId:b}});d={...d,body:g},u(d)});return()=>{m(),s()}},[c,e,u,y]);const C=(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 a in t)if(typeof t[a]=="object"&&t[a]!==null){const r=C(t[a],m,t);if(r!==void 0)return r}},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}),a=x.updateForm(s,{submit:"Submit",errors:{},meta:{groupId:b}});if(s.body=a,s.body.guideId=n,!f.current)return null;u(s)},[f]);return l.useEffect(()=>(w(i),()=>{f.current=!1}),[i,w]),e?(e.clientName==="ace.callback"&&((h=e.body)!=null&&h.entrance)&&C(e,(q=e.body)==null?void 0:q.entrance),N.jsx(W,{...e,body:{...e.body,form:e.body.form?{...e.body.form,data:(k=e.body.form)==null?void 0:k.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:O.appendClassNames("humany-bot-contact-method",T)})):null},W=R($.ContactMethod)`
|
|
2
|
-
padding: ${i=>{var n;return(n=i.theme.sizes)==null?void 0:n.normal}} ${i=>{var n;return(n=i.theme.sizes)==null?void 0:n.medium}};
|
|
3
|
-
`;exports.default=U;
|
|
@@ -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-bd8934cb.js");require("@telia-ace/knowledge-data-client");require("@telia-ace/widget-forms");require("@telia-ace/widget-utilities");require("./index-059f1922.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");require("@webprovisions/platform");const k=({actions:e,entryId:t,groupId:x})=>{const q=g.useDispatch(),o=g.useContainer(),[h,C]=l.useState([]),[d,M]=l.useState([]);return l.useEffect(()=>{o.getAsync("contactMethods").then(n=>{if(!n)return;const c=e.map(async i=>{var m;if(!((m=i.data)!=null&&m.clientName))return null;const s=await n.handleAdapters(i.data);return{...s,...i.data,description:i.data.description?i.data.description:s.description,onClick:(p,r)=>{if(typeof s.onClick=="function"&&s.onClick(p,r),!p.defaultPrevented)if(r.inline&&!r.expanded)M([...d,r.id]);else{const{events:f}=o.get("$widget");f.dispatch("conversational-hub-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,o,t,d]),h.length?a.jsx(j,{className:"humany-bot-contact-list",contactMethods:h,dispatch:q,itemRenderer:(n,c)=>(d.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;
|
package/index-059f1922.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var X=Object.defineProperty;var Y=(n,e,i)=>e in n?X(n,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):n[e]=i;var O=(n,e,i)=>(Y(n,typeof e!="symbol"?e+"":e,i),i);const N=require("@telia-ace/widget-conversation"),j=require("@telia-ace/widget-services"),K=require("@telia-ace/widget-utilities"),F=require("@telia-ace/widget-forms"),Z=require("@webprovisions/platform");class tt{constructor(e){O(this,"enabled",!0);O(this,"botProviderGlobalStateKey","bot-provider-global-state");O(this,"botProviderLocalStateKey","bot-provider-local-state");O(this,"botProviderEntriesKey","bot-provider-entries");O(this,"botProviderMetaStateKey","bot-provider-conversation-meta");this.container=e}getKey(e){let i;switch(e){case"localState":i=this.botProviderLocalStateKey;break;case"globalState":i=this.botProviderGlobalStateKey;break;case"entries":i=this.botProviderEntriesKey;break;case"meta":i=this.botProviderMetaStateKey;break}return i}async read(e){const i=this.getKey(e);if(!(!this.enabled||!i))return j.readStorage(this.container,i)}async write(e,i){const t=this.getKey(i);if(!this.enabled||!t)return;(await j.createStorageWriter(this.container,t,j.StorageCategory.Necessary))(e)}}var $=(n=>(n.ContactMethod="ace-conversational-hub-contact-method",n.ContactList="ace-conversational-hub-contact-list",n))($||{});const et=n=>{if(n){const{type:e,content:i}=n;if(e&&i)return{type:e,content:i}}},nt=({isUser:n,items:e=[],meta:i={}})=>{const t=K.uuid();return{id:t,isUser:n,items:e.map(b=>({id:b.id||K.uuid(),isUser:n,groupId:t,message:b.message||[]})),meta:i}},it=({id:n,title:e,defaultIcon:i,exits:[t],exitType:d,confirmationText:b,expandFormAutomatically:p,form:M,description:P},a={})=>{const{adapter:l}=t||{Adapter:{}},{clientName:u="",settings:y={},customClientName:m=""}=l,{validation:w}=a,g={id:n.toString(),title:e,description:P,symbol:et(i),clientName:u==="custom.adapter"?m:u,expanded:!0,inline:!0,body:{}};if(u.indexOf("phone")>-1||u.indexOf("freetext")>-1){const{displayTextBeforeClick:f,textBeforeClick:L}=y;f==="true"&&(g.expanded=!1,g.title=L),u.indexOf("phone.text")>-1?g.body.phoneNumber=y.phoneNumber:g.body.freetext=y.freetext}return(u.indexOf("chat.popup")>-1||u.indexOf("link")>-1||u==="custom.adapter"&&d==="custom")&&(g.body=y,g.body.confirmationFallback=b),u.indexOf("ace")>-1&&(g.body=y),M&&M.hasValueComponents&&(w?g.body.form=F.FormBuilder.fromLegacyForm(n.toString(),M,w).get():g.body.form=F.FormBuilder.fromLegacyForm(n.toString(),M).get(),p||(g.expanded=g.inline=!1),g.body=z(g,{submit:"Submit"})),a.guideId&&(g.body.guideId=a.guideId),g},ot=n=>{const{localState:e}=n;return n.tags.includes("category")&&n.tags.includes("contact")?N.ConversationMessageListItemType.ItemList:n.tags.includes("suggestion")?N.ConversationMessageListItemType.LinkList:(e==null?void 0:e.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"?$.ContactList:N.ConversationMessageListItemType.ButtonList},z=(n,{submit:e,errors:i,meta:t})=>{var d;if((d=n==null?void 0:n.body)!=null&&d.form){const{body:b}=n,p=new F.FormBuilder(b.form);return b.form.layout.submit||p.createComponent(F.submitButton(e,"submit")),i&&p.setValidationErrors(i),t&&p.setMeta(t),{...b,form:p.get()}}return(n==null?void 0:n.body)||{}},st=async(n,e,i)=>{(await(await n.getAsync("dataClient")).getClient()).parameters.set(e,i)},A=({messageId:n,message:e,group:i})=>({id:n,message:e,groupId:i.id,isUser:i.isUser}),at=async(n,e,i)=>{const t=(a,l,u,y={actions:[],entryId:l.id,groupId:u})=>{const m=[];return y.actions=l.content.items.map(w=>{var f;const g={label:w.title,actionKey:w.actionKey,symbol:w.symbol?w.symbol:void 0,description:w.description||void 0};if(w.data){const L=l.actions[w.actionKey];a===$.ContactList?(m.push(w.data.id),g.data=it(w.data,{guideId:(f=L==null?void 0:L.guideId)==null?void 0:f.toString()})):g.data=w.data}return g}),a===$.ContactList&&(y.contactMethodIds=m),y},d=async(a,l,u=[],y)=>{var w,g;const m=K.uuid();switch(a.type!=="List"&&a.tags.includes("guide")&&((g=(w=a.content.hints)==null?void 0:w[0])!=null&&g.id)&&await st(n,"LastGuideId",a.content.hints[0].id),a.type){case"List":{if(!a.content)return[];const{items:f,html:L}=a.content,k=[];let I={actions:[],entryId:a.id,groupId:l.id};if((f==null?void 0:f.length)>0){const T=ot(a);if(I=t(T,a,l.id,I),u.length){const x=u.find(H=>H.tags.includes("paging"));x!=null&&x.content&&(l.meta.paging={actions:x.actions,items:x.content.items,localState:x.localState},x.content.items.forEach(H=>{I.actions.push({label:H.title,actionKey:H.actionKey,data:{groupId:y?y.id:l.id}})}))}k.unshift(A({messageId:m,message:[T,I],group:l}))}return L&&k.unshift(A({messageId:m,message:[N.ConversationMessageListItemType.HTML,{body:L}],group:l})),k}case"Text":{const f=[];if(f.push(A({messageId:m,message:[N.ConversationMessageListItemType.HTML,{body:a.content.html}],group:l})),u.length){const L=u.find(I=>{var T;return I.type==="List"&&((T=I.localState)==null?void 0:T.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"}),k=u.find(I=>I.tags.includes("contact")&&I.type==="Contact");if(k&&f.push(A({messageId:m,message:[$.ContactMethod,{contactMethodId:k.content.id,groupId:l.id,guideId:k.content.guideId}],group:l})),L){const I=t($.ContactList,L,l.id);f.push(A({messageId:m,message:[N.ConversationMessageListItemType.Separator,void 0],group:l})),f.push(A({messageId:m,message:[$.ContactList,I],group:l}))}}return f}case"Contact":return[A({messageId:m,message:[$.ContactMethod,{contactMethodId:a.content.id,groupId:l.id,guideId:a.content.guideId}],group:l})];case"Error":return[A({messageId:m,message:[N.ConversationMessageListItemType.HTML,{body:a.content.message||"Something went wrong."}],group:l})];default:return[]}},b=new Map([["Text",1],["List",2],["Contact",3]]),p=[],M=e.sort((a,l)=>{const y=b.get(a.type)||20,m=b.get(l.type)||20;return y-m}).filter(a=>!a.relation).reduce((a,l)=>a.concat(l),[]),P=a=>typeof a.actions.selector<"u";for(const a of M){const l=e.filter(m=>m.relation===a.id&&!P(m)),u=nt({isUser:!1});(await d(a,u,l,i)).forEach(m=>{u.items.push(m)}),u.items.length&&p.push(u)}return p};class rt{constructor(e,i,t,d){O(this,"globalState");O(this,"localState");O(this,"clientId");O(this,"entries");this.endpoint=e,this.events=i,this.store=t,this.container=d,this.clientId=K.uuid(),this.entries=[]}async fetchGuide(e){const i={command:{guide:{id:e}},globalState:this.globalState,clientId:this.clientId};return await this.postEnvelope(i)}async postEnvelope(e,i){try{const t=await fetch(this.endpoint,this.getHttpOptions(e));if(!t.ok)throw t;const d=await t.json();return this.handleResponse(d,i)}catch(t){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let d="Something went wrong";return(t.message==="Failed to fetch"||t.message==="NetworkError when attempting to fetch resource.")&&(d="Lost connection... Please try again."),this.events.dispatch("tracking:http-client-error",{message:d,error:t}),this.handleResponse({entries:[{id:K.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:d},actions:{},tags:[]}]})}}async handleResponse(e,i){this.entries=this.entries.concat(e.entries),this.store.write(this.entries,"entries");const t=e.entries.find(b=>b.type==="Widget");return t&&this.events.dispatch("provider:widget-entry",t.content),e.globalState&&(this.globalState=e.globalState,this.store.write(e.globalState,"globalState")),this.localState=e.entries.reduce((b,p)=>p.localState?p.localState:b,void 0),this.store.write(this.localState,"localState"),await at(this.container,e.entries,i)}getHttpOptions(e){const i={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"}};return e.funnel=this.container.get("$widget").name,e.localState=e.localState||this.localState,Object.assign({},i,{body:JSON.stringify(e),credentials:"same-origin"})}}const ct="@telia-ace/conversational-hub-bot-provider",lt="0.0.16",dt="./index.js",ut="./index.d.ts",gt={".":{import:"./index.mjs",require:"./index.js"}},mt={"@telia-ace/widget-conversation":"*","@webprovisions/platform":"^1.1.4","@telia-ace/knowledge-widget-core":"*","@telia-ace/widget-utilities":"*","@telia-ace/widget-services":"*","@telia-ace/widget-core":"*","@telia-ace/knowledge-data-client":"*","@telia-ace/knowledge-widget-adapters":"*","@telia-ace/knowledge-widget-ui":"*","@telia-ace/widget-forms":"*"},pt={"@emotion/react":"11.11.1","@emotion/styled":"11.11.0",react:"18.2.0"},B={name:ct,version:lt,main:dt,types:ut,exports:gt,dependencies:mt,peerDependencies:pt},ft=async n=>{var V,G,J,U,D;const e="chub-plugin",i=n.get("$widget"),t=(D=(U=(J=(G=(V=i==null?void 0:i.container)==null?void 0:V.get("$settings"))==null?void 0:G.components)==null?void 0:J.conversation)==null?void 0:U.properties)==null?void 0:D.conversationalHubPluginSettings;let d,b,p,M=(t==null?void 0:t.connectionAttempts)??5,P,a,l;K.Logger.info((B==null?void 0:B.name)+" version: "+(B==null?void 0:B.version)),N.registerCustomMessageComponent(n,$.ContactMethod,Promise.resolve().then(()=>require("./contact-method-bd8934cb.js"))),N.registerCustomMessageComponent(n,$.ContactList,Promise.resolve().then(()=>require("./contact-method-list-bf5e35d0.js")));const u=await j.createStorageWriter(n,"conversational-hub-session",j.StorageCategory.Necessary),y=(r,s)=>{const{knowledgeBotEndpoint:o}=s.properties();if(o)return`${o}/conversations`;const{data:c}=r.get("$settings");if(!c||!c.projection)throw new Error("Missing Knowledge Bot endpoint");return`${c.projection}/conversations`},m=r=>{var s;if(r.target instanceof HTMLButtonElement){const o=r.target;if((s=o.getAttribute("class"))!=null&&s.includes("dialog-option-cx")){const c=o.getAttribute("value");T(c),d.user.print(c.replace(/</g,"<").replace(/>/g,">"))}}};(await N.ConversationPlatform.getInstance(n)).registerProvider(e,(r,s)=>{d=r,b=d.controller,p=d.createAgent({name:t==null?void 0:t.botName,avatar:t==null?void 0:t.avatar}),l=y(n,s);const{events:o}=n.get("$widget"),c=new tt(n);a=new rt(l,o,c,n),k();const[h]=n.get("widgetDOMElements");h.querySelectorAll(".humany-bot-contact-method").forEach(S=>{var v;(v=S.closest(".humany-conversation-entry"))==null||v.remove()}),h.removeEventListener("click",m),h.addEventListener("click",m);const C=()=>b.providers.includes(e);s.actions.create("submit",S=>{const{events:v}=n.get("$widget");v.dispatch("conversational-hub-provider:form-submitted",S)}),s.actions.create("evaluate",S=>{const{events:v}=n.get("$widget");v.dispatch("conversational-hub-provider:evaluate",S)}),s.actions.watch("conversation.action",(S,v)=>(C()&&I(S),v(S))),s.actions.watch("conversation.user-submit",(S,v)=>{if(!C())return v(S);T(S.text),d.user.print(S.text.replace(/</g,"<").replace(/>/g,">"))}),i.events.subscribe("conversational-hub-provider:fetch-guide",async(S,v)=>{if(!(v!=null&&v.guideId))return;const _=await a.fetchGuide(parseInt(v.guideId));_&&g(_)})});async function g(r){r.forEach(s=>{const o=s.items.map(c=>c.message);s.writer=p.print(o)})}const f=sessionStorage.getItem(`humany_${L(i.implementation.tenant+i.implementation.name+i.name)}`);function L(r){let s=0;if(r.length===0)return s.toString();for(let o=0;o<r.length;o++){const c=r.charCodeAt(o);s=(s<<5)-s+c,s=s&s}return s.toString()}async function k(r=!0){const s=await j.readStorage(n,"conversational-hub-session"),o=n.get("dialogflowSettings");if(o!=null&&o.silentStart)delete o.silentStart,i.events.dispatch("conversational-hub-provider:started",{});else if(s!=null&&s.sessionId&&r)P=s==null?void 0:s.sessionId;else if(t!=null&&t.welcomeMessage){if(!(f!=null&&f.length?JSON.parse(f):{})["conversation-conversation"]){const h=t.welcomeMessage.replaceAll("$lt;","<").replaceAll("$gt;",">");p.print(h)}}else{const c={extension:t.extension};o!=null&&o.initCommand&&(c.input={type:"event",language:t.language,content:{name:o.initCommand,parameters:o.initParameters||{}}}),await x(t.baseUrl+"/initialize",JSON.stringify(c),r)}}async function I(r){await x(`${t.baseUrl}/input/${P}`,`{"type":"button_click","language":"${t.language}","content":{"button_text":"${r.label}","value":"${r.actionKey}"}}`)}async function T(r){const s={text:r};if(!P){const o={extension:t.extension},c=n.get("dialogflowSettings");c!=null&&c.initCommand&&(o.input={type:"event",language:t.language,content:{name:c.initCommand,parameters:c.initParameters||{}}}),await x(t.baseUrl+"/initialize",JSON.stringify(o),!1)}await x(`${t.baseUrl}/input/${P}`,`{"type":"text","language":"${t.language}","content":${JSON.stringify(s)}}`)}async function x(r,s,o=!0){var S,v,_,R;const c=d.loading();let h,C;try{h=await fetch(r,{method:"POST",body:s}),C=await(h==null?void 0:h.json())}catch(q){q instanceof SyntaxError?K.Logger.error("Incorrect JSON format.",q):K.Logger.error("Network error: check connection or baseUrl.",q),c(),p.print(t.errorMessage||"An error occurred");return}if(!(h!=null&&h.ok)){if(K.Logger.error(`HTTP ${h==null?void 0:h.status}.`,JSON.stringify(C)),c(),!!((S=C==null?void 0:C.errors)!=null&&S.filter(E=>E.code==="1003").length)&&M>0){M--,await new Promise(Q=>setTimeout(Q,500)),await k(!1);const E=JSON.parse(s);(v=E==null?void 0:E.content)!=null&&v.text?await T(E.content.text):(_=E==null?void 0:E.content)!=null&&_.action&&await I((R=E==null?void 0:E.content)==null?void 0:R.action)}else p.print(t.errorMessage||"An error occurred");return}c(),M=(t==null?void 0:t.connectionAttempts)??5,C!=null&&C.action_payload&&H(C.action_payload),P=C==null?void 0:C.session_id,u({sessionId:P}),o&&W(C)}async function H(r){var h;const s=(h=r==null?void 0:r.transfer_parameters)==null?void 0:h.contactGuide,o=d.loading(),c=await a.fetchGuide(parseInt(s));o(),c&&g(c)}function W(r){var s;r==null||r.agent_response.forEach(o=>{p.print(o.payload.text)}),(s=r==null?void 0:r.prompt)!=null&&s.items&&p.print(["button-list",{actions:r.prompt.items.map(o=>{let c;return o.type==="button"&&(c={actionKey:o.value,label:o.text}),o.type==="link"&&(c={actionKey:o.value,label:o.text,data:{href:o.url,target:(t==null?void 0:t.linkTarget)??"_blank"}}),c})}])}},ht=Z.createConfigurationApi(n=>{n.createCommand("dialogflow",e=>i=>{const t={initCommand:i.initCommand};i.initParameters&&(t.initParameters=i.initParameters),i.silentStart&&(t.silentStart=i.silentStart),e.container.register("dialogflowSettings",t)})});exports.ConversationalHubPlugin=ft;exports.dialogflowConfigurationApi=ht;exports.updateForm=z;
|