@telia-ace/conversational-hub-bot-provider 1.3.10 → 1.3.11-rc.1
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-b3890fe6.js → contact-method-7ef5dc54.js} +1 -1
- package/{contact-method-65f71f64.mjs → contact-method-999b4ded.mjs} +1 -1
- package/contact-method-list-9988be12.js +28 -0
- package/contact-method-list-a00fee0e.mjs +108 -0
- package/index-088c9fb0.mjs +579 -0
- package/index-b1b50837.js +1 -0
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +10 -10
- package/types.d.ts +2 -1
- package/ui/contact-method-list.d.ts +10 -0
- package/utils.d.ts +7 -1
- package/index-02b60805.js +0 -1
- package/index-735998e7.mjs +0 -421
|
@@ -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-b1b50837.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");const z=({contactMethodId:n,guideId:o,groupId:m,className:x})=>{var C,v,w;const[e,s]=c.useState(),d=p.useContainer(),D=p.useDispatch(),b=c.useRef(!0),l=p.useConversation();c.useEffect(()=>{const{events:u}=d.get("$widget"),q=u.subscribe("conversational-hub-provider:form-submitted",async(f,r)=>{var M;if(((M=r.form.meta)==null?void 0:M.groupId)!==m||r.id!==(e==null?void 0:e.id))return;l&&(r.form.meta||(r.form.meta={}),r.form.meta.conversation=l);const y=await d.getAsync("contactMethods"),t={...e,body:{...e.body,form:r.form}},{errors:i,valid:h,errorTypes:N}=await y.validate(t);if(!h){const S=new T.FormBuilder(e.body.form);s(void 0),S.setValidationErrors(i),t.body={...t.body,form:S.get()},s({...t});return}const E=await y.submit(t);t.confirmation=E,s(t)}),a=u.subscribe("bot-provider:evaluate",async(f,r)=>{if(r.id!==n)return;const t=await(await d.getAsync("contactMethods")).evaluate(e);let i={...e,body:{...e.body,form:t}};const h=k.updateForm(i,{submit:"Submit",errors:{},meta:{groupId:m}});i={...i,body:h},s(i)});return()=>{q(),a()}},[d,e,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]),e?j.jsx(B,{...e,body:{...e.body,form:e.body.form?{...e.body.form,data:(C=e.body.form)==null?void 0:C.data,layout:{...e.body.form.layout},meta:(v=e.body.form)==null?void 0:v.meta,schema:(w=e.body.form)==null?void 0:w.schema}:void 0,guideId:e.body.guideId},inline:!0,expanded:!0,dispatch:D,className:$.appendClassNames("humany-bot-contact-method",x)}):null},B=A(R.ContactMethod)`
|
|
2
2
|
padding: ${n=>{var o;return(o=n.theme.sizes)==null?void 0:o.normal}} ${n=>{var o;return(o=n.theme.sizes)==null?void 0:o.medium}};
|
|
3
3
|
`;exports.default=z;
|
|
@@ -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-088c9fb0.mjs";
|
|
10
10
|
import "@telia-ace/widget-conversation";
|
|
11
11
|
import "@telia-ace/widget-services";
|
|
12
12
|
const tt = ({
|
|
@@ -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"),b=require("./contact-method-7ef5dc54.js");require("@telia-ace/knowledge-data-client");require("@telia-ace/widget-forms");require("@telia-ace/widget-utilities");require("./index-b1b50837.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");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;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { jsx as a } from "react/jsx-runtime";
|
|
2
|
+
import l from "@emotion/styled";
|
|
3
|
+
import { ContactList as M, ContactMethod as b } from "@telia-ace/knowledge-widget-adapters";
|
|
4
|
+
import { useDispatch as $, useContainer as k } from "@telia-ace/knowledge-widget-ui";
|
|
5
|
+
import { useState as f, useEffect as E } from "react";
|
|
6
|
+
import S from "./contact-method-999b4ded.mjs";
|
|
7
|
+
import "@telia-ace/knowledge-data-client";
|
|
8
|
+
import "@telia-ace/widget-forms";
|
|
9
|
+
import "@telia-ace/widget-utilities";
|
|
10
|
+
import "./index-088c9fb0.mjs";
|
|
11
|
+
import "@telia-ace/widget-conversation";
|
|
12
|
+
import "@telia-ace/widget-services";
|
|
13
|
+
const F = ({ actions: t, entryId: e, groupId: y }) => {
|
|
14
|
+
const g = $(), d = k(), [m, x] = f([]), [r, C] = f([]);
|
|
15
|
+
return E(() => {
|
|
16
|
+
d.getAsync("contactMethods").then((i) => {
|
|
17
|
+
if (!i)
|
|
18
|
+
return;
|
|
19
|
+
const c = t.map(async (n) => {
|
|
20
|
+
var p;
|
|
21
|
+
if (!((p = n.data) != null && p.clientName))
|
|
22
|
+
return null;
|
|
23
|
+
const o = await i.handleAdapters(n.data);
|
|
24
|
+
return {
|
|
25
|
+
...o,
|
|
26
|
+
...n.data,
|
|
27
|
+
description: n.data.description ? n.data.description : o.description,
|
|
28
|
+
onClick: (u, s) => {
|
|
29
|
+
if (typeof o.onClick == "function" && o.onClick(u, s), !u.defaultPrevented)
|
|
30
|
+
if (s.inline && !s.expanded)
|
|
31
|
+
C([...r, s.id]);
|
|
32
|
+
else {
|
|
33
|
+
const { events: h } = d.get("$widget");
|
|
34
|
+
h.dispatch(
|
|
35
|
+
"conversational-hub-provider:open-contact-method",
|
|
36
|
+
{
|
|
37
|
+
entryId: e,
|
|
38
|
+
contactMethod: s,
|
|
39
|
+
actionKey: n.actionKey
|
|
40
|
+
}
|
|
41
|
+
), h.dispatch(
|
|
42
|
+
"tracking:contact-method-list-item-clicked",
|
|
43
|
+
s
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
Promise.all(c).then((n) => {
|
|
50
|
+
x(n.filter((o) => !!o));
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}, [t, d, e, r]), m.length ? /* @__PURE__ */ a(
|
|
54
|
+
j,
|
|
55
|
+
{
|
|
56
|
+
className: "humany-bot-contact-list",
|
|
57
|
+
contactMethods: m,
|
|
58
|
+
dispatch: g,
|
|
59
|
+
itemRenderer: (i, c) => (r.includes(i.id) || i.expanded) && i.inline || i.clientName === "custom.link" ? /* @__PURE__ */ a(
|
|
60
|
+
v,
|
|
61
|
+
{
|
|
62
|
+
contactMethodId: i.id,
|
|
63
|
+
groupId: y,
|
|
64
|
+
guideId: i.body.guideId
|
|
65
|
+
}
|
|
66
|
+
) : /* @__PURE__ */ a(z, { ...i, ...c })
|
|
67
|
+
}
|
|
68
|
+
) : null;
|
|
69
|
+
}, j = l(M)`
|
|
70
|
+
> ul > li {
|
|
71
|
+
a {
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
outline-offset: -2px;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
&:not(:last-child) {
|
|
78
|
+
${(t) => t.theme.border && `border-bottom: ${t.theme.border};`}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
`, v = l(S)`
|
|
82
|
+
i {
|
|
83
|
+
margin: 0 ${(t) => {
|
|
84
|
+
var e;
|
|
85
|
+
return (e = t.theme.sizes) == null ? void 0 : e.medium;
|
|
86
|
+
}} 0 0;
|
|
87
|
+
display: flex;
|
|
88
|
+
justify-content: center;
|
|
89
|
+
align-items: center;
|
|
90
|
+
}
|
|
91
|
+
`, z = l(b)`
|
|
92
|
+
padding: ${(t) => {
|
|
93
|
+
var e;
|
|
94
|
+
return (e = t.theme.sizes) == null ? void 0 : e.medium;
|
|
95
|
+
}};
|
|
96
|
+
i {
|
|
97
|
+
margin: 0 ${(t) => {
|
|
98
|
+
var e;
|
|
99
|
+
return (e = t.theme.sizes) == null ? void 0 : e.medium;
|
|
100
|
+
}} 0 0;
|
|
101
|
+
display: flex;
|
|
102
|
+
justify-content: center;
|
|
103
|
+
align-items: center;
|
|
104
|
+
}
|
|
105
|
+
`;
|
|
106
|
+
export {
|
|
107
|
+
F as default
|
|
108
|
+
};
|
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
var X = Object.defineProperty;
|
|
2
|
+
var Y = (n, e, i) => e in n ? X(n, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : n[e] = i;
|
|
3
|
+
var $ = (n, e, i) => (Y(n, typeof e != "symbol" ? e + "" : e, i), i);
|
|
4
|
+
import { ConversationMessageListItemType as H, registerCustomMessageComponent as J, ConversationPlatform as Z } from "@telia-ace/widget-conversation";
|
|
5
|
+
import { readStorage as z, createStorageWriter as W, StorageCategory as q } from "@telia-ace/widget-services";
|
|
6
|
+
import { uuid as V, Logger as G } from "@telia-ace/widget-utilities";
|
|
7
|
+
import { FormBuilder as U, submitButton as tt } from "@telia-ace/widget-forms";
|
|
8
|
+
class et {
|
|
9
|
+
constructor(e) {
|
|
10
|
+
$(this, "enabled", !0);
|
|
11
|
+
// set whether or not to store data
|
|
12
|
+
$(this, "botProviderGlobalStateKey", "bot-provider-global-state");
|
|
13
|
+
$(this, "botProviderLocalStateKey", "bot-provider-local-state");
|
|
14
|
+
$(this, "botProviderEntriesKey", "bot-provider-entries");
|
|
15
|
+
$(this, "botProviderMetaStateKey", "bot-provider-conversation-meta");
|
|
16
|
+
this.container = e;
|
|
17
|
+
}
|
|
18
|
+
getKey(e) {
|
|
19
|
+
let i;
|
|
20
|
+
switch (e) {
|
|
21
|
+
case "localState":
|
|
22
|
+
i = this.botProviderLocalStateKey;
|
|
23
|
+
break;
|
|
24
|
+
case "globalState":
|
|
25
|
+
i = this.botProviderGlobalStateKey;
|
|
26
|
+
break;
|
|
27
|
+
case "entries":
|
|
28
|
+
i = this.botProviderEntriesKey;
|
|
29
|
+
break;
|
|
30
|
+
case "meta":
|
|
31
|
+
i = this.botProviderMetaStateKey;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
return i;
|
|
35
|
+
}
|
|
36
|
+
async read(e) {
|
|
37
|
+
const i = this.getKey(e);
|
|
38
|
+
if (!(!this.enabled || !i))
|
|
39
|
+
return z(this.container, i);
|
|
40
|
+
}
|
|
41
|
+
async write(e, i) {
|
|
42
|
+
const t = this.getKey(i);
|
|
43
|
+
if (!this.enabled || !t)
|
|
44
|
+
return;
|
|
45
|
+
(await W(
|
|
46
|
+
this.container,
|
|
47
|
+
t,
|
|
48
|
+
q.Necessary
|
|
49
|
+
))(e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
var K = /* @__PURE__ */ ((n) => (n.ContactMethod = "ace-conversational-hub-contact-method", n.ContactList = "ace-conversational-hub-contact-list", n))(K || {});
|
|
53
|
+
const nt = (n) => {
|
|
54
|
+
if (n) {
|
|
55
|
+
const { type: e, content: i } = n;
|
|
56
|
+
if (e && i)
|
|
57
|
+
return { type: e, content: i };
|
|
58
|
+
}
|
|
59
|
+
}, it = ({
|
|
60
|
+
isUser: n,
|
|
61
|
+
items: e = [],
|
|
62
|
+
meta: i = {}
|
|
63
|
+
}) => {
|
|
64
|
+
const t = V();
|
|
65
|
+
return {
|
|
66
|
+
id: t,
|
|
67
|
+
isUser: n,
|
|
68
|
+
items: e.map((m) => ({
|
|
69
|
+
id: m.id || V(),
|
|
70
|
+
isUser: n,
|
|
71
|
+
groupId: t,
|
|
72
|
+
message: m.message || []
|
|
73
|
+
})),
|
|
74
|
+
meta: i
|
|
75
|
+
};
|
|
76
|
+
}, ot = ({
|
|
77
|
+
id: n,
|
|
78
|
+
title: e,
|
|
79
|
+
defaultIcon: i,
|
|
80
|
+
exits: [t],
|
|
81
|
+
exitType: r,
|
|
82
|
+
confirmationText: m,
|
|
83
|
+
expandFormAutomatically: g,
|
|
84
|
+
form: k,
|
|
85
|
+
description: M
|
|
86
|
+
}, o = {}) => {
|
|
87
|
+
const { adapter: s } = t || { Adapter: {} }, {
|
|
88
|
+
clientName: l = "",
|
|
89
|
+
settings: b = {},
|
|
90
|
+
customClientName: u = ""
|
|
91
|
+
} = s, { validation: p } = o, d = {
|
|
92
|
+
id: n.toString(),
|
|
93
|
+
title: e,
|
|
94
|
+
description: M,
|
|
95
|
+
symbol: nt(i),
|
|
96
|
+
clientName: l === "custom.adapter" ? u : l,
|
|
97
|
+
expanded: !0,
|
|
98
|
+
inline: !0,
|
|
99
|
+
body: {}
|
|
100
|
+
};
|
|
101
|
+
if (l.indexOf("phone") > -1 || l.indexOf("freetext") > -1) {
|
|
102
|
+
const { displayTextBeforeClick: y, textBeforeClick: v } = b;
|
|
103
|
+
y === "true" && (d.expanded = !1, d.title = v), l.indexOf("phone.text") > -1 ? d.body.phoneNumber = b.phoneNumber : d.body.freetext = b.freetext;
|
|
104
|
+
}
|
|
105
|
+
return (l.indexOf("chat.popup") > -1 || l.indexOf("link") > -1 || l === "custom.adapter" && r === "custom") && (d.body = b, d.body.confirmationFallback = m), l.indexOf("ace") > -1 && (d.body = b), k && k.hasValueComponents && (p ? d.body.form = U.fromLegacyForm(
|
|
106
|
+
n.toString(),
|
|
107
|
+
k,
|
|
108
|
+
p
|
|
109
|
+
).get() : d.body.form = U.fromLegacyForm(
|
|
110
|
+
n.toString(),
|
|
111
|
+
k
|
|
112
|
+
).get(), g || (d.expanded = d.inline = !1), d.body = at(d, { submit: "Submit" })), o.guideId && (d.body.guideId = o.guideId), d;
|
|
113
|
+
}, st = (n) => {
|
|
114
|
+
const { localState: e } = n;
|
|
115
|
+
return n.tags.includes("category") && n.tags.includes("contact") ? H.ItemList : n.tags.includes("suggestion") ? H.LinkList : (e == null ? void 0 : e.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching" ? K.ContactList : H.ButtonList;
|
|
116
|
+
}, at = (n, {
|
|
117
|
+
submit: e,
|
|
118
|
+
errors: i,
|
|
119
|
+
meta: t
|
|
120
|
+
}) => {
|
|
121
|
+
var r;
|
|
122
|
+
if ((r = n == null ? void 0 : n.body) != null && r.form) {
|
|
123
|
+
const { body: m } = n, g = new U(m.form);
|
|
124
|
+
return m.form.layout.submit || g.createComponent(tt(e, "submit")), i && g.setValidationErrors(i), t && g.setMeta(t), {
|
|
125
|
+
...m,
|
|
126
|
+
form: g.get()
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return (n == null ? void 0 : n.body) || {};
|
|
130
|
+
}, rt = async (n, e, i) => {
|
|
131
|
+
(await (await n.getAsync("dataClient")).getClient()).parameters.set(e, i);
|
|
132
|
+
}, N = ({
|
|
133
|
+
messageId: n,
|
|
134
|
+
message: e,
|
|
135
|
+
group: i
|
|
136
|
+
}) => ({
|
|
137
|
+
id: n,
|
|
138
|
+
message: e,
|
|
139
|
+
groupId: i.id,
|
|
140
|
+
isUser: i.isUser
|
|
141
|
+
}), ct = async (n, e, i) => {
|
|
142
|
+
const t = (o, s, l, b = {
|
|
143
|
+
actions: [],
|
|
144
|
+
entryId: s.id,
|
|
145
|
+
groupId: l
|
|
146
|
+
}) => {
|
|
147
|
+
const u = [];
|
|
148
|
+
return b.actions = s.content.items.map((p) => {
|
|
149
|
+
var y;
|
|
150
|
+
const d = {
|
|
151
|
+
label: p.title,
|
|
152
|
+
actionKey: p.actionKey,
|
|
153
|
+
symbol: p.symbol ? p.symbol : void 0,
|
|
154
|
+
description: p.description || void 0
|
|
155
|
+
};
|
|
156
|
+
if (p.data) {
|
|
157
|
+
const v = s.actions[p.actionKey];
|
|
158
|
+
o === K.ContactList ? (u.push(p.data.id), d.data = ot(p.data, {
|
|
159
|
+
guideId: (y = v == null ? void 0 : v.guideId) == null ? void 0 : y.toString()
|
|
160
|
+
})) : d.data = p.data;
|
|
161
|
+
}
|
|
162
|
+
return d;
|
|
163
|
+
}), o === K.ContactList && (b.contactMethodIds = u), b;
|
|
164
|
+
}, r = async (o, s, l = [], b) => {
|
|
165
|
+
var p, d;
|
|
166
|
+
const u = V();
|
|
167
|
+
switch (o.type !== "List" && o.tags.includes("guide") && ((d = (p = o.content.hints) == null ? void 0 : p[0]) != null && d.id) && await rt(
|
|
168
|
+
n,
|
|
169
|
+
"LastGuideId",
|
|
170
|
+
o.content.hints[0].id
|
|
171
|
+
), o.type) {
|
|
172
|
+
case "List": {
|
|
173
|
+
if (!o.content)
|
|
174
|
+
return [];
|
|
175
|
+
const { items: y, html: v } = o.content, I = [];
|
|
176
|
+
let C = {
|
|
177
|
+
actions: [],
|
|
178
|
+
entryId: o.id,
|
|
179
|
+
groupId: s.id
|
|
180
|
+
};
|
|
181
|
+
if ((y == null ? void 0 : y.length) > 0) {
|
|
182
|
+
const P = st(o);
|
|
183
|
+
if (C = t(
|
|
184
|
+
P,
|
|
185
|
+
o,
|
|
186
|
+
s.id,
|
|
187
|
+
C
|
|
188
|
+
), l.length) {
|
|
189
|
+
const O = l.find(
|
|
190
|
+
(T) => T.tags.includes("paging")
|
|
191
|
+
);
|
|
192
|
+
O != null && O.content && (s.meta.paging = {
|
|
193
|
+
actions: O.actions,
|
|
194
|
+
items: O.content.items,
|
|
195
|
+
localState: O.localState
|
|
196
|
+
}, O.content.items.forEach((T) => {
|
|
197
|
+
C.actions.push({
|
|
198
|
+
label: T.title,
|
|
199
|
+
actionKey: T.actionKey,
|
|
200
|
+
data: {
|
|
201
|
+
groupId: b ? b.id : s.id
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
I.unshift(
|
|
207
|
+
N({
|
|
208
|
+
messageId: u,
|
|
209
|
+
message: [P, C],
|
|
210
|
+
group: s
|
|
211
|
+
})
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
return v && I.unshift(
|
|
215
|
+
N({
|
|
216
|
+
messageId: u,
|
|
217
|
+
message: [H.HTML, { body: v }],
|
|
218
|
+
group: s
|
|
219
|
+
})
|
|
220
|
+
), I;
|
|
221
|
+
}
|
|
222
|
+
case "Text": {
|
|
223
|
+
const y = [];
|
|
224
|
+
if (y.push(
|
|
225
|
+
N({
|
|
226
|
+
messageId: u,
|
|
227
|
+
message: [
|
|
228
|
+
H.HTML,
|
|
229
|
+
{ body: o.content.html }
|
|
230
|
+
],
|
|
231
|
+
group: s
|
|
232
|
+
})
|
|
233
|
+
), l.length) {
|
|
234
|
+
const v = l.find(
|
|
235
|
+
(C) => {
|
|
236
|
+
var P;
|
|
237
|
+
return C.type === "List" && ((P = C.localState) == null ? void 0 : P.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching";
|
|
238
|
+
}
|
|
239
|
+
), I = l.find(
|
|
240
|
+
(C) => C.tags.includes("contact") && C.type === "Contact"
|
|
241
|
+
);
|
|
242
|
+
if (I && y.push(
|
|
243
|
+
N({
|
|
244
|
+
messageId: u,
|
|
245
|
+
message: [
|
|
246
|
+
K.ContactMethod,
|
|
247
|
+
{
|
|
248
|
+
contactMethodId: I.content.id,
|
|
249
|
+
groupId: s.id,
|
|
250
|
+
guideId: I.content.guideId
|
|
251
|
+
}
|
|
252
|
+
],
|
|
253
|
+
group: s
|
|
254
|
+
})
|
|
255
|
+
), v) {
|
|
256
|
+
const C = t(
|
|
257
|
+
K.ContactList,
|
|
258
|
+
v,
|
|
259
|
+
s.id
|
|
260
|
+
);
|
|
261
|
+
y.push(
|
|
262
|
+
N({
|
|
263
|
+
messageId: u,
|
|
264
|
+
message: [
|
|
265
|
+
H.Separator,
|
|
266
|
+
void 0
|
|
267
|
+
],
|
|
268
|
+
group: s
|
|
269
|
+
})
|
|
270
|
+
), y.push(
|
|
271
|
+
N({
|
|
272
|
+
messageId: u,
|
|
273
|
+
message: [K.ContactList, C],
|
|
274
|
+
group: s
|
|
275
|
+
})
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return y;
|
|
280
|
+
}
|
|
281
|
+
case "Contact":
|
|
282
|
+
return [
|
|
283
|
+
N({
|
|
284
|
+
messageId: u,
|
|
285
|
+
message: [
|
|
286
|
+
K.ContactMethod,
|
|
287
|
+
{
|
|
288
|
+
contactMethodId: o.content.id,
|
|
289
|
+
groupId: s.id,
|
|
290
|
+
guideId: o.content.guideId
|
|
291
|
+
}
|
|
292
|
+
],
|
|
293
|
+
group: s
|
|
294
|
+
})
|
|
295
|
+
];
|
|
296
|
+
case "Error":
|
|
297
|
+
return [
|
|
298
|
+
N({
|
|
299
|
+
messageId: u,
|
|
300
|
+
message: [
|
|
301
|
+
H.HTML,
|
|
302
|
+
{
|
|
303
|
+
body: o.content.message || "Something went wrong."
|
|
304
|
+
}
|
|
305
|
+
],
|
|
306
|
+
group: s
|
|
307
|
+
})
|
|
308
|
+
];
|
|
309
|
+
default:
|
|
310
|
+
return [];
|
|
311
|
+
}
|
|
312
|
+
}, m = /* @__PURE__ */ new Map([
|
|
313
|
+
["Text", 1],
|
|
314
|
+
["List", 2],
|
|
315
|
+
["Contact", 3]
|
|
316
|
+
]), g = [], k = e.sort((o, s) => {
|
|
317
|
+
const b = m.get(o.type) || 20, u = m.get(s.type) || 20;
|
|
318
|
+
return b - u;
|
|
319
|
+
}).filter((o) => !o.relation).reduce((o, s) => o.concat(s), []), M = (o) => typeof o.actions.selector < "u";
|
|
320
|
+
for (const o of k) {
|
|
321
|
+
const s = e.filter(
|
|
322
|
+
(u) => u.relation === o.id && !M(u)
|
|
323
|
+
), l = it({ isUser: !1 });
|
|
324
|
+
(await r(o, l, s, i)).forEach((u) => {
|
|
325
|
+
l.items.push(u);
|
|
326
|
+
}), l.items.length && g.push(l);
|
|
327
|
+
}
|
|
328
|
+
return g;
|
|
329
|
+
};
|
|
330
|
+
class lt {
|
|
331
|
+
constructor(e, i, t, r) {
|
|
332
|
+
$(this, "globalState");
|
|
333
|
+
$(this, "localState");
|
|
334
|
+
$(this, "clientId");
|
|
335
|
+
$(this, "entries");
|
|
336
|
+
this.endpoint = e, this.events = i, this.store = t, this.container = r, this.clientId = V(), this.entries = [];
|
|
337
|
+
}
|
|
338
|
+
async fetchGuide(e) {
|
|
339
|
+
const i = {
|
|
340
|
+
command: { guide: { id: e } },
|
|
341
|
+
globalState: this.globalState,
|
|
342
|
+
clientId: this.clientId
|
|
343
|
+
};
|
|
344
|
+
return await this.postEnvelope(i);
|
|
345
|
+
}
|
|
346
|
+
async postEnvelope(e, i) {
|
|
347
|
+
try {
|
|
348
|
+
const t = await fetch(
|
|
349
|
+
this.endpoint,
|
|
350
|
+
this.getHttpOptions(e)
|
|
351
|
+
);
|
|
352
|
+
if (!t.ok)
|
|
353
|
+
throw t;
|
|
354
|
+
const r = await t.json();
|
|
355
|
+
return this.handleResponse(r, i);
|
|
356
|
+
} catch (t) {
|
|
357
|
+
process.env.NODE_ENV !== "production" && console.warn("Something went wrong when posting the envelope.");
|
|
358
|
+
let r = "Something went wrong";
|
|
359
|
+
return (t.message === "Failed to fetch" || t.message === "NetworkError when attempting to fetch resource.") && (r = "Lost connection... Please try again."), this.events.dispatch("tracking:http-client-error", { message: r, error: t }), this.handleResponse({
|
|
360
|
+
entries: [
|
|
361
|
+
{
|
|
362
|
+
id: V(),
|
|
363
|
+
type: "Error",
|
|
364
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
365
|
+
content: {
|
|
366
|
+
message: r
|
|
367
|
+
},
|
|
368
|
+
actions: {},
|
|
369
|
+
tags: []
|
|
370
|
+
}
|
|
371
|
+
]
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
async handleResponse(e, i) {
|
|
376
|
+
this.entries = this.entries.concat(e.entries), this.store.write(this.entries, "entries");
|
|
377
|
+
const t = e.entries.find((m) => m.type === "Widget");
|
|
378
|
+
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(
|
|
379
|
+
(m, g) => g.localState ? g.localState : m,
|
|
380
|
+
void 0
|
|
381
|
+
), this.store.write(this.localState, "localState"), await ct(
|
|
382
|
+
this.container,
|
|
383
|
+
e.entries,
|
|
384
|
+
i
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
getHttpOptions(e) {
|
|
388
|
+
const i = {
|
|
389
|
+
method: "POST",
|
|
390
|
+
headers: {
|
|
391
|
+
Accept: "application/json",
|
|
392
|
+
"Content-Type": "application/json"
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
return e.funnel = this.container.get("$widget").name, e.localState = e.localState || this.localState, Object.assign({}, i, {
|
|
396
|
+
body: JSON.stringify(e),
|
|
397
|
+
credentials: "same-origin"
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
const dt = "@telia-ace/conversational-hub-bot-provider", ut = "0.0.16", gt = "./index.js", ft = "./index.d.ts", mt = {
|
|
402
|
+
".": {
|
|
403
|
+
import: "./index.mjs",
|
|
404
|
+
require: "./index.js"
|
|
405
|
+
}
|
|
406
|
+
}, pt = {
|
|
407
|
+
"@telia-ace/widget-conversation": "*",
|
|
408
|
+
"@webprovisions/platform": "^1.1.4",
|
|
409
|
+
"@telia-ace/knowledge-widget-core": "*",
|
|
410
|
+
"@telia-ace/widget-utilities": "*",
|
|
411
|
+
"@telia-ace/widget-services": "*",
|
|
412
|
+
"@telia-ace/widget-core": "*",
|
|
413
|
+
"@telia-ace/knowledge-data-client": "*",
|
|
414
|
+
"@telia-ace/knowledge-widget-adapters": "*",
|
|
415
|
+
"@telia-ace/knowledge-widget-ui": "*",
|
|
416
|
+
"@telia-ace/widget-forms": "*"
|
|
417
|
+
}, ht = {
|
|
418
|
+
"@emotion/react": "11.11.1",
|
|
419
|
+
"@emotion/styled": "11.11.0",
|
|
420
|
+
react: "18.2.0"
|
|
421
|
+
}, A = {
|
|
422
|
+
name: dt,
|
|
423
|
+
version: ut,
|
|
424
|
+
main: gt,
|
|
425
|
+
types: ft,
|
|
426
|
+
exports: mt,
|
|
427
|
+
dependencies: pt,
|
|
428
|
+
peerDependencies: ht
|
|
429
|
+
}, xt = async (n) => {
|
|
430
|
+
var O, T, D, R, F;
|
|
431
|
+
const e = "chub-plugin", i = n.get("$widget"), t = (F = (R = (D = (T = (O = i == null ? void 0 : i.container) == null ? void 0 : O.get("$settings")) == null ? void 0 : T.components) == null ? void 0 : D.conversation) == null ? void 0 : R.properties) == null ? void 0 : F.conversationalHubPluginSettings;
|
|
432
|
+
let r, m, g, k = (t == null ? void 0 : t.connectionAttempts) ?? 5, M, o, s;
|
|
433
|
+
G.info((A == null ? void 0 : A.name) + " version: " + (A == null ? void 0 : A.version)), J(
|
|
434
|
+
n,
|
|
435
|
+
K.ContactMethod,
|
|
436
|
+
import("./contact-method-999b4ded.mjs")
|
|
437
|
+
), J(
|
|
438
|
+
n,
|
|
439
|
+
K.ContactList,
|
|
440
|
+
import("./contact-method-list-a00fee0e.mjs")
|
|
441
|
+
);
|
|
442
|
+
const l = await W(
|
|
443
|
+
n,
|
|
444
|
+
"conversational-hub-session",
|
|
445
|
+
q.Necessary
|
|
446
|
+
), b = (a, c) => {
|
|
447
|
+
const { knowledgeBotEndpoint: f } = c.properties();
|
|
448
|
+
if (f)
|
|
449
|
+
return `${f}/conversations`;
|
|
450
|
+
const { data: h } = a.get("$settings");
|
|
451
|
+
if (!h || !h.projection)
|
|
452
|
+
throw new Error("Missing Knowledge Bot endpoint");
|
|
453
|
+
return `${h.projection}/conversations`;
|
|
454
|
+
};
|
|
455
|
+
(await Z.getInstance(
|
|
456
|
+
n
|
|
457
|
+
)).registerProvider(e, (a, c) => {
|
|
458
|
+
r = a, m = r.controller, g = r.createAgent({
|
|
459
|
+
name: t == null ? void 0 : t.botName,
|
|
460
|
+
avatar: t == null ? void 0 : t.avatar
|
|
461
|
+
}), s = b(n, c);
|
|
462
|
+
const { events: f } = n.get("$widget"), h = new et(n);
|
|
463
|
+
o = new lt(s, f, h, n), d();
|
|
464
|
+
const [S] = n.get("widgetDOMElements");
|
|
465
|
+
S.addEventListener("click", (x) => {
|
|
466
|
+
var L;
|
|
467
|
+
if (x.target instanceof HTMLButtonElement) {
|
|
468
|
+
const B = x.target;
|
|
469
|
+
if ((L = B.getAttribute("class")) != null && L.includes("dialog-option-cx")) {
|
|
470
|
+
const j = B.getAttribute("value");
|
|
471
|
+
v(j), r.user.print(
|
|
472
|
+
j.replace(/</g, "<").replace(/>/g, ">")
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
const w = () => m.providers.includes(e);
|
|
478
|
+
window.controller = m, c.actions.create("submit", (x) => {
|
|
479
|
+
const { events: L } = n.get("$widget");
|
|
480
|
+
L.dispatch("conversational-hub-provider:form-submitted", x);
|
|
481
|
+
}), c.actions.watch("conversation.action", (x, L) => (w() && y(x), L(x))), c.actions.watch("conversation.user-submit", (x, L) => {
|
|
482
|
+
if (!w())
|
|
483
|
+
return L(x);
|
|
484
|
+
v(x.text), r.user.print(
|
|
485
|
+
x.text.replace(/</g, "<").replace(/>/g, ">")
|
|
486
|
+
);
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
async function p(a) {
|
|
490
|
+
a.forEach((c) => {
|
|
491
|
+
const f = c.items.map((h) => h.message);
|
|
492
|
+
c.writer = g.print(f);
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
async function d(a = !0) {
|
|
496
|
+
const c = await z(
|
|
497
|
+
n,
|
|
498
|
+
"conversational-hub-session"
|
|
499
|
+
);
|
|
500
|
+
c != null && c.sessionId && a ? M = c == null ? void 0 : c.sessionId : t != null && t.welcomeMessage ? g.print(t == null ? void 0 : t.welcomeMessage) : await I(
|
|
501
|
+
t.baseUrl + "/initialize",
|
|
502
|
+
`{"extension": "${t.extension}"}`,
|
|
503
|
+
a
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
async function y(a) {
|
|
507
|
+
await I(
|
|
508
|
+
`${t.baseUrl}/input/${M}`,
|
|
509
|
+
`{"type":"button_click","language":"${t.language}","content":{"button_text":"${a.label}","value":"${a.actionKey}"}}`
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
async function v(a) {
|
|
513
|
+
const c = { text: a };
|
|
514
|
+
M || await I(
|
|
515
|
+
t.baseUrl + "/initialize",
|
|
516
|
+
`{"extension": "${t.extension}"}`,
|
|
517
|
+
!1
|
|
518
|
+
), await I(
|
|
519
|
+
`${t.baseUrl}/input/${M}`,
|
|
520
|
+
`{"type":"text","language":"${t.language}","content":${JSON.stringify(c)}}`
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
async function I(a, c, f = !0) {
|
|
524
|
+
var x, L, B, j;
|
|
525
|
+
const h = r.loading();
|
|
526
|
+
let S, w;
|
|
527
|
+
try {
|
|
528
|
+
S = await fetch(a, {
|
|
529
|
+
method: "POST",
|
|
530
|
+
body: c
|
|
531
|
+
}), w = await (S == null ? void 0 : S.json());
|
|
532
|
+
} catch (_) {
|
|
533
|
+
_ instanceof SyntaxError ? G.error("Incorrect JSON format.", _) : G.error("Network error: check connection or baseUrl.", _), h(), g.print(t.errorMessage || "An error occurred");
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
if (!(S != null && S.ok)) {
|
|
537
|
+
if (G.error(`HTTP ${S == null ? void 0 : S.status}.`, JSON.stringify(w)), h(), !!((x = w == null ? void 0 : w.errors) != null && x.filter(
|
|
538
|
+
(E) => E.code === "1003"
|
|
539
|
+
).length) && k > 0) {
|
|
540
|
+
k--, await new Promise((Q) => setTimeout(Q, 500)), await d(!1);
|
|
541
|
+
const E = JSON.parse(c);
|
|
542
|
+
(L = E == null ? void 0 : E.content) != null && L.text ? await v(E.content.text) : (B = E == null ? void 0 : E.content) != null && B.action && await y((j = E == null ? void 0 : E.content) == null ? void 0 : j.action);
|
|
543
|
+
} else
|
|
544
|
+
g.print(t.errorMessage || "An error occurred");
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
h(), k = (t == null ? void 0 : t.connectionAttempts) ?? 5, w != null && w.action_payload && C(w.action_payload), M = w == null ? void 0 : w.session_id, l({ sessionId: M }), f && P(w);
|
|
548
|
+
}
|
|
549
|
+
async function C(a) {
|
|
550
|
+
var S;
|
|
551
|
+
const c = (S = a == null ? void 0 : a.transfer_parameters) == null ? void 0 : S.contactGuide, f = r.loading(), h = await o.fetchGuide(parseInt(c));
|
|
552
|
+
f(), h && p(h);
|
|
553
|
+
}
|
|
554
|
+
function P(a) {
|
|
555
|
+
var c;
|
|
556
|
+
a == null || a.agent_response.forEach((f) => {
|
|
557
|
+
g.print(f.payload.text);
|
|
558
|
+
}), (c = a == null ? void 0 : a.prompt) != null && c.items && g.print([
|
|
559
|
+
"button-list",
|
|
560
|
+
{
|
|
561
|
+
actions: a.prompt.items.map((f) => {
|
|
562
|
+
let h;
|
|
563
|
+
return f.type === "button" && (h = { actionKey: f.value, label: f.text }), f.type === "link" && (h = {
|
|
564
|
+
actionKey: f.value,
|
|
565
|
+
label: f.text,
|
|
566
|
+
data: {
|
|
567
|
+
href: f.url,
|
|
568
|
+
target: (t == null ? void 0 : t.linkTarget) ?? "_blank"
|
|
569
|
+
}
|
|
570
|
+
}), h;
|
|
571
|
+
})
|
|
572
|
+
}
|
|
573
|
+
]);
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
export {
|
|
577
|
+
xt as C,
|
|
578
|
+
at as u
|
|
579
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var z=Object.defineProperty;var W=(n,e,i)=>e in n?z(n,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):n[e]=i;var O=(n,e,i)=>(W(n,typeof e!="symbol"?e+"":e,i),i);const T=require("@telia-ace/widget-conversation"),j=require("@telia-ace/widget-services"),K=require("@telia-ace/widget-utilities"),U=require("@telia-ace/widget-forms");class Q{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 P=(n=>(n.ContactMethod="ace-conversational-hub-contact-method",n.ContactList="ace-conversational-hub-contact-list",n))(P||{});const X=n=>{if(n){const{type:e,content:i}=n;if(e&&i)return{type:e,content:i}}},Y=({isUser:n,items:e=[],meta:i={}})=>{const t=K.uuid();return{id:t,isUser:n,items:e.map(f=>({id:f.id||K.uuid(),isUser:n,groupId:t,message:f.message||[]})),meta:i}},Z=({id:n,title:e,defaultIcon:i,exits:[t],exitType:r,confirmationText:f,expandFormAutomatically:g,form:M,description:k},o={})=>{const{adapter:s}=t||{Adapter:{}},{clientName:l="",settings:b={},customClientName:u=""}=s,{validation:p}=o,d={id:n.toString(),title:e,description:k,symbol:X(i),clientName:l==="custom.adapter"?u:l,expanded:!0,inline:!0,body:{}};if(l.indexOf("phone")>-1||l.indexOf("freetext")>-1){const{displayTextBeforeClick:y,textBeforeClick:v}=b;y==="true"&&(d.expanded=!1,d.title=v),l.indexOf("phone.text")>-1?d.body.phoneNumber=b.phoneNumber:d.body.freetext=b.freetext}return(l.indexOf("chat.popup")>-1||l.indexOf("link")>-1||l==="custom.adapter"&&r==="custom")&&(d.body=b,d.body.confirmationFallback=f),l.indexOf("ace")>-1&&(d.body=b),M&&M.hasValueComponents&&(p?d.body.form=U.FormBuilder.fromLegacyForm(n.toString(),M,p).get():d.body.form=U.FormBuilder.fromLegacyForm(n.toString(),M).get(),g||(d.expanded=d.inline=!1),d.body=R(d,{submit:"Submit"})),o.guideId&&(d.body.guideId=o.guideId),d},tt=n=>{const{localState:e}=n;return n.tags.includes("category")&&n.tags.includes("contact")?T.ConversationMessageListItemType.ItemList:n.tags.includes("suggestion")?T.ConversationMessageListItemType.LinkList:(e==null?void 0:e.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"?P.ContactList:T.ConversationMessageListItemType.ButtonList},R=(n,{submit:e,errors:i,meta:t})=>{var r;if((r=n==null?void 0:n.body)!=null&&r.form){const{body:f}=n,g=new U.FormBuilder(f.form);return f.form.layout.submit||g.createComponent(U.submitButton(e,"submit")),i&&g.setValidationErrors(i),t&&g.setMeta(t),{...f,form:g.get()}}return(n==null?void 0:n.body)||{}},et=async(n,e,i)=>{(await(await n.getAsync("dataClient")).getClient()).parameters.set(e,i)},N=({messageId:n,message:e,group:i})=>({id:n,message:e,groupId:i.id,isUser:i.isUser}),nt=async(n,e,i)=>{const t=(o,s,l,b={actions:[],entryId:s.id,groupId:l})=>{const u=[];return b.actions=s.content.items.map(p=>{var y;const d={label:p.title,actionKey:p.actionKey,symbol:p.symbol?p.symbol:void 0,description:p.description||void 0};if(p.data){const v=s.actions[p.actionKey];o===P.ContactList?(u.push(p.data.id),d.data=Z(p.data,{guideId:(y=v==null?void 0:v.guideId)==null?void 0:y.toString()})):d.data=p.data}return d}),o===P.ContactList&&(b.contactMethodIds=u),b},r=async(o,s,l=[],b)=>{var p,d;const u=K.uuid();switch(o.type!=="List"&&o.tags.includes("guide")&&((d=(p=o.content.hints)==null?void 0:p[0])!=null&&d.id)&&await et(n,"LastGuideId",o.content.hints[0].id),o.type){case"List":{if(!o.content)return[];const{items:y,html:v}=o.content,L=[];let I={actions:[],entryId:o.id,groupId:s.id};if((y==null?void 0:y.length)>0){const H=tt(o);if(I=t(H,o,s.id,I),l.length){const $=l.find(A=>A.tags.includes("paging"));$!=null&&$.content&&(s.meta.paging={actions:$.actions,items:$.content.items,localState:$.localState},$.content.items.forEach(A=>{I.actions.push({label:A.title,actionKey:A.actionKey,data:{groupId:b?b.id:s.id}})}))}L.unshift(N({messageId:u,message:[H,I],group:s}))}return v&&L.unshift(N({messageId:u,message:[T.ConversationMessageListItemType.HTML,{body:v}],group:s})),L}case"Text":{const y=[];if(y.push(N({messageId:u,message:[T.ConversationMessageListItemType.HTML,{body:o.content.html}],group:s})),l.length){const v=l.find(I=>{var H;return I.type==="List"&&((H=I.localState)==null?void 0:H.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"}),L=l.find(I=>I.tags.includes("contact")&&I.type==="Contact");if(L&&y.push(N({messageId:u,message:[P.ContactMethod,{contactMethodId:L.content.id,groupId:s.id,guideId:L.content.guideId}],group:s})),v){const I=t(P.ContactList,v,s.id);y.push(N({messageId:u,message:[T.ConversationMessageListItemType.Separator,void 0],group:s})),y.push(N({messageId:u,message:[P.ContactList,I],group:s}))}}return y}case"Contact":return[N({messageId:u,message:[P.ContactMethod,{contactMethodId:o.content.id,groupId:s.id,guideId:o.content.guideId}],group:s})];case"Error":return[N({messageId:u,message:[T.ConversationMessageListItemType.HTML,{body:o.content.message||"Something went wrong."}],group:s})];default:return[]}},f=new Map([["Text",1],["List",2],["Contact",3]]),g=[],M=e.sort((o,s)=>{const b=f.get(o.type)||20,u=f.get(s.type)||20;return b-u}).filter(o=>!o.relation).reduce((o,s)=>o.concat(s),[]),k=o=>typeof o.actions.selector<"u";for(const o of M){const s=e.filter(u=>u.relation===o.id&&!k(u)),l=Y({isUser:!1});(await r(o,l,s,i)).forEach(u=>{l.items.push(u)}),l.items.length&&g.push(l)}return g};class it{constructor(e,i,t,r){O(this,"globalState");O(this,"localState");O(this,"clientId");O(this,"entries");this.endpoint=e,this.events=i,this.store=t,this.container=r,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 r=await t.json();return this.handleResponse(r,i)}catch(t){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let r="Something went wrong";return(t.message==="Failed to fetch"||t.message==="NetworkError when attempting to fetch resource.")&&(r="Lost connection... Please try again."),this.events.dispatch("tracking:http-client-error",{message:r,error:t}),this.handleResponse({entries:[{id:K.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:r},actions:{},tags:[]}]})}}async handleResponse(e,i){this.entries=this.entries.concat(e.entries),this.store.write(this.entries,"entries");const t=e.entries.find(f=>f.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((f,g)=>g.localState?g.localState:f,void 0),this.store.write(this.localState,"localState"),await nt(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 ot="@telia-ace/conversational-hub-bot-provider",st="0.0.16",at="./index.js",rt="./index.d.ts",ct={".":{import:"./index.mjs",require:"./index.js"}},lt={"@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":"*"},dt={"@emotion/react":"11.11.1","@emotion/styled":"11.11.0",react:"18.2.0"},B={name:ot,version:st,main:at,types:rt,exports:ct,dependencies:lt,peerDependencies:dt},ut=async n=>{var $,A,q,G,D;const e="chub-plugin",i=n.get("$widget"),t=(D=(G=(q=(A=($=i==null?void 0:i.container)==null?void 0:$.get("$settings"))==null?void 0:A.components)==null?void 0:q.conversation)==null?void 0:G.properties)==null?void 0:D.conversationalHubPluginSettings;let r,f,g,M=(t==null?void 0:t.connectionAttempts)??5,k,o,s;K.Logger.info((B==null?void 0:B.name)+" version: "+(B==null?void 0:B.version)),T.registerCustomMessageComponent(n,P.ContactMethod,Promise.resolve().then(()=>require("./contact-method-7ef5dc54.js"))),T.registerCustomMessageComponent(n,P.ContactList,Promise.resolve().then(()=>require("./contact-method-list-9988be12.js")));const l=await j.createStorageWriter(n,"conversational-hub-session",j.StorageCategory.Necessary),b=(a,c)=>{const{knowledgeBotEndpoint:m}=c.properties();if(m)return`${m}/conversations`;const{data:h}=a.get("$settings");if(!h||!h.projection)throw new Error("Missing Knowledge Bot endpoint");return`${h.projection}/conversations`};(await T.ConversationPlatform.getInstance(n)).registerProvider(e,(a,c)=>{r=a,f=r.controller,g=r.createAgent({name:t==null?void 0:t.botName,avatar:t==null?void 0:t.avatar}),s=b(n,c);const{events:m}=n.get("$widget"),h=new Q(n);o=new it(s,m,h,n),d();const[S]=n.get("widgetDOMElements");S.addEventListener("click",C=>{var x;if(C.target instanceof HTMLButtonElement){const F=C.target;if((x=F.getAttribute("class"))!=null&&x.includes("dialog-option-cx")){const V=F.getAttribute("value");v(V),r.user.print(V.replace(/</g,"<").replace(/>/g,">"))}}});const w=()=>f.providers.includes(e);window.controller=f,c.actions.create("submit",C=>{const{events:x}=n.get("$widget");x.dispatch("conversational-hub-provider:form-submitted",C)}),c.actions.watch("conversation.action",(C,x)=>(w()&&y(C),x(C))),c.actions.watch("conversation.user-submit",(C,x)=>{if(!w())return x(C);v(C.text),r.user.print(C.text.replace(/</g,"<").replace(/>/g,">"))})});async function p(a){a.forEach(c=>{const m=c.items.map(h=>h.message);c.writer=g.print(m)})}async function d(a=!0){const c=await j.readStorage(n,"conversational-hub-session");c!=null&&c.sessionId&&a?k=c==null?void 0:c.sessionId:t!=null&&t.welcomeMessage?g.print(t==null?void 0:t.welcomeMessage):await L(t.baseUrl+"/initialize",`{"extension": "${t.extension}"}`,a)}async function y(a){await L(`${t.baseUrl}/input/${k}`,`{"type":"button_click","language":"${t.language}","content":{"button_text":"${a.label}","value":"${a.actionKey}"}}`)}async function v(a){const c={text:a};k||await L(t.baseUrl+"/initialize",`{"extension": "${t.extension}"}`,!1),await L(`${t.baseUrl}/input/${k}`,`{"type":"text","language":"${t.language}","content":${JSON.stringify(c)}}`)}async function L(a,c,m=!0){var C,x,F,V;const h=r.loading();let S,w;try{S=await fetch(a,{method:"POST",body:c}),w=await(S==null?void 0:S.json())}catch(_){_ instanceof SyntaxError?K.Logger.error("Incorrect JSON format.",_):K.Logger.error("Network error: check connection or baseUrl.",_),h(),g.print(t.errorMessage||"An error occurred");return}if(!(S!=null&&S.ok)){if(K.Logger.error(`HTTP ${S==null?void 0:S.status}.`,JSON.stringify(w)),h(),!!((C=w==null?void 0:w.errors)!=null&&C.filter(E=>E.code==="1003").length)&&M>0){M--,await new Promise(J=>setTimeout(J,500)),await d(!1);const E=JSON.parse(c);(x=E==null?void 0:E.content)!=null&&x.text?await v(E.content.text):(F=E==null?void 0:E.content)!=null&&F.action&&await y((V=E==null?void 0:E.content)==null?void 0:V.action)}else g.print(t.errorMessage||"An error occurred");return}h(),M=(t==null?void 0:t.connectionAttempts)??5,w!=null&&w.action_payload&&I(w.action_payload),k=w==null?void 0:w.session_id,l({sessionId:k}),m&&H(w)}async function I(a){var S;const c=(S=a==null?void 0:a.transfer_parameters)==null?void 0:S.contactGuide,m=r.loading(),h=await o.fetchGuide(parseInt(c));m(),h&&p(h)}function H(a){var c;a==null||a.agent_response.forEach(m=>{g.print(m.payload.text)}),(c=a==null?void 0:a.prompt)!=null&&c.items&&g.print(["button-list",{actions:a.prompt.items.map(m=>{let h;return m.type==="button"&&(h={actionKey:m.value,label:m.text}),m.type==="link"&&(h={actionKey:m.value,label:m.text,data:{href:m.url,target:(t==null?void 0:t.linkTarget)??"_blank"}}),h})}])}};exports.ConversationalHubPlugin=ut;exports.updateForm=R;
|
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-b1b50837.js");require("@telia-ace/widget-conversation");require("@telia-ace/widget-services");require("@telia-ace/widget-utilities");require("@telia-ace/widget-forms");exports.ConversationalHubPlugin=e.ConversationalHubPlugin;
|
package/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/conversational-hub-bot-provider",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.11-rc.1",
|
|
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.
|
|
13
|
+
"@telia-ace/widget-conversation": "^1.3.11-rc.1",
|
|
14
14
|
"@webprovisions/platform": "^1.1.4",
|
|
15
|
-
"@telia-ace/knowledge-widget-core": "^1.3.
|
|
16
|
-
"@telia-ace/widget-utilities": "^1.3.
|
|
17
|
-
"@telia-ace/widget-services": "^1.3.
|
|
18
|
-
"@telia-ace/widget-core": "^1.3.
|
|
19
|
-
"@telia-ace/knowledge-data-client": "^1.3.
|
|
20
|
-
"@telia-ace/knowledge-widget-adapters": "^1.3.
|
|
21
|
-
"@telia-ace/knowledge-widget-ui": "^1.3.
|
|
22
|
-
"@telia-ace/widget-forms": "^1.3.
|
|
15
|
+
"@telia-ace/knowledge-widget-core": "^1.3.11-rc.1",
|
|
16
|
+
"@telia-ace/widget-utilities": "^1.3.11-rc.1",
|
|
17
|
+
"@telia-ace/widget-services": "^1.3.11-rc.1",
|
|
18
|
+
"@telia-ace/widget-core": "^1.3.11-rc.1",
|
|
19
|
+
"@telia-ace/knowledge-data-client": "^1.3.11-rc.1",
|
|
20
|
+
"@telia-ace/knowledge-widget-adapters": "^1.3.11-rc.1",
|
|
21
|
+
"@telia-ace/knowledge-widget-ui": "^1.3.11-rc.1",
|
|
22
|
+
"@telia-ace/widget-forms": "^1.3.11-rc.1"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@emotion/react": "11.11.1",
|
package/types.d.ts
CHANGED
|
@@ -26,7 +26,8 @@ export type TransferPayload = {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
export declare enum CustomMessageTypes {
|
|
29
|
-
ContactMethod = "ace-conversational-hub-contact-method"
|
|
29
|
+
ContactMethod = "ace-conversational-hub-contact-method",
|
|
30
|
+
ContactList = "ace-conversational-hub-contact-list"
|
|
30
31
|
}
|
|
31
32
|
export type LooseObject = {
|
|
32
33
|
[key: string]: any;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ActionItem } from '../types';
|
|
3
|
+
type Props = {
|
|
4
|
+
actions: ActionItem[];
|
|
5
|
+
contactMethodIds?: string[];
|
|
6
|
+
entryId: string;
|
|
7
|
+
groupId: string;
|
|
8
|
+
};
|
|
9
|
+
declare const ContactMethodList: React.FC<Props>;
|
|
10
|
+
export default ContactMethodList;
|
package/utils.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ContactMethodType } from '@telia-ace/knowledge-widget-adapters';
|
|
2
|
+
import { ConversationMessageListItemType } from '@telia-ace/widget-conversation';
|
|
2
3
|
import { Container } from '@webprovisions/platform';
|
|
3
4
|
import { ComponentNodeController } from '@telia-ace/widget-core';
|
|
4
|
-
import { MessageGroup, MessageGroupItem } from './types';
|
|
5
|
+
import { CustomMessageTypes, MessageGroup, MessageGroupItem, ServerEntry } from './types';
|
|
5
6
|
export declare const createGroup: ({ isUser, items, meta, }: {
|
|
6
7
|
isUser: boolean;
|
|
7
8
|
items?: Partial<MessageGroupItem>[] | undefined;
|
|
@@ -9,6 +10,11 @@ export declare const createGroup: ({ isUser, items, meta, }: {
|
|
|
9
10
|
[key: string]: any;
|
|
10
11
|
} | undefined;
|
|
11
12
|
}) => MessageGroup;
|
|
13
|
+
export declare const contactMethodFromLegacy: ({ id, title, defaultIcon, exits: [exit], exitType, confirmationText, expandFormAutomatically, form, description, }: any, options?: {
|
|
14
|
+
validation?: any;
|
|
15
|
+
guideId?: string;
|
|
16
|
+
}) => any;
|
|
17
|
+
export declare const getListType: (entry: ServerEntry) => ConversationMessageListItemType.LinkList | ConversationMessageListItemType.ButtonList | ConversationMessageListItemType.ItemList | CustomMessageTypes.ContactList;
|
|
12
18
|
export declare const getKnowledgeBotEndpoint: (container: Container, component: ComponentNodeController) => string;
|
|
13
19
|
export declare const updateForm: (contactMethod: ContactMethodType, { submit, errors, meta, }: {
|
|
14
20
|
submit: string;
|
package/index-02b60805.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var D=Object.defineProperty;var z=(i,t,n)=>t in i?D(i,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[t]=n;var y=(i,t,n)=>(z(i,typeof t!="symbol"?t+"":t,n),n);const O=require("@telia-ace/widget-conversation"),x=require("@telia-ace/widget-services"),S=require("@telia-ace/widget-utilities"),B=require("@telia-ace/widget-forms");class F{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 n;switch(t){case"localState":n=this.botProviderLocalStateKey;break;case"globalState":n=this.botProviderGlobalStateKey;break;case"entries":n=this.botProviderEntriesKey;break;case"meta":n=this.botProviderMetaStateKey;break}return n}async read(t){const n=this.getKey(t);if(!(!this.enabled||!n))return x.readStorage(this.container,n)}async write(t,n){const e=this.getKey(n);if(!this.enabled||!e)return;(await x.createStorageWriter(this.container,e,x.StorageCategory.Necessary))(t)}}var T=(i=>(i.ContactMethod="ace-conversational-hub-contact-method",i))(T||{});const W=({isUser:i,items:t=[],meta:n={}})=>{const e=S.uuid();return{id:e,isUser:i,items:t.map(d=>({id:d.id||S.uuid(),isUser:i,groupId:e,message:d.message||[]})),meta:n}},Q=(i,{submit:t,errors:n,meta:e})=>{var a;if((a=i==null?void 0:i.body)!=null&&a.form){const{body:d}=i,u=new B.FormBuilder(d.form);return d.form.layout.submit||u.createComponent(B.submitButton(t,"submit")),n&&u.setValidationErrors(n),e&&u.setMeta(e),{...d,form:u.get()}}return(i==null?void 0:i.body)||{}},X=async(i,t,n)=>{(await(await i.getAsync("dataClient")).getClient()).parameters.set(t,n)},N=({messageId:i,message:t,group:n})=>({id:i,message:t,groupId:n.id,isUser:n.isUser}),Y=async(i,t,n)=>{const e=async(o,h,f=[],P)=>{var A,k;const m=S.uuid();switch(o.type!=="List"&&o.tags.includes("guide")&&((k=(A=o.content.hints)==null?void 0:A[0])!=null&&k.id)&&await X(i,"LastGuideId",o.content.hints[0].id),o.type){case"Text":{const C=[];if(C.push(N({messageId:m,message:[O.ConversationMessageListItemType.HTML,{body:o.content.html}],group:h})),f.length){f.find(b=>{var K;return b.type==="List"&&((K=b.localState)==null?void 0:K.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"});const I=f.find(b=>b.tags.includes("contact")&&b.type==="Contact");I&&C.push(N({messageId:m,message:[T.ContactMethod,{contactMethodId:I.content.id,groupId:h.id,guideId:I.content.guideId}],group:h}))}return C}case"Contact":return[N({messageId:m,message:[T.ContactMethod,{contactMethodId:o.content.id,groupId:h.id,guideId:o.content.guideId}],group:h})];case"Error":return[N({messageId:m,message:[O.ConversationMessageListItemType.HTML,{body:o.content.message||"Something went wrong."}],group:h})];default:return[]}},a=new Map([["Text",1],["Contact",2]]),d=[],u=t.sort((o,h)=>{const P=a.get(o.type)||20,m=a.get(h.type)||20;return P-m}).filter(o=>!o.relation).reduce((o,h)=>o.concat(h),[]),$=o=>typeof o.actions.selector<"u";for(const o of u){const h=t.filter(m=>m.relation===o.id&&!$(m)),f=W({isUser:!1});(await e(o,f,h)).forEach(m=>{f.items.push(m)}),f.items.length&&d.push(f)}return d};class Z{constructor(t,n,e,a){y(this,"globalState");y(this,"localState");y(this,"clientId");y(this,"entries");this.endpoint=t,this.events=n,this.store=e,this.container=a,this.clientId=S.uuid(),this.entries=[]}async fetchGuide(t){const n={command:{guide:{id:t}},globalState:this.globalState,clientId:this.clientId};return await this.postEnvelope(n)}async postEnvelope(t,n){try{const e=await fetch(this.endpoint,this.getHttpOptions(t));if(!e.ok)throw e;const a=await e.json();return this.handleResponse(a,n)}catch(e){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let a="Something went wrong";return(e.message==="Failed to fetch"||e.message==="NetworkError when attempting to fetch resource.")&&(a="Lost connection... Please try again."),this.handleResponse({entries:[{id:S.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:a},actions:{},tags:[]}]})}}async handleResponse(t,n){this.entries=this.entries.concat(t.entries),this.store.write(this.entries,"entries");const e=t.entries.find(d=>d.type==="Widget");return e&&this.events.dispatch("provider:widget-entry",e.content),t.globalState&&(this.globalState=t.globalState,this.store.write(t.globalState,"globalState")),this.localState=t.entries.reduce((d,u)=>u.localState?u.localState:d,void 0),this.store.write(this.localState,"localState"),await Y(this.container,t.entries)}getHttpOptions(t){const n={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({},n,{body:JSON.stringify(t),credentials:"same-origin"})}}const ee="@telia-ace/conversational-hub-bot-provider",te="0.0.16",ne="./index.js",ie="./index.d.ts",oe={".":{import:"./index.mjs",require:"./index.js"}},se={"@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":"*"},re={"@emotion/react":"11.11.1","@emotion/styled":"11.11.0",react:"18.2.0"},E={name:ee,version:te,main:ne,types:ie,exports:oe,dependencies:se,peerDependencies:re},ae=async i=>{var G,H,j,_,U;const t="chub-plugin",n=i.get("$widget"),e=(U=(_=(j=(H=(G=n==null?void 0:n.container)==null?void 0:G.get("$settings"))==null?void 0:H.components)==null?void 0:j.conversation)==null?void 0:_.properties)==null?void 0:U.conversationalHubPluginSettings;let a,d,u,$=(e==null?void 0:e.connectionAttempts)??5,o,h,f;S.Logger.info((E==null?void 0:E.name)+" version: "+(E==null?void 0:E.version)),O.registerCustomMessageComponent(i,T.ContactMethod,Promise.resolve().then(()=>require("./contact-method-b3890fe6.js")));const P=await x.createStorageWriter(i,"conversational-hub-session",x.StorageCategory.Necessary),m=(r,c)=>{const{knowledgeBotEndpoint:l}=c.properties();if(l)return`${l}/conversations`;const{data:g}=r.get("$settings");if(!g||!g.projection)throw new Error("Missing Knowledge Bot endpoint");return`${g.projection}/conversations`};(await O.ConversationPlatform.getInstance(i)).registerProvider(t,(r,c)=>{a=r,d=a.controller,u=a.createAgent({name:e==null?void 0:e.botName,avatar:e==null?void 0:e.avatar}),f=m(i,c);const{events:l}=i.get("$widget"),g=new F(i);h=new Z(f,l,g,i),k();const p=()=>d.providers.includes(t);window.controller=d,c.actions.create("submit",s=>{const{events:v}=i.get("$widget");v.dispatch("conversational-hub-provider:form-submitted",s)}),c.actions.watch("conversation.action",(s,v)=>(p()&&C(s),v(s))),c.actions.watch("conversation.user-submit",(s,v)=>{if(!p())return v(s);I(s.text),a.user.print(s.text.replace(/</g,"<").replace(/>/g,">"))})});async function k(r=!0){const c=await x.readStorage(i,"conversational-hub-session");c!=null&&c.sessionId&&r?o=c==null?void 0:c.sessionId:e!=null&&e.welcomeMessage?u.print(e==null?void 0:e.welcomeMessage):await b(e.baseUrl+"/initialize",`{"extension": "${e.extension}"}`,r)}async function C(r){await b(`${e.baseUrl}/input/${o}`,`{"type":"button_click","language":"${e.language}","content":{"button_text":"${r.label}","value":"${r.actionKey}"}}`)}async function I(r){const c={text:r};o||await b(e.baseUrl+"/initialize",`{"extension": "${e.extension}"}`,!1),await b(`${e.baseUrl}/input/${o}`,`{"type":"text","language":"${e.language}","content":${JSON.stringify(c)}}`)}async function b(r,c,l=!0){var v,L,V,q;const g=a.loading();let p,s;try{p=await fetch(r,{method:"POST",body:c}),s=await(p==null?void 0:p.json())}catch(M){M instanceof SyntaxError?S.Logger.error("Incorrect JSON format.",M):S.Logger.error("Network error: check connection or baseUrl.",M),g(),u.print(e.errorMessage||"An error occurred");return}if(!(p!=null&&p.ok)){if(S.Logger.error(`HTTP ${p==null?void 0:p.status}.`,JSON.stringify(s)),g(),!!((v=s==null?void 0:s.errors)!=null&&v.filter(w=>w.code==="1003").length)&&$>0){$--,await new Promise(R=>setTimeout(R,500)),await k(!1);const w=JSON.parse(c);(L=w==null?void 0:w.content)!=null&&L.text?await I(w.content.text):(V=w==null?void 0:w.content)!=null&&V.action&&await C((q=w==null?void 0:w.content)==null?void 0:q.action)}else u.print(e.errorMessage||"An error occurred");return}g(),$=(e==null?void 0:e.connectionAttempts)??5,s!=null&&s.action_payload&&K(s.action_payload),o=s==null?void 0:s.session_id,P({sessionId:o}),l&&J(s)}async function K(r){var p;const c=(p=r==null?void 0:r.transfer_parameters)==null?void 0:p.contactGuide,l=a.loading(),g=await h.fetchGuide(parseInt(c));if(l(),g){const s=g.concat(g);if(s.length){const v=s[0].items.map(L=>L.message);u.print(v)}}}function J(r){var c;r==null||r.agent_response.forEach(l=>{u.print(l.payload.text)}),(c=r==null?void 0:r.prompt)!=null&&c.items&&u.print(["button-list",{actions:r.prompt.items.map(l=>{let g;return l.type==="button"&&(g={actionKey:l.value,label:l.text}),l.type==="link"&&(g={actionKey:l.value,label:l.text,data:{href:l.url,target:(e==null?void 0:e.linkTarget)??"_blank"}}),g})}])}};exports.ConversationalHubPlugin=ae;exports.updateForm=Q;
|
package/index-735998e7.mjs
DELETED
|
@@ -1,421 +0,0 @@
|
|
|
1
|
-
var q = Object.defineProperty;
|
|
2
|
-
var F = (i, e, n) => e in i ? q(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n;
|
|
3
|
-
var y = (i, e, n) => (F(i, typeof e != "symbol" ? e + "" : e, n), n);
|
|
4
|
-
import { ConversationMessageListItemType as B, registerCustomMessageComponent as Q, ConversationPlatform as X } from "@telia-ace/widget-conversation";
|
|
5
|
-
import { readStorage as J, createStorageWriter as R, StorageCategory as D } from "@telia-ace/widget-services";
|
|
6
|
-
import { uuid as P, Logger as O } from "@telia-ace/widget-utilities";
|
|
7
|
-
import { FormBuilder as Y, submitButton as Z } from "@telia-ace/widget-forms";
|
|
8
|
-
class tt {
|
|
9
|
-
constructor(e) {
|
|
10
|
-
y(this, "enabled", !0);
|
|
11
|
-
// set whether or not to store data
|
|
12
|
-
y(this, "botProviderGlobalStateKey", "bot-provider-global-state");
|
|
13
|
-
y(this, "botProviderLocalStateKey", "bot-provider-local-state");
|
|
14
|
-
y(this, "botProviderEntriesKey", "bot-provider-entries");
|
|
15
|
-
y(this, "botProviderMetaStateKey", "bot-provider-conversation-meta");
|
|
16
|
-
this.container = e;
|
|
17
|
-
}
|
|
18
|
-
getKey(e) {
|
|
19
|
-
let n;
|
|
20
|
-
switch (e) {
|
|
21
|
-
case "localState":
|
|
22
|
-
n = this.botProviderLocalStateKey;
|
|
23
|
-
break;
|
|
24
|
-
case "globalState":
|
|
25
|
-
n = this.botProviderGlobalStateKey;
|
|
26
|
-
break;
|
|
27
|
-
case "entries":
|
|
28
|
-
n = this.botProviderEntriesKey;
|
|
29
|
-
break;
|
|
30
|
-
case "meta":
|
|
31
|
-
n = this.botProviderMetaStateKey;
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
return n;
|
|
35
|
-
}
|
|
36
|
-
async read(e) {
|
|
37
|
-
const n = this.getKey(e);
|
|
38
|
-
if (!(!this.enabled || !n))
|
|
39
|
-
return J(this.container, n);
|
|
40
|
-
}
|
|
41
|
-
async write(e, n) {
|
|
42
|
-
const t = this.getKey(n);
|
|
43
|
-
if (!this.enabled || !t)
|
|
44
|
-
return;
|
|
45
|
-
(await R(
|
|
46
|
-
this.container,
|
|
47
|
-
t,
|
|
48
|
-
D.Necessary
|
|
49
|
-
))(e);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
var T = /* @__PURE__ */ ((i) => (i.ContactMethod = "ace-conversational-hub-contact-method", i))(T || {});
|
|
53
|
-
const et = ({
|
|
54
|
-
isUser: i,
|
|
55
|
-
items: e = [],
|
|
56
|
-
meta: n = {}
|
|
57
|
-
}) => {
|
|
58
|
-
const t = P();
|
|
59
|
-
return {
|
|
60
|
-
id: t,
|
|
61
|
-
isUser: i,
|
|
62
|
-
items: e.map((d) => ({
|
|
63
|
-
id: d.id || P(),
|
|
64
|
-
isUser: i,
|
|
65
|
-
groupId: t,
|
|
66
|
-
message: d.message || []
|
|
67
|
-
})),
|
|
68
|
-
meta: n
|
|
69
|
-
};
|
|
70
|
-
}, wt = (i, {
|
|
71
|
-
submit: e,
|
|
72
|
-
errors: n,
|
|
73
|
-
meta: t
|
|
74
|
-
}) => {
|
|
75
|
-
var a;
|
|
76
|
-
if ((a = i == null ? void 0 : i.body) != null && a.form) {
|
|
77
|
-
const { body: d } = i, u = new Y(d.form);
|
|
78
|
-
return d.form.layout.submit || u.createComponent(Z(e, "submit")), n && u.setValidationErrors(n), t && u.setMeta(t), {
|
|
79
|
-
...d,
|
|
80
|
-
form: u.get()
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
return (i == null ? void 0 : i.body) || {};
|
|
84
|
-
}, nt = async (i, e, n) => {
|
|
85
|
-
(await (await i.getAsync("dataClient")).getClient()).parameters.set(e, n);
|
|
86
|
-
}, M = ({
|
|
87
|
-
messageId: i,
|
|
88
|
-
message: e,
|
|
89
|
-
group: n
|
|
90
|
-
}) => ({
|
|
91
|
-
id: i,
|
|
92
|
-
message: e,
|
|
93
|
-
groupId: n.id,
|
|
94
|
-
isUser: n.isUser
|
|
95
|
-
}), it = async (i, e, n) => {
|
|
96
|
-
const t = async (o, h, f = [], E) => {
|
|
97
|
-
var A, $;
|
|
98
|
-
const m = P();
|
|
99
|
-
switch (o.type !== "List" && o.tags.includes("guide") && (($ = (A = o.content.hints) == null ? void 0 : A[0]) != null && $.id) && await nt(
|
|
100
|
-
i,
|
|
101
|
-
"LastGuideId",
|
|
102
|
-
o.content.hints[0].id
|
|
103
|
-
), o.type) {
|
|
104
|
-
case "Text": {
|
|
105
|
-
const S = [];
|
|
106
|
-
if (S.push(
|
|
107
|
-
M({
|
|
108
|
-
messageId: m,
|
|
109
|
-
message: [
|
|
110
|
-
B.HTML,
|
|
111
|
-
{ body: o.content.html }
|
|
112
|
-
],
|
|
113
|
-
group: h
|
|
114
|
-
})
|
|
115
|
-
), f.length) {
|
|
116
|
-
f.find(
|
|
117
|
-
(v) => {
|
|
118
|
-
var k;
|
|
119
|
-
return v.type === "List" && ((k = v.localState) == null ? void 0 : k.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching";
|
|
120
|
-
}
|
|
121
|
-
);
|
|
122
|
-
const I = f.find(
|
|
123
|
-
(v) => v.tags.includes("contact") && v.type === "Contact"
|
|
124
|
-
);
|
|
125
|
-
I && S.push(
|
|
126
|
-
M({
|
|
127
|
-
messageId: m,
|
|
128
|
-
message: [
|
|
129
|
-
T.ContactMethod,
|
|
130
|
-
{
|
|
131
|
-
contactMethodId: I.content.id,
|
|
132
|
-
groupId: h.id,
|
|
133
|
-
guideId: I.content.guideId
|
|
134
|
-
}
|
|
135
|
-
],
|
|
136
|
-
group: h
|
|
137
|
-
})
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
return S;
|
|
141
|
-
}
|
|
142
|
-
case "Contact":
|
|
143
|
-
return [
|
|
144
|
-
M({
|
|
145
|
-
messageId: m,
|
|
146
|
-
message: [
|
|
147
|
-
T.ContactMethod,
|
|
148
|
-
{
|
|
149
|
-
contactMethodId: o.content.id,
|
|
150
|
-
groupId: h.id,
|
|
151
|
-
guideId: o.content.guideId
|
|
152
|
-
}
|
|
153
|
-
],
|
|
154
|
-
group: h
|
|
155
|
-
})
|
|
156
|
-
];
|
|
157
|
-
case "Error":
|
|
158
|
-
return [
|
|
159
|
-
M({
|
|
160
|
-
messageId: m,
|
|
161
|
-
message: [
|
|
162
|
-
B.HTML,
|
|
163
|
-
{
|
|
164
|
-
body: o.content.message || "Something went wrong."
|
|
165
|
-
}
|
|
166
|
-
],
|
|
167
|
-
group: h
|
|
168
|
-
})
|
|
169
|
-
];
|
|
170
|
-
default:
|
|
171
|
-
return [];
|
|
172
|
-
}
|
|
173
|
-
}, a = /* @__PURE__ */ new Map([
|
|
174
|
-
["Text", 1],
|
|
175
|
-
["Contact", 2]
|
|
176
|
-
]), d = [], u = e.sort((o, h) => {
|
|
177
|
-
const E = a.get(o.type) || 20, m = a.get(h.type) || 20;
|
|
178
|
-
return E - m;
|
|
179
|
-
}).filter((o) => !o.relation).reduce((o, h) => o.concat(h), []), x = (o) => typeof o.actions.selector < "u";
|
|
180
|
-
for (const o of u) {
|
|
181
|
-
const h = e.filter(
|
|
182
|
-
(m) => m.relation === o.id && !x(m)
|
|
183
|
-
), f = et({ isUser: !1 });
|
|
184
|
-
(await t(o, f, h)).forEach((m) => {
|
|
185
|
-
f.items.push(m);
|
|
186
|
-
}), f.items.length && d.push(f);
|
|
187
|
-
}
|
|
188
|
-
return d;
|
|
189
|
-
};
|
|
190
|
-
class ot {
|
|
191
|
-
constructor(e, n, t, a) {
|
|
192
|
-
y(this, "globalState");
|
|
193
|
-
y(this, "localState");
|
|
194
|
-
y(this, "clientId");
|
|
195
|
-
y(this, "entries");
|
|
196
|
-
this.endpoint = e, this.events = n, this.store = t, this.container = a, this.clientId = P(), this.entries = [];
|
|
197
|
-
}
|
|
198
|
-
async fetchGuide(e) {
|
|
199
|
-
const n = {
|
|
200
|
-
command: { guide: { id: e } },
|
|
201
|
-
globalState: this.globalState,
|
|
202
|
-
clientId: this.clientId
|
|
203
|
-
};
|
|
204
|
-
return await this.postEnvelope(n);
|
|
205
|
-
}
|
|
206
|
-
async postEnvelope(e, n) {
|
|
207
|
-
try {
|
|
208
|
-
const t = await fetch(
|
|
209
|
-
this.endpoint,
|
|
210
|
-
this.getHttpOptions(e)
|
|
211
|
-
);
|
|
212
|
-
if (!t.ok)
|
|
213
|
-
throw t;
|
|
214
|
-
const a = await t.json();
|
|
215
|
-
return this.handleResponse(a, n);
|
|
216
|
-
} catch (t) {
|
|
217
|
-
process.env.NODE_ENV !== "production" && console.warn("Something went wrong when posting the envelope.");
|
|
218
|
-
let a = "Something went wrong";
|
|
219
|
-
return (t.message === "Failed to fetch" || t.message === "NetworkError when attempting to fetch resource.") && (a = "Lost connection... Please try again."), this.handleResponse({
|
|
220
|
-
entries: [
|
|
221
|
-
{
|
|
222
|
-
id: P(),
|
|
223
|
-
type: "Error",
|
|
224
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
225
|
-
content: {
|
|
226
|
-
message: a
|
|
227
|
-
},
|
|
228
|
-
actions: {},
|
|
229
|
-
tags: []
|
|
230
|
-
}
|
|
231
|
-
]
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
async handleResponse(e, n) {
|
|
236
|
-
this.entries = this.entries.concat(e.entries), this.store.write(this.entries, "entries");
|
|
237
|
-
const t = e.entries.find((d) => d.type === "Widget");
|
|
238
|
-
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(
|
|
239
|
-
(d, u) => u.localState ? u.localState : d,
|
|
240
|
-
void 0
|
|
241
|
-
), this.store.write(this.localState, "localState"), await it(
|
|
242
|
-
this.container,
|
|
243
|
-
e.entries
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
getHttpOptions(e) {
|
|
247
|
-
const n = {
|
|
248
|
-
method: "POST",
|
|
249
|
-
headers: {
|
|
250
|
-
Accept: "application/json",
|
|
251
|
-
"Content-Type": "application/json"
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
return e.funnel = this.container.get("$widget").name, e.localState = e.localState || this.localState, Object.assign({}, n, {
|
|
255
|
-
body: JSON.stringify(e),
|
|
256
|
-
credentials: "same-origin"
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
const st = "@telia-ace/conversational-hub-bot-provider", rt = "0.0.16", at = "./index.js", ct = "./index.d.ts", lt = {
|
|
261
|
-
".": {
|
|
262
|
-
import: "./index.mjs",
|
|
263
|
-
require: "./index.js"
|
|
264
|
-
}
|
|
265
|
-
}, dt = {
|
|
266
|
-
"@telia-ace/widget-conversation": "*",
|
|
267
|
-
"@webprovisions/platform": "^1.1.4",
|
|
268
|
-
"@telia-ace/knowledge-widget-core": "*",
|
|
269
|
-
"@telia-ace/widget-utilities": "*",
|
|
270
|
-
"@telia-ace/widget-services": "*",
|
|
271
|
-
"@telia-ace/widget-core": "*",
|
|
272
|
-
"@telia-ace/knowledge-data-client": "*",
|
|
273
|
-
"@telia-ace/knowledge-widget-adapters": "*",
|
|
274
|
-
"@telia-ace/knowledge-widget-ui": "*",
|
|
275
|
-
"@telia-ace/widget-forms": "*"
|
|
276
|
-
}, ut = {
|
|
277
|
-
"@emotion/react": "11.11.1",
|
|
278
|
-
"@emotion/styled": "11.11.0",
|
|
279
|
-
react: "18.2.0"
|
|
280
|
-
}, C = {
|
|
281
|
-
name: st,
|
|
282
|
-
version: rt,
|
|
283
|
-
main: at,
|
|
284
|
-
types: ct,
|
|
285
|
-
exports: lt,
|
|
286
|
-
dependencies: dt,
|
|
287
|
-
peerDependencies: ut
|
|
288
|
-
}, bt = async (i) => {
|
|
289
|
-
var G, j, H, L, _;
|
|
290
|
-
const e = "chub-plugin", n = i.get("$widget"), t = (_ = (L = (H = (j = (G = n == null ? void 0 : n.container) == null ? void 0 : G.get("$settings")) == null ? void 0 : j.components) == null ? void 0 : H.conversation) == null ? void 0 : L.properties) == null ? void 0 : _.conversationalHubPluginSettings;
|
|
291
|
-
let a, d, u, x = (t == null ? void 0 : t.connectionAttempts) ?? 5, o, h, f;
|
|
292
|
-
O.info((C == null ? void 0 : C.name) + " version: " + (C == null ? void 0 : C.version)), Q(
|
|
293
|
-
i,
|
|
294
|
-
T.ContactMethod,
|
|
295
|
-
import("./contact-method-65f71f64.mjs")
|
|
296
|
-
);
|
|
297
|
-
const E = await R(
|
|
298
|
-
i,
|
|
299
|
-
"conversational-hub-session",
|
|
300
|
-
D.Necessary
|
|
301
|
-
), m = (r, c) => {
|
|
302
|
-
const { knowledgeBotEndpoint: l } = c.properties();
|
|
303
|
-
if (l)
|
|
304
|
-
return `${l}/conversations`;
|
|
305
|
-
const { data: g } = r.get("$settings");
|
|
306
|
-
if (!g || !g.projection)
|
|
307
|
-
throw new Error("Missing Knowledge Bot endpoint");
|
|
308
|
-
return `${g.projection}/conversations`;
|
|
309
|
-
};
|
|
310
|
-
(await X.getInstance(
|
|
311
|
-
i
|
|
312
|
-
)).registerProvider(e, (r, c) => {
|
|
313
|
-
a = r, d = a.controller, u = a.createAgent({
|
|
314
|
-
name: t == null ? void 0 : t.botName,
|
|
315
|
-
avatar: t == null ? void 0 : t.avatar
|
|
316
|
-
}), f = m(i, c);
|
|
317
|
-
const { events: l } = i.get("$widget"), g = new tt(i);
|
|
318
|
-
h = new ot(f, l, g, i), $();
|
|
319
|
-
const p = () => d.providers.includes(e);
|
|
320
|
-
window.controller = d, c.actions.create("submit", (s) => {
|
|
321
|
-
const { events: b } = i.get("$widget");
|
|
322
|
-
b.dispatch("conversational-hub-provider:form-submitted", s);
|
|
323
|
-
}), c.actions.watch("conversation.action", (s, b) => (p() && S(s), b(s))), c.actions.watch("conversation.user-submit", (s, b) => {
|
|
324
|
-
if (!p())
|
|
325
|
-
return b(s);
|
|
326
|
-
I(s.text), a.user.print(
|
|
327
|
-
s.text.replace(/</g, "<").replace(/>/g, ">")
|
|
328
|
-
);
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
async function $(r = !0) {
|
|
332
|
-
const c = await J(
|
|
333
|
-
i,
|
|
334
|
-
"conversational-hub-session"
|
|
335
|
-
);
|
|
336
|
-
c != null && c.sessionId && r ? o = c == null ? void 0 : c.sessionId : t != null && t.welcomeMessage ? u.print(t == null ? void 0 : t.welcomeMessage) : await v(
|
|
337
|
-
t.baseUrl + "/initialize",
|
|
338
|
-
`{"extension": "${t.extension}"}`,
|
|
339
|
-
r
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
async function S(r) {
|
|
343
|
-
await v(
|
|
344
|
-
`${t.baseUrl}/input/${o}`,
|
|
345
|
-
`{"type":"button_click","language":"${t.language}","content":{"button_text":"${r.label}","value":"${r.actionKey}"}}`
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
async function I(r) {
|
|
349
|
-
const c = { text: r };
|
|
350
|
-
o || await v(
|
|
351
|
-
t.baseUrl + "/initialize",
|
|
352
|
-
`{"extension": "${t.extension}"}`,
|
|
353
|
-
!1
|
|
354
|
-
), await v(
|
|
355
|
-
`${t.baseUrl}/input/${o}`,
|
|
356
|
-
`{"type":"text","language":"${t.language}","content":${JSON.stringify(c)}}`
|
|
357
|
-
);
|
|
358
|
-
}
|
|
359
|
-
async function v(r, c, l = !0) {
|
|
360
|
-
var b, K, V, U;
|
|
361
|
-
const g = a.loading();
|
|
362
|
-
let p, s;
|
|
363
|
-
try {
|
|
364
|
-
p = await fetch(r, {
|
|
365
|
-
method: "POST",
|
|
366
|
-
body: c
|
|
367
|
-
}), s = await (p == null ? void 0 : p.json());
|
|
368
|
-
} catch (N) {
|
|
369
|
-
N instanceof SyntaxError ? O.error("Incorrect JSON format.", N) : O.error("Network error: check connection or baseUrl.", N), g(), u.print(t.errorMessage || "An error occurred");
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
if (!(p != null && p.ok)) {
|
|
373
|
-
if (O.error(`HTTP ${p == null ? void 0 : p.status}.`, JSON.stringify(s)), g(), !!((b = s == null ? void 0 : s.errors) != null && b.filter(
|
|
374
|
-
(w) => w.code === "1003"
|
|
375
|
-
).length) && x > 0) {
|
|
376
|
-
x--, await new Promise((W) => setTimeout(W, 500)), await $(!1);
|
|
377
|
-
const w = JSON.parse(c);
|
|
378
|
-
(K = w == null ? void 0 : w.content) != null && K.text ? await I(w.content.text) : (V = w == null ? void 0 : w.content) != null && V.action && await S((U = w == null ? void 0 : w.content) == null ? void 0 : U.action);
|
|
379
|
-
} else
|
|
380
|
-
u.print(t.errorMessage || "An error occurred");
|
|
381
|
-
return;
|
|
382
|
-
}
|
|
383
|
-
g(), x = (t == null ? void 0 : t.connectionAttempts) ?? 5, s != null && s.action_payload && k(s.action_payload), o = s == null ? void 0 : s.session_id, E({ sessionId: o }), l && z(s);
|
|
384
|
-
}
|
|
385
|
-
async function k(r) {
|
|
386
|
-
var p;
|
|
387
|
-
const c = (p = r == null ? void 0 : r.transfer_parameters) == null ? void 0 : p.contactGuide, l = a.loading(), g = await h.fetchGuide(parseInt(c));
|
|
388
|
-
if (l(), g) {
|
|
389
|
-
const s = g.concat(g);
|
|
390
|
-
if (s.length) {
|
|
391
|
-
const b = s[0].items.map((K) => K.message);
|
|
392
|
-
u.print(b);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
function z(r) {
|
|
397
|
-
var c;
|
|
398
|
-
r == null || r.agent_response.forEach((l) => {
|
|
399
|
-
u.print(l.payload.text);
|
|
400
|
-
}), (c = r == null ? void 0 : r.prompt) != null && c.items && u.print([
|
|
401
|
-
"button-list",
|
|
402
|
-
{
|
|
403
|
-
actions: r.prompt.items.map((l) => {
|
|
404
|
-
let g;
|
|
405
|
-
return l.type === "button" && (g = { actionKey: l.value, label: l.text }), l.type === "link" && (g = {
|
|
406
|
-
actionKey: l.value,
|
|
407
|
-
label: l.text,
|
|
408
|
-
data: {
|
|
409
|
-
href: l.url,
|
|
410
|
-
target: (t == null ? void 0 : t.linkTarget) ?? "_blank"
|
|
411
|
-
}
|
|
412
|
-
}), g;
|
|
413
|
-
})
|
|
414
|
-
}
|
|
415
|
-
]);
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
export {
|
|
419
|
-
bt as C,
|
|
420
|
-
wt as u
|
|
421
|
-
};
|