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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ import { useContainer as R, useDispatch as _, useConversation as G } from "@teli
6
6
  import { FormBuilder as I } from "@telia-ace/widget-forms";
7
7
  import { appendClassNames as O } from "@telia-ace/widget-utilities";
8
8
  import { useState as V, useRef as q, useEffect as $, useCallback as H } from "react";
9
- import { u as j } from "./index-BnOsK3l6.mjs";
9
+ import { u as j } from "./index-BC2Tv5_h.mjs";
10
10
  const et = ({
11
11
  contactMethodId: a,
12
12
  guideId: n,
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("react/jsx-runtime"),N=require("@emotion/styled"),F=require("@telia-ace/knowledge-data-client"),R=require("@telia-ace/knowledge-widget-adapters"),C=require("@telia-ace/knowledge-widget-ui"),$=require("@telia-ace/widget-forms"),z=require("@telia-ace/widget-utilities"),l=require("react"),x=require("./index-UFpIz4f_.js"),O=({contactMethodId:a,guideId:n,groupId:b,className:T})=>{var h,k,q,S,j;const[e,d]=l.useState(),c=C.useContainer(),A=C.useDispatch(),f=l.useRef(!0),y=C.useConversation();l.useEffect(()=>{const{events:t}=c.get("$widget"),m=t.subscribe("bot-provider:form-submitted",async(i,o)=>{var D;if(((D=o.form.meta)==null?void 0:D.groupId)!==b||o.id!==e.id)return;y&&(o.form.meta||(o.form.meta={}),o.form.meta.conversation=y);const p=await c.getAsync("contactMethods"),r={...e,body:{...e.body,form:o.form}},{errors:u,valid:g,errorTypes:W}=await p.validate(r);if(!g){const E=new $.FormBuilder(e.body.form);d(void 0),E.setValidationErrors(u),r.body={...r.body,form:E.get()},d({...r});return}const B=await p.submit(r);r.confirmation=B,d(r)}),s=t.subscribe("bot-provider:evaluate",async(i,o)=>{if(String(o.id)!==String(a))return;const r=await(await c.getAsync("contactMethods")).evaluate(e);let u={...e,body:{...e.body,form:r}};const g=x.updateForm(u,{submit:"Skicka",errors:{},meta:{groupId:b}});u={...u,body:g},d(u)});return()=>{m(),s()}},[c,e,d,y]);const v=(t,m,s=null)=>{if(t["ui:component"]&&t["ui:component"]==="Date")return Object.assign(t,{"ui:bot":!0,"ui:entrance":m}),t;for(const i in t)if(typeof t[i]=="object"&&t[i]!==null){const o=v(t[i],m,t);if(o!==void 0)return o}},w=l.useCallback(async t=>{const s=await(await F.DataClient.getInstance(c)).fetch(F.DataType.ContactMethod,{contactMethodId:t,guideId:n},{noCache:!0,isBot:!0}),i=x.updateForm(s,{submit:"Skicka",errors:{},meta:{groupId:b}});if(s.body=i,s.body.guideId=n,!f.current)return null;d(s)},[f]);return l.useEffect(()=>(w(a),()=>{f.current=!1}),[a,w]),e?(e.clientName==="ace.callback"&&((h=e.body)!=null&&h.entrance)&&v(e,(k=e.body)==null?void 0:k.entrance),M.jsx(U,{...e,body:{...e.body,form:e.body.form?{...e.body.form,data:(q=e.body.form)==null?void 0:q.data,layout:{...e.body.form.layout},meta:(S=e.body.form)==null?void 0:S.meta,schema:(j=e.body.form)==null?void 0:j.schema}:void 0,guideId:e.body.guideId},inline:!0,expanded:!0,dispatch:A,className:z.appendClassNames("humany-bot-contact-method",T)})):null},U=N(R.ContactMethod)`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("react/jsx-runtime"),N=require("@emotion/styled"),F=require("@telia-ace/knowledge-data-client"),R=require("@telia-ace/knowledge-widget-adapters"),C=require("@telia-ace/knowledge-widget-ui"),$=require("@telia-ace/widget-forms"),z=require("@telia-ace/widget-utilities"),l=require("react"),x=require("./index-S0_42F-Y.js"),O=({contactMethodId:a,guideId:n,groupId:b,className:T})=>{var h,k,q,S,j;const[e,d]=l.useState(),c=C.useContainer(),A=C.useDispatch(),f=l.useRef(!0),y=C.useConversation();l.useEffect(()=>{const{events:t}=c.get("$widget"),m=t.subscribe("bot-provider:form-submitted",async(i,o)=>{var D;if(((D=o.form.meta)==null?void 0:D.groupId)!==b||o.id!==e.id)return;y&&(o.form.meta||(o.form.meta={}),o.form.meta.conversation=y);const p=await c.getAsync("contactMethods"),r={...e,body:{...e.body,form:o.form}},{errors:u,valid:g,errorTypes:W}=await p.validate(r);if(!g){const E=new $.FormBuilder(e.body.form);d(void 0),E.setValidationErrors(u),r.body={...r.body,form:E.get()},d({...r});return}const B=await p.submit(r);r.confirmation=B,d(r)}),s=t.subscribe("bot-provider:evaluate",async(i,o)=>{if(String(o.id)!==String(a))return;const r=await(await c.getAsync("contactMethods")).evaluate(e);let u={...e,body:{...e.body,form:r}};const g=x.updateForm(u,{submit:"Skicka",errors:{},meta:{groupId:b}});u={...u,body:g},d(u)});return()=>{m(),s()}},[c,e,d,y]);const v=(t,m,s=null)=>{if(t["ui:component"]&&t["ui:component"]==="Date")return Object.assign(t,{"ui:bot":!0,"ui:entrance":m}),t;for(const i in t)if(typeof t[i]=="object"&&t[i]!==null){const o=v(t[i],m,t);if(o!==void 0)return o}},w=l.useCallback(async t=>{const s=await(await F.DataClient.getInstance(c)).fetch(F.DataType.ContactMethod,{contactMethodId:t,guideId:n},{noCache:!0,isBot:!0}),i=x.updateForm(s,{submit:"Skicka",errors:{},meta:{groupId:b}});if(s.body=i,s.body.guideId=n,!f.current)return null;d(s)},[f]);return l.useEffect(()=>(w(a),()=>{f.current=!1}),[a,w]),e?(e.clientName==="ace.callback"&&((h=e.body)!=null&&h.entrance)&&v(e,(k=e.body)==null?void 0:k.entrance),M.jsx(U,{...e,body:{...e.body,form:e.body.form?{...e.body.form,data:(q=e.body.form)==null?void 0:q.data,layout:{...e.body.form.layout},meta:(S=e.body.form)==null?void 0:S.meta,schema:(j=e.body.form)==null?void 0:j.schema}:void 0,guideId:e.body.guideId},inline:!0,expanded:!0,dispatch:A,className:z.appendClassNames("humany-bot-contact-method",T)})):null},U=N(R.ContactMethod)`
2
2
  padding: ${a=>{var n;return(n=a.theme.sizes)==null?void 0:n.normal}} ${a=>{var n;return(n=a.theme.sizes)==null?void 0:n.medium}};
3
3
  `;exports.default=O;
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),u=require("@emotion/styled"),y=require("@telia-ace/knowledge-widget-adapters"),g=require("@telia-ace/knowledge-widget-ui"),l=require("react"),k=require("./contact-method-bGgHBWcr.js"),j=({actions:e,entryId:t,groupId:x})=>{const C=g.useDispatch(),o=g.useContainer(),[m,M]=l.useState([]),[c,b]=l.useState([]);return l.useEffect(()=>{o.getAsync("contactMethods").then(n=>{if(!n)return;const r=e.map(async i=>{var h;if(!((h=i.data)!=null&&h.clientName))return null;const s=await n.handleAdapters(i.data);return{...s,...i.data,description:i.data.description?i.data.description:s.description,onClick:(p,d)=>{if(typeof s.onClick=="function"&&s.onClick(p,d),!p.defaultPrevented)if(d.inline&&!d.expanded)b([...c,d.id]);else{const{events:f}=o.get("$widget");f.dispatch("provider:open-contact-method",{entryId:t,contactMethod:d,actionKey:i.actionKey}),f.dispatch("tracking:contact-method-list-item-clicked",d)}}}});Promise.all(r).then(i=>{M(i.filter(s=>!!s))})})},[e,o,t,c]),m.length?a.jsx(S,{className:"humany-bot-contact-list",contactMethods:m,dispatch:C,itemRenderer:(n,r)=>(c.includes(n.id)||n.expanded)&&n.inline||n.clientName==="custom.link"?a.jsx(q,{contactMethodId:n.id,groupId:x,guideId:n.body.guideId}):a.jsx($,{...n,...r})}):null},S=u(y.ContactList)`
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-BL0X7F1O.js"),j=({actions:e,entryId:t,groupId:x})=>{const C=g.useDispatch(),o=g.useContainer(),[m,M]=l.useState([]),[c,b]=l.useState([]);return l.useEffect(()=>{o.getAsync("contactMethods").then(n=>{if(!n)return;const r=e.map(async i=>{var h;if(!((h=i.data)!=null&&h.clientName))return null;const s=await n.handleAdapters(i.data);return{...s,...i.data,description:i.data.description?i.data.description:s.description,onClick:(p,d)=>{if(typeof s.onClick=="function"&&s.onClick(p,d),!p.defaultPrevented)if(d.inline&&!d.expanded)b([...c,d.id]);else{const{events:f}=o.get("$widget");f.dispatch("provider:open-contact-method",{entryId:t,contactMethod:d,actionKey:i.actionKey}),f.dispatch("tracking:contact-method-list-item-clicked",d)}}}});Promise.all(r).then(i=>{M(i.filter(s=>!!s))})})},[e,o,t,c]),m.length?a.jsx(S,{className:"humany-bot-contact-list",contactMethods:m,dispatch:C,itemRenderer:(n,r)=>(c.includes(n.id)||n.expanded)&&n.inline||n.clientName==="custom.link"?a.jsx(q,{contactMethodId:n.id,groupId:x,guideId:n.body.guideId}):a.jsx($,{...n,...r})}):null},S=u(y.ContactList)`
2
2
  > ul > li {
3
3
  a {
4
4
  display: flex;
@@ -3,7 +3,7 @@ import l from "@emotion/styled";
3
3
  import { ContactList as M, ContactMethod as $ } from "@telia-ace/knowledge-widget-adapters";
4
4
  import { useDispatch as b, useContainer as k } from "@telia-ace/knowledge-widget-ui";
5
5
  import { useState as f, useEffect as E } from "react";
6
- import S from "./contact-method-B2iMHgUU.mjs";
6
+ import S from "./contact-method-BBndyfJD.mjs";
7
7
  const P = ({ actions: t, entryId: e, groupId: y }) => {
8
8
  const g = b(), d = k(), [m, x] = f([]), [c, C] = f([]);
9
9
  return E(() => {
@@ -1,4 +1,3 @@
1
1
  import { Container } from '@webprovisions/platform';
2
2
  import { MessageGroup, ServerEntry } from './types';
3
-
4
3
  export declare const processEntries: (container: Container, entries: ServerEntry[], prevGroup?: MessageGroup) => Promise<MessageGroup[]>;
package/http-client.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Container, EventManager } from '@webprovisions/platform';
2
2
  import { default as Store } from './store';
3
3
  import { MessageGroup } from './types';
4
-
5
4
  declare class HttpClient {
6
5
  private endpoint;
7
6
  private events;
@@ -1,11 +1,11 @@
1
1
  var F = Object.defineProperty;
2
2
  var G = (s, t, e) => t in s ? F(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var f = (s, t, e) => G(s, typeof t != "symbol" ? t + "" : t, e);
3
+ var g = (s, t, e) => G(s, typeof t != "symbol" ? t + "" : t, e);
4
4
  import { ConversationMessageListItemType as v, ConversationPlatform as T, registerCustomMessageComponent as N } from "@telia-ace/widget-conversation";
5
5
  import { readStorage as U, createStorageWriter as P, StorageCategory as B } from "@telia-ace/widget-services";
6
6
  import { uuid as K } from "@telia-ace/widget-utilities";
7
7
  import { FormBuilder as A, submitButton as V } from "@telia-ace/widget-forms";
8
- var m = /* @__PURE__ */ ((s) => (s.ContactMethod = "ace-knowledge-bot-contact-method", s.ContactList = "ace-knowledge-bot-contact-list", s.FeedbackList = "ace-knowledge-bot-feedback-list", s.NotificationList = "ace-knowledge-bot-notification-list", s.NoGoodAlternative = "ace-knowledge-bot-no-good-alternative", s))(m || {});
8
+ var f = /* @__PURE__ */ ((s) => (s.ContactMethod = "ace-knowledge-bot-contact-method", s.ContactList = "ace-knowledge-bot-contact-list", s.FeedbackList = "ace-knowledge-bot-feedback-list", s.NotificationList = "ace-knowledge-bot-notification-list", s.NoGoodAlternative = "ace-knowledge-bot-no-good-alternative", s))(f || {});
9
9
  const j = (s) => {
10
10
  if (s) {
11
11
  const { type: t, content: e } = s;
@@ -37,7 +37,7 @@ const j = (s) => {
37
37
  exitType: i,
38
38
  confirmationText: a,
39
39
  expandFormAutomatically: r,
40
- form: g,
40
+ form: p,
41
41
  description: M
42
42
  }, w = {}) => {
43
43
  const { adapter: c } = n || {}, {
@@ -55,20 +55,20 @@ const j = (s) => {
55
55
  body: {}
56
56
  };
57
57
  if (o.indexOf("phone") > -1 || o.indexOf("freetext") > -1) {
58
- const { displayTextBeforeClick: L, textBeforeClick: u } = h;
59
- L === "true" && (d.expanded = !1, d.title = u), o.indexOf("phone.text") > -1 ? d.body.phoneNumber = h.phoneNumber : d.body.freetext = h.freetext;
58
+ const { displayTextBeforeClick: L, textBeforeClick: m } = h;
59
+ L === "true" && (d.expanded = !1, d.title = m), o.indexOf("phone.text") > -1 ? d.body.phoneNumber = h.phoneNumber : d.body.freetext = h.freetext;
60
60
  }
61
- return (o.indexOf("chat.popup") > -1 || o.indexOf("link") > -1 || o === "custom.adapter" && i === "custom") && (d.body = h, d.body.confirmationFallback = a), o.indexOf("ace") > -1 && (d.body = h), g && g.hasValueComponents && (l ? d.body.form = A.fromLegacyForm(
61
+ return (o.indexOf("chat.popup") > -1 || o.indexOf("link") > -1 || o === "custom.adapter" && i === "custom") && (d.body = h, d.body.confirmationFallback = a), o.indexOf("ace") > -1 && (d.body = h), p && p.hasValueComponents && (l ? d.body.form = A.fromLegacyForm(
62
62
  s.toString(),
63
- g,
63
+ p,
64
64
  l
65
65
  ).get() : d.body.form = A.fromLegacyForm(
66
66
  s.toString(),
67
- g
67
+ p
68
68
  ).get(), r || (d.expanded = d.inline = !1), d.body = D(d, { submit: "Submit" })), w.guideId && (d.body.guideId = w.guideId), d;
69
69
  }, W = (s) => {
70
70
  const { localState: t } = s;
71
- return s.tags.includes("category") && s.tags.includes("contact") ? v.ItemList : s.tags.includes("suggestion") ? v.LinkList : (t == null ? void 0 : t.$type) === "Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching" ? v.LinkList : (t == null ? void 0 : t.$type) === "Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching" ? m.FeedbackList : (t == null ? void 0 : t.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching" ? m.ContactList : v.ButtonList;
71
+ return s.tags.includes("category") && s.tags.includes("contact") ? v.ItemList : s.tags.includes("suggestion") ? v.LinkList : (t == null ? void 0 : t.$type) === "Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching" ? v.LinkList : (t == null ? void 0 : t.$type) === "Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching" ? f.FeedbackList : (t == null ? void 0 : t.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching" ? f.ContactList : v.ButtonList;
72
72
  }, _ = (s, t) => {
73
73
  const { knowledgeBotEndpoint: e } = t.properties();
74
74
  if (e)
@@ -110,7 +110,7 @@ const j = (s) => {
110
110
  }) => {
111
111
  const l = [];
112
112
  return y.actions = o.content.items.map((d) => {
113
- var u;
113
+ var m;
114
114
  const L = {
115
115
  label: d.title,
116
116
  actionKey: d.actionKey,
@@ -119,12 +119,12 @@ const j = (s) => {
119
119
  };
120
120
  if (d.data) {
121
121
  const S = o.actions[d.actionKey];
122
- c === m.ContactList ? (l.push(d.data.id), L.data = z(d.data, {
123
- guideId: (u = S == null ? void 0 : S.guideId) == null ? void 0 : u.toString()
122
+ c === f.ContactList ? (l.push(d.data.id), L.data = z(d.data, {
123
+ guideId: (m = S == null ? void 0 : S.guideId) == null ? void 0 : m.toString()
124
124
  })) : L.data = d.data;
125
125
  }
126
126
  return L;
127
- }), c === m.ContactList && (y.contactMethodIds = l), y;
127
+ }), c === f.ContactList && (y.contactMethodIds = l), y;
128
128
  }, i = async (c, o, h = [], y) => {
129
129
  var d, L;
130
130
  const l = K();
@@ -134,16 +134,16 @@ const j = (s) => {
134
134
  c.content.hints[0].id
135
135
  ), c.type) {
136
136
  case "List": {
137
- const { header: u, items: S, html: x } = c.content, k = [];
137
+ const { header: m, items: S, html: x } = c.content, k = [];
138
138
  let I = {
139
139
  actions: [],
140
140
  entryId: c.id,
141
141
  groupId: o.id
142
142
  };
143
- if (I.tags = c.tags || null, u && (I.header = u), (S == null ? void 0 : S.length) > 0) {
144
- const p = W(c);
143
+ if (I.tags = c.tags || null, m && (I.header = m), (S == null ? void 0 : S.length) > 0) {
144
+ const u = W(c);
145
145
  if (I = n(
146
- p,
146
+ u,
147
147
  c,
148
148
  o.id,
149
149
  I
@@ -182,7 +182,7 @@ const j = (s) => {
182
182
  b({
183
183
  messageId: l,
184
184
  message: [
185
- m.NoGoodAlternative,
185
+ f.NoGoodAlternative,
186
186
  { body: E.title }
187
187
  ],
188
188
  group: o
@@ -193,7 +193,7 @@ const j = (s) => {
193
193
  k.unshift(
194
194
  b({
195
195
  messageId: l,
196
- message: [p, I],
196
+ message: [u, I],
197
197
  group: o
198
198
  })
199
199
  );
@@ -207,8 +207,8 @@ const j = (s) => {
207
207
  ), k;
208
208
  }
209
209
  case "Text": {
210
- const u = [];
211
- if (u.push(
210
+ const m = [];
211
+ if (m.push(
212
212
  b({
213
213
  messageId: l,
214
214
  message: [
@@ -219,22 +219,22 @@ const j = (s) => {
219
219
  })
220
220
  ), h.length) {
221
221
  const S = h.find(
222
- (p) => {
222
+ (u) => {
223
223
  var C;
224
- return p.type === "List" && ((C = p.localState) == null ? void 0 : C.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching";
224
+ return u.type === "List" && ((C = u.localState) == null ? void 0 : C.$type) === "Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching";
225
225
  }
226
226
  ), x = h.find(
227
- (p) => p.tags.includes("dialog")
227
+ (u) => u.tags.includes("dialog")
228
228
  ), k = h.find(
229
- (p) => p.tags.includes("feedback")
229
+ (u) => u.tags.includes("feedback")
230
230
  ), I = h.find(
231
- (p) => p.tags.includes("contact") && p.type === "Contact"
231
+ (u) => u.tags.includes("contact") && u.type === "Contact"
232
232
  );
233
- if (I && u.push(
233
+ if (I && m.push(
234
234
  b({
235
235
  messageId: l,
236
236
  message: [
237
- m.ContactMethod,
237
+ f.ContactMethod,
238
238
  {
239
239
  contactMethodId: I.content.id,
240
240
  groupId: o.id,
@@ -243,28 +243,28 @@ const j = (s) => {
243
243
  ],
244
244
  group: o
245
245
  })
246
- ), x && u.push(
246
+ ), x && m.push(
247
247
  b({
248
248
  messageId: l,
249
249
  message: [
250
250
  v.ButtonList,
251
251
  {
252
- actions: x.content.items.map((p) => ({
253
- label: p.title,
254
- actionKey: p.actionKey,
255
- data: p.data
252
+ actions: x.content.items.map((u) => ({
253
+ label: u.title,
254
+ actionKey: u.actionKey,
255
+ data: u.data
256
256
  }))
257
257
  }
258
258
  ],
259
259
  group: o
260
260
  })
261
261
  ), S) {
262
- const p = n(
263
- m.ContactList,
262
+ const u = n(
263
+ f.ContactList,
264
264
  S,
265
265
  o.id
266
266
  );
267
- u.push(
267
+ m.push(
268
268
  b({
269
269
  messageId: l,
270
270
  message: [
@@ -273,40 +273,40 @@ const j = (s) => {
273
273
  ],
274
274
  group: o
275
275
  })
276
- ), u.push(
276
+ ), m.push(
277
277
  b({
278
278
  messageId: l,
279
- message: [m.ContactList, p],
279
+ message: [f.ContactList, u],
280
280
  group: o
281
281
  })
282
282
  );
283
283
  }
284
- k && u.push(
284
+ k && m.push(
285
285
  b({
286
286
  messageId: l,
287
287
  group: o,
288
288
  message: [
289
- m.FeedbackList,
289
+ f.FeedbackList,
290
290
  {
291
291
  title: k.content.html,
292
292
  messageId: l,
293
- actions: k.content.items.map((p) => ({
294
- actionKey: p.actionKey,
295
- label: p.title
293
+ actions: k.content.items.map((u) => ({
294
+ actionKey: u.actionKey,
295
+ label: u.title
296
296
  }))
297
297
  }
298
298
  ]
299
299
  })
300
300
  );
301
301
  }
302
- return u;
302
+ return m;
303
303
  }
304
304
  case "Contact":
305
305
  return [
306
306
  b({
307
307
  messageId: l,
308
308
  message: [
309
- m.ContactMethod,
309
+ f.ContactMethod,
310
310
  {
311
311
  contactMethodId: c.content.id,
312
312
  groupId: o.id,
@@ -317,11 +317,11 @@ const j = (s) => {
317
317
  })
318
318
  ];
319
319
  case "CategorizedNoticeList": {
320
- const u = [
320
+ const m = [
321
321
  b({
322
322
  messageId: l,
323
323
  message: [
324
- m.NotificationList,
324
+ f.NotificationList,
325
325
  {
326
326
  id: c.content.item.id.toString(),
327
327
  header: c.content.item.title,
@@ -333,7 +333,7 @@ const j = (s) => {
333
333
  })
334
334
  ];
335
335
  return (c.content.notices || []).forEach((S) => {
336
- u.push(
336
+ m.push(
337
337
  b({
338
338
  messageId: l,
339
339
  message: [
@@ -345,7 +345,7 @@ const j = (s) => {
345
345
  group: o
346
346
  })
347
347
  );
348
- }), u;
348
+ }), m;
349
349
  }
350
350
  case "footerNotice":
351
351
  return [
@@ -391,7 +391,7 @@ const j = (s) => {
391
391
  ["List", 2],
392
392
  ["Contact", 3],
393
393
  ["CategorizedNoticeList", 10]
394
- ]), g = [], M = t.sort((c, o) => {
394
+ ]), p = [], M = t.sort((c, o) => {
395
395
  const y = r.get(c.type) || 20, l = r.get(o.type) || 20;
396
396
  return y - l;
397
397
  }).filter((c) => !c.relation).reduce((c, o) => c.concat(a(o)), []), w = (c) => typeof c.actions.selector < "u";
@@ -401,16 +401,20 @@ const j = (s) => {
401
401
  ), h = R({ isUser: !1 });
402
402
  (await i(c, h, o, e)).forEach((l) => {
403
403
  h.items.push(l);
404
- }), h.items.length && g.push(h);
404
+ }), h.items.length && p.push(h);
405
405
  }
406
- return g;
406
+ return p;
407
407
  };
408
408
  class q {
409
409
  constructor(t, e, n, i) {
410
- f(this, "globalState");
411
- f(this, "localState");
412
- f(this, "clientId");
413
- f(this, "entries");
410
+ g(this, "endpoint");
411
+ g(this, "events");
412
+ g(this, "store");
413
+ g(this, "container");
414
+ g(this, "globalState");
415
+ g(this, "localState");
416
+ g(this, "clientId");
417
+ g(this, "entries");
414
418
  this.endpoint = t, this.events = e, this.store = n, this.container = i, this.clientId = K(), this.entries = [];
415
419
  }
416
420
  async start({ silent: t }) {
@@ -576,12 +580,13 @@ class q {
576
580
  }
577
581
  class Q {
578
582
  constructor(t) {
579
- f(this, "enabled", !0);
583
+ g(this, "container");
584
+ g(this, "enabled", !0);
580
585
  // set whether or not to store data
581
- f(this, "botProviderGlobalStateKey", "bot-provider-global-state");
582
- f(this, "botProviderLocalStateKey", "bot-provider-local-state");
583
- f(this, "botProviderEntriesKey", "bot-provider-entries");
584
- f(this, "botProviderMetaStateKey", "bot-provider-conversation-meta");
586
+ g(this, "botProviderGlobalStateKey", "bot-provider-global-state");
587
+ g(this, "botProviderLocalStateKey", "bot-provider-local-state");
588
+ g(this, "botProviderEntriesKey", "bot-provider-entries");
589
+ g(this, "botProviderMetaStateKey", "bot-provider-conversation-meta");
585
590
  this.container = t;
586
591
  }
587
592
  getKey(t) {
@@ -620,12 +625,14 @@ class Q {
620
625
  }
621
626
  class X {
622
627
  constructor(t, e, n) {
623
- f(this, "agent");
624
- f(this, "user");
625
- f(this, "httpClient");
626
- f(this, "events");
627
- f(this, "groups", []);
628
- f(this, "store");
628
+ g(this, "container");
629
+ g(this, "conversation");
630
+ g(this, "agent");
631
+ g(this, "user");
632
+ g(this, "httpClient");
633
+ g(this, "events");
634
+ g(this, "groups", []);
635
+ g(this, "store");
629
636
  this.container = t, this.conversation = e;
630
637
  const { events: i } = this.container.get("$widget");
631
638
  this.events = i, this.store = new Q(t), this.agent = e.createAgent({
@@ -642,14 +649,14 @@ class X {
642
649
  this.container
643
650
  ), this.events.subscribe(
644
651
  "provider:widget-entry",
645
- (r, g) => {
646
- this.onWidgetEntryReceived(g);
652
+ (r, p) => {
653
+ this.onWidgetEntryReceived(p);
647
654
  }
648
655
  ), this.events.subscribe(
649
656
  "provider:open-contact-method",
650
- async (r, g) => {
651
- const M = await this.httpClient.showContactMethodAction(g);
652
- M && (g.contactMethod.title && this.printUserMessage(g.contactMethod.title), this.onMessagesReceived(M));
657
+ async (r, p) => {
658
+ const M = await this.httpClient.showContactMethodAction(p);
659
+ M && (p.contactMethod.title && this.printUserMessage(p.contactMethod.title), this.onMessagesReceived(M));
653
660
  }
654
661
  );
655
662
  }
@@ -742,8 +749,8 @@ class X {
742
749
  }
743
750
  const n = (await this.container.getAsync("components")).components().ofType("widget-header").select();
744
751
  if (!n) return;
745
- const i = await this.container.get("settings"), a = i == null ? void 0 : i.components["widget-header"], r = (o = (c = a == null ? void 0 : a.properties) == null ? void 0 : c.actions) == null ? void 0 : o.avatar, g = (h = a == null ? void 0 : a.properties) == null ? void 0 : h.header, M = (y = a == null ? void 0 : a.properties) == null ? void 0 : y.tagline, w = {};
746
- !g && (t != null && t.heading) && (w.header = t.heading), !M && (t != null && t.tagline) && (w.tagline = t.tagline), !r && ((l = t == null ? void 0 : t.agent) != null && l.avatar) && (w.actions = {
752
+ const i = await this.container.get("settings"), a = i == null ? void 0 : i.components["widget-header"], r = (o = (c = a == null ? void 0 : a.properties) == null ? void 0 : c.actions) == null ? void 0 : o.avatar, p = (h = a == null ? void 0 : a.properties) == null ? void 0 : h.header, M = (y = a == null ? void 0 : a.properties) == null ? void 0 : y.tagline, w = {};
753
+ !p && (t != null && t.heading) && (w.header = t.heading), !M && (t != null && t.tagline) && (w.tagline = t.tagline), !r && ((l = t == null ? void 0 : t.agent) != null && l.avatar) && (w.actions = {
747
754
  avatar: {
748
755
  position: "left",
749
756
  symbol: {
@@ -758,23 +765,23 @@ const it = async (s) => {
758
765
  const t = await T.getInstance(s);
759
766
  N(
760
767
  s,
761
- m.ContactList,
762
- import("./contact-method-list-Beab6Xhp.mjs")
768
+ f.ContactList,
769
+ import("./contact-method-list-PU2fihB5.mjs")
763
770
  ), N(
764
771
  s,
765
- m.ContactMethod,
766
- import("./contact-method-B2iMHgUU.mjs")
772
+ f.ContactMethod,
773
+ import("./contact-method-BBndyfJD.mjs")
767
774
  ), N(
768
775
  s,
769
- m.NotificationList,
776
+ f.NotificationList,
770
777
  import("./notification-list-D7mYuPM3.mjs")
771
778
  ), N(
772
779
  s,
773
- m.NoGoodAlternative,
780
+ f.NoGoodAlternative,
774
781
  import("./no-good-alternative-DzoAFy4p.mjs")
775
782
  ), N(
776
783
  s,
777
- m.FeedbackList,
784
+ f.FeedbackList,
778
785
  import("./feedback-list-kWYlxaOZ.mjs")
779
786
  ), t.registerProvider("ace-knowledge-bot", (e, n) => {
780
787
  const i = new X(
@@ -785,20 +792,20 @@ const it = async (s) => {
785
792
  i.initialize();
786
793
  const a = [];
787
794
  return a.push(
788
- n.actions.watch("conversation.user-submit", (r, g) => {
795
+ n.actions.watch("conversation.user-submit", (r, p) => {
789
796
  i.onMessageSend(r.text);
790
797
  })
791
798
  ), a.push(
792
- n.actions.watch("conversation.action", (r, g) => (i.onInput(r), g(r)))
799
+ n.actions.watch("conversation.action", (r, p) => (i.onInput(r), p(r)))
793
800
  ), a.push(
794
801
  n.actions.create("evaluate", (r) => {
795
- const { events: g } = s.get("$widget");
796
- g.dispatch("bot-provider:evaluate", r);
802
+ const { events: p } = s.get("$widget");
803
+ p.dispatch("bot-provider:evaluate", r);
797
804
  })
798
805
  ), a.push(
799
806
  n.actions.create("submit", (r) => {
800
- const { events: g } = s.get("$widget");
801
- g.dispatch("bot-provider:form-submitted", r);
807
+ const { events: p } = s.get("$widget");
808
+ p.dispatch("bot-provider:form-submitted", r);
802
809
  })
803
810
  ), () => {
804
811
  a.forEach((r) => {
@@ -0,0 +1 @@
1
+ "use strict";var R=Object.defineProperty;var H=(n,t,e)=>t in n?R(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var h=(n,t,e)=>H(n,typeof t!="symbol"?t+"":t,e);const m=require("@telia-ace/widget-conversation"),N=require("@telia-ace/widget-services"),K=require("@telia-ace/widget-utilities"),P=require("@telia-ace/widget-forms");var y=(n=>(n.ContactMethod="ace-knowledge-bot-contact-method",n.ContactList="ace-knowledge-bot-contact-list",n.FeedbackList="ace-knowledge-bot-feedback-list",n.NotificationList="ace-knowledge-bot-notification-list",n.NoGoodAlternative="ace-knowledge-bot-no-good-alternative",n))(y||{});const $=n=>{if(n){const{type:t,content:e}=n;if(t&&e)return{type:t,content:e}}},B=({isUser:n,items:t=[],meta:e={}})=>{const s=K.uuid();return{id:s,isUser:n,items:t.map(a=>({id:a.id||K.uuid(),isUser:n,groupId:s,message:a.message||[]})),meta:e}},U=({id:n,title:t,defaultIcon:e,exits:[s],exitType:i,confirmationText:a,expandFormAutomatically:c,form:u,description:E},S={})=>{const{adapter:r}=s||{},{clientName:o="",settings:g={},customClientName:v=""}=r,{validation:l}=S,d={id:n.toString(),title:t,description:E,symbol:$(e),clientName:o==="custom.adapter"?v:o,expanded:!0,inline:!0,body:{}};if(o.indexOf("phone")>-1||o.indexOf("freetext")>-1){const{displayTextBeforeClick:L,textBeforeClick:f}=g;L==="true"&&(d.expanded=!1,d.title=f),o.indexOf("phone.text")>-1?d.body.phoneNumber=g.phoneNumber:d.body.freetext=g.freetext}return(o.indexOf("chat.popup")>-1||o.indexOf("link")>-1||o==="custom.adapter"&&i==="custom")&&(d.body=g,d.body.confirmationFallback=a),o.indexOf("ace")>-1&&(d.body=g),u&&u.hasValueComponents&&(l?d.body.form=P.FormBuilder.fromLegacyForm(n.toString(),u,l).get():d.body.form=P.FormBuilder.fromLegacyForm(n.toString(),u).get(),c||(d.expanded=d.inline=!1),d.body=A(d,{submit:"Submit"})),S.guideId&&(d.body.guideId=S.guideId),d},G=n=>{const{localState:t}=n;return n.tags.includes("category")&&n.tags.includes("contact")?m.ConversationMessageListItemType.ItemList:n.tags.includes("suggestion")||(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching"?m.ConversationMessageListItemType.LinkList:(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching"?y.FeedbackList:(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"?y.ContactList:m.ConversationMessageListItemType.ButtonList},q=(n,t)=>{const{knowledgeBotEndpoint:e}=t.properties();if(e)return`${e}/conversations`;const{data:s}=n.get("$settings");if(!s||!s.projection)throw new Error("Missing Knowledge Bot endpoint");return`${s.projection}/conversations`},A=(n,{submit:t,errors:e,meta:s})=>{var i;if((i=n==null?void 0:n.body)!=null&&i.form){const{body:a}=n,c=new P.FormBuilder(a.form);return a.form.layout.submit||c.createComponent(P.submitButton(t,"submit")),e&&c.setValidationErrors(e),s&&c.setMeta(s),{...a,form:c.get()}}return(n==null?void 0:n.body)||{}},O=async(n,t,e)=>{(await(await n.getAsync("dataClient")).getClient()).parameters.set(t,e)},b=({messageId:n,message:t,group:e})=>({id:n,message:t,groupId:e.id,isUser:e.isUser}),V=async(n,t,e)=>{const s=(r,o,g,v={actions:[],entryId:o.id,groupId:g})=>{const l=[];return v.actions=o.content.items.map(d=>{var f;const L={label:d.title,actionKey:d.actionKey,symbol:d.symbol?d.symbol:void 0,description:d.description||void 0};if(d.data){const w=o.actions[d.actionKey];r===y.ContactList?(l.push(d.data.id),L.data=U(d.data,{guideId:(f=w==null?void 0:w.guideId)==null?void 0:f.toString()})):L.data=d.data}return L}),r===y.ContactList&&(v.contactMethodIds=l),v},i=async(r,o,g=[],v)=>{var d,L;const l=K.uuid();switch(r.type!=="List"&&r.tags.includes("guide")&&((L=(d=r.content.hints)==null?void 0:d[0])!=null&&L.id)&&await O(n,"LastGuideId",r.content.hints[0].id),r.type){case"List":{const{header:f,items:w,html:x}=r.content,M=[];let C={actions:[],entryId:r.id,groupId:o.id};if(C.tags=r.tags||null,f&&(C.header=f),(w==null?void 0:w.length)>0){const p=G(r);if(C=s(p,r,o.id,C),g.length){const I=g.find(k=>k.tags.includes("paging")),T=g.find(k=>k.tags.includes("fallback"));if(I!=null&&I.content&&(o.meta.paging={actions:I.actions,items:I.content.items,localState:I.localState},I.content.items.forEach(k=>{C.actions.push({label:k.title,actionKey:k.actionKey,data:{groupId:v?v.id:o.id}})})),T){const k=T.content.items.find(F=>F.actionKey==="help");k&&(M.push(b({messageId:l,message:[m.ConversationMessageListItemType.Separator,void 0],group:o})),M.push(b({messageId:l,message:[y.NoGoodAlternative,{body:k.title}],group:o})))}}M.unshift(b({messageId:l,message:[p,C],group:o}))}return x&&M.unshift(b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:x}],group:o})),M}case"Text":{const f=[];if(f.push(b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:r.content.html}],group:o})),g.length){const w=g.find(p=>{var I;return p.type==="List"&&((I=p.localState)==null?void 0:I.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"}),x=g.find(p=>p.tags.includes("dialog")),M=g.find(p=>p.tags.includes("feedback")),C=g.find(p=>p.tags.includes("contact")&&p.type==="Contact");if(C&&f.push(b({messageId:l,message:[y.ContactMethod,{contactMethodId:C.content.id,groupId:o.id,guideId:C.content.guideId}],group:o})),x&&f.push(b({messageId:l,message:[m.ConversationMessageListItemType.ButtonList,{actions:x.content.items.map(p=>({label:p.title,actionKey:p.actionKey,data:p.data}))}],group:o})),w){const p=s(y.ContactList,w,o.id);f.push(b({messageId:l,message:[m.ConversationMessageListItemType.Separator,void 0],group:o})),f.push(b({messageId:l,message:[y.ContactList,p],group:o}))}M&&f.push(b({messageId:l,group:o,message:[y.FeedbackList,{title:M.content.html,messageId:l,actions:M.content.items.map(p=>({actionKey:p.actionKey,label:p.title}))}]}))}return f}case"Contact":return[b({messageId:l,message:[y.ContactMethod,{contactMethodId:r.content.id,groupId:o.id,guideId:r.content.guideId}],group:o})];case"CategorizedNoticeList":{const f=[b({messageId:l,message:[y.NotificationList,{id:r.content.item.id.toString(),header:r.content.item.title,items:r.content.item.listNotices,symbol:r.content.item.defaultIcon}],group:o})];return(r.content.notices||[]).forEach(w=>{f.push(b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:w.body}],group:o}))}),f}case"footerNotice":return[b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:r.content.item.body}],group:o})];case"Error":return[b({messageId:l,message:[m.ConversationMessageListItemType.HTML,{body:r.content.message||"Something went wrong."}],group:o})];default:return[]}},a=r=>["CategorizedNoticeList","NoticeList"].includes(r.type)?(r.content.items||[]).reduce((o,g)=>(r.content.isInitialNotices&&o.push({...r,id:K.uuid(),type:g.type||r.type,content:{$type:r.content.$type,isInitialNotices:r.content.isInitialNotices,notices:g.notices,item:g}}),o),[]):r,c=new Map([["Text",1],["List",2],["Contact",3],["CategorizedNoticeList",10]]),u=[],E=t.sort((r,o)=>{const v=c.get(r.type)||20,l=c.get(o.type)||20;return v-l}).filter(r=>!r.relation).reduce((r,o)=>r.concat(a(o)),[]),S=r=>typeof r.actions.selector<"u";for(const r of E){const o=t.filter(l=>l.relation===r.id&&!S(l)),g=B({isUser:!1});(await i(r,g,o,e)).forEach(l=>{g.items.push(l)}),g.items.length&&u.push(g)}return u};class j{constructor(t,e,s,i){h(this,"endpoint");h(this,"events");h(this,"store");h(this,"container");h(this,"globalState");h(this,"localState");h(this,"clientId");h(this,"entries");this.endpoint=t,this.events=e,this.store=s,this.container=i,this.clientId=K.uuid(),this.entries=[]}async start({silent:t}){const e=await this.store.read("globalState"),s=await this.store.read("localState"),i=await this.store.read("entries");if(this.globalState=e||this.globalState,this.localState=s||this.localState,this.entries=i||this.entries,t)return;const a=this.createInitialEnvelope();return await this.postEnvelope(a)}async sendMessage(t){const e={command:{phrase:t},globalState:this.globalState,clientId:this.clientId};return await this.postEnvelope(e)}async helpAction(){return this.postEnvelope({action:{key:"help",content:{$type:"Humany.Matching.Bots.Conversations.Actions.Help, Humany.Matching"}},globalState:this.globalState,clientId:this.clientId})}async nextAction(t){var s;const{paging:e}=t.meta;if((s=e.actions)!=null&&s.next)return this.postEnvelope({action:{key:"next",content:e.actions.next},localState:e.localState,globalState:this.globalState,clientId:this.clientId},t).then(i=>{const a=t.items.findIndex(c=>c.message[0]==="link-list");return a===-1||!i?t:{...t,meta:{...t.meta,...i[0].meta},items:[...t.items.slice(0,a),{...t.items[a],message:[i[0].items[0].message[0],{...t.items[a].message[1],...i[0].items[0].message[1]}]},...t.items.slice(a+1)]}})}async showContactMethodAction(t){const e=this.entries.find(i=>i.id===t.entryId),s=e==null?void 0:e.actions[t.actionKey];if(s)return this.postEnvelope({action:{key:t.actionKey,content:s},localState:e.localState,globalState:this.globalState,clientId:this.clientId})}async defaultAction(t){const e=this.getEntryOfAction(t);if(e)return this.postEnvelope({action:{key:t,content:e.actions[t]},localState:e.localState,globalState:this.globalState,clientId:this.clientId})}createInitialEnvelope(){return{command:{site:this.endpoint},clientId:this.clientId,globalState:{},funnel:this.container.get("$widget").name}}async postEnvelope(t,e){try{const s=await fetch(this.endpoint,this.getHttpOptions(t));if(!s.ok)throw s;const i=await s.json();return this.handleResponse(i,e)}catch(s){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let i="Something went wrong";return(s.message==="Failed to fetch"||s.message==="NetworkError when attempting to fetch resource.")&&(i="Lost connection... Please try again."),this.events.dispatch("tracking:http-client-error",{message:i,error:s}),this.handleResponse({entries:[{id:K.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:i},actions:{},tags:[]}]})}}async handleResponse(t,e){this.entries=this.entries.concat(t.entries),this.store.write(this.entries,"entries");const s=t.entries.find(a=>a.type==="Widget");return s&&this.events.dispatch("provider:widget-entry",s.content),t.globalState&&(this.globalState=t.globalState,this.store.write(t.globalState,"globalState")),this.localState=t.entries.reduce((a,c)=>c.localState?c.localState:a,void 0),this.store.write(this.localState,"localState"),await V(this.container,t.entries,e)}getHttpOptions(t){const e={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"}};return t.funnel=this.container.get("$widget").name,t.localState=t.localState||this.localState,Object.assign({},e,{body:JSON.stringify(t),credentials:"same-origin"})}getEntryOfAction(t){return this.entries.find(e=>!!e.actions[t])}}class z{constructor(t){h(this,"container");h(this,"enabled",!0);h(this,"botProviderGlobalStateKey","bot-provider-global-state");h(this,"botProviderLocalStateKey","bot-provider-local-state");h(this,"botProviderEntriesKey","bot-provider-entries");h(this,"botProviderMetaStateKey","bot-provider-conversation-meta");this.container=t}getKey(t){let e;switch(t){case"localState":e=this.botProviderLocalStateKey;break;case"globalState":e=this.botProviderGlobalStateKey;break;case"entries":e=this.botProviderEntriesKey;break;case"meta":e=this.botProviderMetaStateKey;break}return e}async read(t){const e=this.getKey(t);if(!(!this.enabled||!e))return N.readStorage(this.container,e)}async write(t,e){const s=this.getKey(e);if(!this.enabled||!s)return;(await N.createStorageWriter(this.container,s,N.StorageCategory.Necessary))(t)}}class W{constructor(t,e,s){h(this,"container");h(this,"conversation");h(this,"agent");h(this,"user");h(this,"httpClient");h(this,"events");h(this,"groups",[]);h(this,"store");this.container=t,this.conversation=e;const{events:i}=this.container.get("$widget");this.events=i,this.store=new z(t),this.agent=e.createAgent({id:"knowledge-bot-agent",name:"",avatar:void 0}),this.user=e.user;const a=q(t,s);this.httpClient=new j(a,i,this.store,this.container),this.events.subscribe("provider:widget-entry",(c,u)=>{this.onWidgetEntryReceived(u)}),this.events.subscribe("provider:open-contact-method",async(c,u)=>{const E=await this.httpClient.showContactMethodAction(u);E&&(u.contactMethod.title&&this.printUserMessage(u.contactMethod.title),this.onMessagesReceived(E))})}async initialize(){var a;const t=this.conversation.loading(),e=await this.store.read("meta");e!=null&&e.agent&&this.agent.update({name:e.agent.name,avatar:e.agent.avatar});const s=await this.conversation.isRehydrated(),i=await this.httpClient.start({silent:((a=this.conversation.options)==null?void 0:a.silent)||s});i&&this.onMessagesReceived(i),t()}async onMessagesReceived(t){this.groups=this.groups.concat(t),t.forEach(e=>{const s=e.items.map(i=>i.message);e.isUser?e.writer=this.user.print(s):e.writer=this.agent.print(s)})}async onInput(t){const e=typeof t=="string"?t:t.actionKey;switch(e){case"next":{if(typeof t=="string")return;const s=this.groups.find(i=>{var a;return i.id===((a=t.data)==null?void 0:a.groupId)});if(s){const i=await this.httpClient.nextAction(s);if(i){const a=i.items.map(c=>c.message);s.meta.paging=i==null?void 0:i.meta.paging,s.writer.update(a)}}}break;case"help":{const s=this.conversation.loading(),i=await this.httpClient.helpAction();s(),i&&this.onMessagesReceived(i)}break;default:{typeof t!="string"&&t.label&&this.printUserMessage(t.label);const s=this.conversation.loading(),i=await this.httpClient.defaultAction(e);i&&this.onMessagesReceived(i),s()}break}}printUserMessage(t){const e=B({isUser:!0,items:[{id:K.uuid(),isUser:!0,message:[m.ConversationMessageListItemType.HTML,{body:t}]}]});return this.onMessagesReceived([e]),e}async onMessageSend(t){const e=this.conversation.loading(),s=await this.httpClient.sendMessage(t);await O(this.container,"phrase",t),this.printUserMessage(t),s&&this.onMessagesReceived(s),e()}async onWidgetEntryReceived(t){var r,o,g,v,l;if(t.agent){const d={name:t.agent.name,avatar:t.agent.avatar};this.agent.update(d),(await N.createStorageWriter(this.container,"bot-provider-conversation-meta",N.StorageCategory.Necessary))({agent:d})}const s=(await this.container.getAsync("components")).components().ofType("widget-header").select();if(!s)return;const i=await this.container.get("settings"),a=i==null?void 0:i.components["widget-header"],c=(o=(r=a==null?void 0:a.properties)==null?void 0:r.actions)==null?void 0:o.avatar,u=(g=a==null?void 0:a.properties)==null?void 0:g.header,E=(v=a==null?void 0:a.properties)==null?void 0:v.tagline,S={};!u&&(t!=null&&t.heading)&&(S.header=t.heading),!E&&(t!=null&&t.tagline)&&(S.tagline=t.tagline),!c&&((l=t==null?void 0:t.agent)!=null&&l.avatar)&&(S.actions={avatar:{position:"left",symbol:{type:"Uri",content:t.agent.avatar}}}),Object.keys(S).length>0&&s.writeProperties(S)}}const _=async n=>{const t=await m.ConversationPlatform.getInstance(n);m.registerCustomMessageComponent(n,y.ContactList,Promise.resolve().then(()=>require("./contact-method-list-B5JMoU6B.js"))),m.registerCustomMessageComponent(n,y.ContactMethod,Promise.resolve().then(()=>require("./contact-method-BL0X7F1O.js"))),m.registerCustomMessageComponent(n,y.NotificationList,Promise.resolve().then(()=>require("./notification-list-BG4xAMsg.js"))),m.registerCustomMessageComponent(n,y.NoGoodAlternative,Promise.resolve().then(()=>require("./no-good-alternative-_ZVxoVd9.js"))),m.registerCustomMessageComponent(n,y.FeedbackList,Promise.resolve().then(()=>require("./feedback-list-DgaoNq6f.js"))),t.registerProvider("ace-knowledge-bot",(e,s)=>{const i=new W(n,e,s);i.initialize();const a=[];return a.push(s.actions.watch("conversation.user-submit",(c,u)=>{i.onMessageSend(c.text)})),a.push(s.actions.watch("conversation.action",(c,u)=>(i.onInput(c),u(c)))),a.push(s.actions.create("evaluate",c=>{const{events:u}=n.get("$widget");u.dispatch("bot-provider:evaluate",c)})),a.push(s.actions.create("submit",c=>{const{events:u}=n.get("$widget");u.dispatch("bot-provider:form-submitted",c)})),()=>{a.forEach(c=>{c()})}})};exports.KnowledgeBotProviderPlugin=_;exports.updateForm=A;
package/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  import { default as ConversationPlugin } from './plugin';
2
-
3
2
  export { ConversationPlugin };
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-UFpIz4f_.js");exports.ConversationPlugin=e.KnowledgeBotProviderPlugin;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-S0_42F-Y.js");exports.ConversationPlugin=e.KnowledgeBotProviderPlugin;
package/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { K as r } from "./index-BnOsK3l6.mjs";
1
+ import { K as r } from "./index-BC2Tv5_h.mjs";
2
2
  export {
3
3
  r as ConversationPlugin
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/knowledge-widget-bot-provider",
3
- "version": "1.3.59-rc.1",
3
+ "version": "1.3.59-rc.2",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
@@ -10,14 +10,14 @@
10
10
  }
11
11
  },
12
12
  "dependencies": {
13
- "@telia-ace/knowledge-data-client": "^1.3.59-rc.1",
14
- "@telia-ace/knowledge-widget-adapters": "^1.3.59-rc.1",
15
- "@telia-ace/knowledge-widget-core": "^1.3.59-rc.1",
16
- "@telia-ace/knowledge-widget-ui": "^1.3.59-rc.1",
17
- "@telia-ace/widget-conversation": "^1.3.59-rc.1",
18
- "@telia-ace/widget-forms": "^1.3.59-rc.1",
19
- "@telia-ace/widget-services": "^1.3.59-rc.1",
20
- "@telia-ace/widget-utilities": "^1.3.59-rc.1",
13
+ "@telia-ace/knowledge-data-client": "^1.3.59-rc.2",
14
+ "@telia-ace/knowledge-widget-adapters": "^1.3.59-rc.2",
15
+ "@telia-ace/knowledge-widget-core": "^1.3.59-rc.2",
16
+ "@telia-ace/knowledge-widget-ui": "^1.3.59-rc.2",
17
+ "@telia-ace/widget-conversation": "^1.3.59-rc.2",
18
+ "@telia-ace/widget-forms": "^1.3.59-rc.2",
19
+ "@telia-ace/widget-services": "^1.3.59-rc.2",
20
+ "@telia-ace/widget-utilities": "^1.3.59-rc.2",
21
21
  "@webprovisions/platform": "^1.1.4"
22
22
  },
23
23
  "peerDependencies": {
package/plugin.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  import { Container } from '@webprovisions/platform';
2
-
3
2
  declare const KnowledgeBotProviderPlugin: (container: Container) => Promise<void>;
4
3
  export default KnowledgeBotProviderPlugin;
package/provider.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { ComponentNodeController } from '../../core/src/index.ts';
1
+ import { ComponentNodeController } from '@telia-ace/knowledge-widget-core';
2
2
  import { Container } from '@webprovisions/platform';
3
3
  import { MessageGroup } from './types';
4
-
5
4
  declare class KnowledgeBotProvider {
6
5
  private container;
7
6
  private conversation;
package/store.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Container } from '@webprovisions/platform';
2
2
  import { GlobalState, LooseObject, ServerEntry } from './types';
3
-
4
3
  type MetaData = {
5
4
  agent: {
6
5
  name: string;
package/types.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { ConversationMessageListItemType } from '../../../conversation/src/index.ts';
2
-
1
+ import { ConversationMessageListItemType } from '@telia-ace/widget-conversation';
3
2
  export declare enum CustomMessageTypes {
4
3
  ContactMethod = "ace-knowledge-bot-contact-method",
5
4
  ContactList = "ace-knowledge-bot-contact-list",
@@ -1,6 +1,5 @@
1
1
  import { default as React } from 'react';
2
2
  import { ActionItem } from '../types';
3
-
4
3
  type Props = {
5
4
  actions: ActionItem[];
6
5
  contactMethodIds?: string[];
@@ -1,5 +1,4 @@
1
1
  import { default as React } from 'react';
2
-
3
2
  type Props = {
4
3
  contactMethodId: string;
5
4
  groupId: string;
@@ -1,5 +1,4 @@
1
1
  import { default as React } from 'react';
2
-
3
2
  type Props = {
4
3
  title: string;
5
4
  messageId: string;
@@ -1,5 +1,4 @@
1
1
  import { default as React } from 'react';
2
-
3
2
  type Props = {
4
3
  body: string;
5
4
  };
@@ -1,6 +1,5 @@
1
- import { Symbol } from '../../../ui/src/index.ts';
1
+ import { Symbol } from '@telia-ace/knowledge-widget-ui';
2
2
  import { default as React } from 'react';
3
-
4
3
  type Props = {
5
4
  id: string;
6
5
  header: string;
package/ui/styles.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Theme } from '@emotion/react';
2
-
3
2
  export declare const messageContentPadding: (p: {
4
3
  theme: Theme;
5
4
  }) => import('@emotion/react').SerializedStyles;
package/utils.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { ContactMethodType } from '../../adapters/src/index.ts';
2
- import { ConversationMessageListItemType } from '../../../conversation/src/index.ts';
1
+ import { ContactMethodType } from '@telia-ace/knowledge-widget-adapters';
2
+ import { ConversationMessageListItemType } from '@telia-ace/widget-conversation';
3
3
  import { Container } from '@webprovisions/platform';
4
4
  import { CustomMessageTypes, MessageGroup, MessageGroupItem, ServerEntry } from './types';
5
-
6
5
  export declare const createGroup: ({ isUser, items, meta, }: {
7
6
  isUser: boolean;
8
7
  items?: Partial<MessageGroupItem>[];
package/index-UFpIz4f_.js DELETED
@@ -1 +0,0 @@
1
- "use strict";var R=Object.defineProperty;var H=(n,t,e)=>t in n?R(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var y=(n,t,e)=>H(n,typeof t!="symbol"?t+"":t,e);const p=require("@telia-ace/widget-conversation"),N=require("@telia-ace/widget-services"),K=require("@telia-ace/widget-utilities"),P=require("@telia-ace/widget-forms");var f=(n=>(n.ContactMethod="ace-knowledge-bot-contact-method",n.ContactList="ace-knowledge-bot-contact-list",n.FeedbackList="ace-knowledge-bot-feedback-list",n.NotificationList="ace-knowledge-bot-notification-list",n.NoGoodAlternative="ace-knowledge-bot-no-good-alternative",n))(f||{});const $=n=>{if(n){const{type:t,content:e}=n;if(t&&e)return{type:t,content:e}}},B=({isUser:n,items:t=[],meta:e={}})=>{const s=K.uuid();return{id:s,isUser:n,items:t.map(a=>({id:a.id||K.uuid(),isUser:n,groupId:s,message:a.message||[]})),meta:e}},U=({id:n,title:t,defaultIcon:e,exits:[s],exitType:i,confirmationText:a,expandFormAutomatically:c,form:h,description:E},S={})=>{const{adapter:r}=s||{},{clientName:o="",settings:g={},customClientName:v=""}=r,{validation:l}=S,d={id:n.toString(),title:t,description:E,symbol:$(e),clientName:o==="custom.adapter"?v:o,expanded:!0,inline:!0,body:{}};if(o.indexOf("phone")>-1||o.indexOf("freetext")>-1){const{displayTextBeforeClick:L,textBeforeClick:m}=g;L==="true"&&(d.expanded=!1,d.title=m),o.indexOf("phone.text")>-1?d.body.phoneNumber=g.phoneNumber:d.body.freetext=g.freetext}return(o.indexOf("chat.popup")>-1||o.indexOf("link")>-1||o==="custom.adapter"&&i==="custom")&&(d.body=g,d.body.confirmationFallback=a),o.indexOf("ace")>-1&&(d.body=g),h&&h.hasValueComponents&&(l?d.body.form=P.FormBuilder.fromLegacyForm(n.toString(),h,l).get():d.body.form=P.FormBuilder.fromLegacyForm(n.toString(),h).get(),c||(d.expanded=d.inline=!1),d.body=A(d,{submit:"Submit"})),S.guideId&&(d.body.guideId=S.guideId),d},G=n=>{const{localState:t}=n;return n.tags.includes("category")&&n.tags.includes("contact")?p.ConversationMessageListItemType.ItemList:n.tags.includes("suggestion")||(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.GuideListState, Humany.Matching"?p.ConversationMessageListItemType.LinkList:(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.States.GuideFeedbackState, Humany.Matching"?f.FeedbackList:(t==null?void 0:t.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"?f.ContactList:p.ConversationMessageListItemType.ButtonList},q=(n,t)=>{const{knowledgeBotEndpoint:e}=t.properties();if(e)return`${e}/conversations`;const{data:s}=n.get("$settings");if(!s||!s.projection)throw new Error("Missing Knowledge Bot endpoint");return`${s.projection}/conversations`},A=(n,{submit:t,errors:e,meta:s})=>{var i;if((i=n==null?void 0:n.body)!=null&&i.form){const{body:a}=n,c=new P.FormBuilder(a.form);return a.form.layout.submit||c.createComponent(P.submitButton(t,"submit")),e&&c.setValidationErrors(e),s&&c.setMeta(s),{...a,form:c.get()}}return(n==null?void 0:n.body)||{}},O=async(n,t,e)=>{(await(await n.getAsync("dataClient")).getClient()).parameters.set(t,e)},b=({messageId:n,message:t,group:e})=>({id:n,message:t,groupId:e.id,isUser:e.isUser}),V=async(n,t,e)=>{const s=(r,o,g,v={actions:[],entryId:o.id,groupId:g})=>{const l=[];return v.actions=o.content.items.map(d=>{var m;const L={label:d.title,actionKey:d.actionKey,symbol:d.symbol?d.symbol:void 0,description:d.description||void 0};if(d.data){const w=o.actions[d.actionKey];r===f.ContactList?(l.push(d.data.id),L.data=U(d.data,{guideId:(m=w==null?void 0:w.guideId)==null?void 0:m.toString()})):L.data=d.data}return L}),r===f.ContactList&&(v.contactMethodIds=l),v},i=async(r,o,g=[],v)=>{var d,L;const l=K.uuid();switch(r.type!=="List"&&r.tags.includes("guide")&&((L=(d=r.content.hints)==null?void 0:d[0])!=null&&L.id)&&await O(n,"LastGuideId",r.content.hints[0].id),r.type){case"List":{const{header:m,items:w,html:x}=r.content,M=[];let C={actions:[],entryId:r.id,groupId:o.id};if(C.tags=r.tags||null,m&&(C.header=m),(w==null?void 0:w.length)>0){const u=G(r);if(C=s(u,r,o.id,C),g.length){const I=g.find(k=>k.tags.includes("paging")),T=g.find(k=>k.tags.includes("fallback"));if(I!=null&&I.content&&(o.meta.paging={actions:I.actions,items:I.content.items,localState:I.localState},I.content.items.forEach(k=>{C.actions.push({label:k.title,actionKey:k.actionKey,data:{groupId:v?v.id:o.id}})})),T){const k=T.content.items.find(F=>F.actionKey==="help");k&&(M.push(b({messageId:l,message:[p.ConversationMessageListItemType.Separator,void 0],group:o})),M.push(b({messageId:l,message:[f.NoGoodAlternative,{body:k.title}],group:o})))}}M.unshift(b({messageId:l,message:[u,C],group:o}))}return x&&M.unshift(b({messageId:l,message:[p.ConversationMessageListItemType.HTML,{body:x}],group:o})),M}case"Text":{const m=[];if(m.push(b({messageId:l,message:[p.ConversationMessageListItemType.HTML,{body:r.content.html}],group:o})),g.length){const w=g.find(u=>{var I;return u.type==="List"&&((I=u.localState)==null?void 0:I.$type)==="Humany.Matching.Bots.Conversations.States.ContactState, Humany.Matching"}),x=g.find(u=>u.tags.includes("dialog")),M=g.find(u=>u.tags.includes("feedback")),C=g.find(u=>u.tags.includes("contact")&&u.type==="Contact");if(C&&m.push(b({messageId:l,message:[f.ContactMethod,{contactMethodId:C.content.id,groupId:o.id,guideId:C.content.guideId}],group:o})),x&&m.push(b({messageId:l,message:[p.ConversationMessageListItemType.ButtonList,{actions:x.content.items.map(u=>({label:u.title,actionKey:u.actionKey,data:u.data}))}],group:o})),w){const u=s(f.ContactList,w,o.id);m.push(b({messageId:l,message:[p.ConversationMessageListItemType.Separator,void 0],group:o})),m.push(b({messageId:l,message:[f.ContactList,u],group:o}))}M&&m.push(b({messageId:l,group:o,message:[f.FeedbackList,{title:M.content.html,messageId:l,actions:M.content.items.map(u=>({actionKey:u.actionKey,label:u.title}))}]}))}return m}case"Contact":return[b({messageId:l,message:[f.ContactMethod,{contactMethodId:r.content.id,groupId:o.id,guideId:r.content.guideId}],group:o})];case"CategorizedNoticeList":{const m=[b({messageId:l,message:[f.NotificationList,{id:r.content.item.id.toString(),header:r.content.item.title,items:r.content.item.listNotices,symbol:r.content.item.defaultIcon}],group:o})];return(r.content.notices||[]).forEach(w=>{m.push(b({messageId:l,message:[p.ConversationMessageListItemType.HTML,{body:w.body}],group:o}))}),m}case"footerNotice":return[b({messageId:l,message:[p.ConversationMessageListItemType.HTML,{body:r.content.item.body}],group:o})];case"Error":return[b({messageId:l,message:[p.ConversationMessageListItemType.HTML,{body:r.content.message||"Something went wrong."}],group:o})];default:return[]}},a=r=>["CategorizedNoticeList","NoticeList"].includes(r.type)?(r.content.items||[]).reduce((o,g)=>(r.content.isInitialNotices&&o.push({...r,id:K.uuid(),type:g.type||r.type,content:{$type:r.content.$type,isInitialNotices:r.content.isInitialNotices,notices:g.notices,item:g}}),o),[]):r,c=new Map([["Text",1],["List",2],["Contact",3],["CategorizedNoticeList",10]]),h=[],E=t.sort((r,o)=>{const v=c.get(r.type)||20,l=c.get(o.type)||20;return v-l}).filter(r=>!r.relation).reduce((r,o)=>r.concat(a(o)),[]),S=r=>typeof r.actions.selector<"u";for(const r of E){const o=t.filter(l=>l.relation===r.id&&!S(l)),g=B({isUser:!1});(await i(r,g,o,e)).forEach(l=>{g.items.push(l)}),g.items.length&&h.push(g)}return h};class j{constructor(t,e,s,i){y(this,"globalState");y(this,"localState");y(this,"clientId");y(this,"entries");this.endpoint=t,this.events=e,this.store=s,this.container=i,this.clientId=K.uuid(),this.entries=[]}async start({silent:t}){const e=await this.store.read("globalState"),s=await this.store.read("localState"),i=await this.store.read("entries");if(this.globalState=e||this.globalState,this.localState=s||this.localState,this.entries=i||this.entries,t)return;const a=this.createInitialEnvelope();return await this.postEnvelope(a)}async sendMessage(t){const e={command:{phrase:t},globalState:this.globalState,clientId:this.clientId};return await this.postEnvelope(e)}async helpAction(){return this.postEnvelope({action:{key:"help",content:{$type:"Humany.Matching.Bots.Conversations.Actions.Help, Humany.Matching"}},globalState:this.globalState,clientId:this.clientId})}async nextAction(t){var s;const{paging:e}=t.meta;if((s=e.actions)!=null&&s.next)return this.postEnvelope({action:{key:"next",content:e.actions.next},localState:e.localState,globalState:this.globalState,clientId:this.clientId},t).then(i=>{const a=t.items.findIndex(c=>c.message[0]==="link-list");return a===-1||!i?t:{...t,meta:{...t.meta,...i[0].meta},items:[...t.items.slice(0,a),{...t.items[a],message:[i[0].items[0].message[0],{...t.items[a].message[1],...i[0].items[0].message[1]}]},...t.items.slice(a+1)]}})}async showContactMethodAction(t){const e=this.entries.find(i=>i.id===t.entryId),s=e==null?void 0:e.actions[t.actionKey];if(s)return this.postEnvelope({action:{key:t.actionKey,content:s},localState:e.localState,globalState:this.globalState,clientId:this.clientId})}async defaultAction(t){const e=this.getEntryOfAction(t);if(e)return this.postEnvelope({action:{key:t,content:e.actions[t]},localState:e.localState,globalState:this.globalState,clientId:this.clientId})}createInitialEnvelope(){return{command:{site:this.endpoint},clientId:this.clientId,globalState:{},funnel:this.container.get("$widget").name}}async postEnvelope(t,e){try{const s=await fetch(this.endpoint,this.getHttpOptions(t));if(!s.ok)throw s;const i=await s.json();return this.handleResponse(i,e)}catch(s){process.env.NODE_ENV!=="production"&&console.warn("Something went wrong when posting the envelope.");let i="Something went wrong";return(s.message==="Failed to fetch"||s.message==="NetworkError when attempting to fetch resource.")&&(i="Lost connection... Please try again."),this.events.dispatch("tracking:http-client-error",{message:i,error:s}),this.handleResponse({entries:[{id:K.uuid(),type:"Error",timestamp:new Date().toISOString(),content:{message:i},actions:{},tags:[]}]})}}async handleResponse(t,e){this.entries=this.entries.concat(t.entries),this.store.write(this.entries,"entries");const s=t.entries.find(a=>a.type==="Widget");return s&&this.events.dispatch("provider:widget-entry",s.content),t.globalState&&(this.globalState=t.globalState,this.store.write(t.globalState,"globalState")),this.localState=t.entries.reduce((a,c)=>c.localState?c.localState:a,void 0),this.store.write(this.localState,"localState"),await V(this.container,t.entries,e)}getHttpOptions(t){const e={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"}};return t.funnel=this.container.get("$widget").name,t.localState=t.localState||this.localState,Object.assign({},e,{body:JSON.stringify(t),credentials:"same-origin"})}getEntryOfAction(t){return this.entries.find(e=>!!e.actions[t])}}class z{constructor(t){y(this,"enabled",!0);y(this,"botProviderGlobalStateKey","bot-provider-global-state");y(this,"botProviderLocalStateKey","bot-provider-local-state");y(this,"botProviderEntriesKey","bot-provider-entries");y(this,"botProviderMetaStateKey","bot-provider-conversation-meta");this.container=t}getKey(t){let e;switch(t){case"localState":e=this.botProviderLocalStateKey;break;case"globalState":e=this.botProviderGlobalStateKey;break;case"entries":e=this.botProviderEntriesKey;break;case"meta":e=this.botProviderMetaStateKey;break}return e}async read(t){const e=this.getKey(t);if(!(!this.enabled||!e))return N.readStorage(this.container,e)}async write(t,e){const s=this.getKey(e);if(!this.enabled||!s)return;(await N.createStorageWriter(this.container,s,N.StorageCategory.Necessary))(t)}}class W{constructor(t,e,s){y(this,"agent");y(this,"user");y(this,"httpClient");y(this,"events");y(this,"groups",[]);y(this,"store");this.container=t,this.conversation=e;const{events:i}=this.container.get("$widget");this.events=i,this.store=new z(t),this.agent=e.createAgent({id:"knowledge-bot-agent",name:"",avatar:void 0}),this.user=e.user;const a=q(t,s);this.httpClient=new j(a,i,this.store,this.container),this.events.subscribe("provider:widget-entry",(c,h)=>{this.onWidgetEntryReceived(h)}),this.events.subscribe("provider:open-contact-method",async(c,h)=>{const E=await this.httpClient.showContactMethodAction(h);E&&(h.contactMethod.title&&this.printUserMessage(h.contactMethod.title),this.onMessagesReceived(E))})}async initialize(){var a;const t=this.conversation.loading(),e=await this.store.read("meta");e!=null&&e.agent&&this.agent.update({name:e.agent.name,avatar:e.agent.avatar});const s=await this.conversation.isRehydrated(),i=await this.httpClient.start({silent:((a=this.conversation.options)==null?void 0:a.silent)||s});i&&this.onMessagesReceived(i),t()}async onMessagesReceived(t){this.groups=this.groups.concat(t),t.forEach(e=>{const s=e.items.map(i=>i.message);e.isUser?e.writer=this.user.print(s):e.writer=this.agent.print(s)})}async onInput(t){const e=typeof t=="string"?t:t.actionKey;switch(e){case"next":{if(typeof t=="string")return;const s=this.groups.find(i=>{var a;return i.id===((a=t.data)==null?void 0:a.groupId)});if(s){const i=await this.httpClient.nextAction(s);if(i){const a=i.items.map(c=>c.message);s.meta.paging=i==null?void 0:i.meta.paging,s.writer.update(a)}}}break;case"help":{const s=this.conversation.loading(),i=await this.httpClient.helpAction();s(),i&&this.onMessagesReceived(i)}break;default:{typeof t!="string"&&t.label&&this.printUserMessage(t.label);const s=this.conversation.loading(),i=await this.httpClient.defaultAction(e);i&&this.onMessagesReceived(i),s()}break}}printUserMessage(t){const e=B({isUser:!0,items:[{id:K.uuid(),isUser:!0,message:[p.ConversationMessageListItemType.HTML,{body:t}]}]});return this.onMessagesReceived([e]),e}async onMessageSend(t){const e=this.conversation.loading(),s=await this.httpClient.sendMessage(t);await O(this.container,"phrase",t),this.printUserMessage(t),s&&this.onMessagesReceived(s),e()}async onWidgetEntryReceived(t){var r,o,g,v,l;if(t.agent){const d={name:t.agent.name,avatar:t.agent.avatar};this.agent.update(d),(await N.createStorageWriter(this.container,"bot-provider-conversation-meta",N.StorageCategory.Necessary))({agent:d})}const s=(await this.container.getAsync("components")).components().ofType("widget-header").select();if(!s)return;const i=await this.container.get("settings"),a=i==null?void 0:i.components["widget-header"],c=(o=(r=a==null?void 0:a.properties)==null?void 0:r.actions)==null?void 0:o.avatar,h=(g=a==null?void 0:a.properties)==null?void 0:g.header,E=(v=a==null?void 0:a.properties)==null?void 0:v.tagline,S={};!h&&(t!=null&&t.heading)&&(S.header=t.heading),!E&&(t!=null&&t.tagline)&&(S.tagline=t.tagline),!c&&((l=t==null?void 0:t.agent)!=null&&l.avatar)&&(S.actions={avatar:{position:"left",symbol:{type:"Uri",content:t.agent.avatar}}}),Object.keys(S).length>0&&s.writeProperties(S)}}const _=async n=>{const t=await p.ConversationPlatform.getInstance(n);p.registerCustomMessageComponent(n,f.ContactList,Promise.resolve().then(()=>require("./contact-method-list-BI5sXyex.js"))),p.registerCustomMessageComponent(n,f.ContactMethod,Promise.resolve().then(()=>require("./contact-method-bGgHBWcr.js"))),p.registerCustomMessageComponent(n,f.NotificationList,Promise.resolve().then(()=>require("./notification-list-BG4xAMsg.js"))),p.registerCustomMessageComponent(n,f.NoGoodAlternative,Promise.resolve().then(()=>require("./no-good-alternative-_ZVxoVd9.js"))),p.registerCustomMessageComponent(n,f.FeedbackList,Promise.resolve().then(()=>require("./feedback-list-DgaoNq6f.js"))),t.registerProvider("ace-knowledge-bot",(e,s)=>{const i=new W(n,e,s);i.initialize();const a=[];return a.push(s.actions.watch("conversation.user-submit",(c,h)=>{i.onMessageSend(c.text)})),a.push(s.actions.watch("conversation.action",(c,h)=>(i.onInput(c),h(c)))),a.push(s.actions.create("evaluate",c=>{const{events:h}=n.get("$widget");h.dispatch("bot-provider:evaluate",c)})),a.push(s.actions.create("submit",c=>{const{events:h}=n.get("$widget");h.dispatch("bot-provider:form-submitted",c)})),()=>{a.forEach(c=>{c()})}})};exports.KnowledgeBotProviderPlugin=_;exports.updateForm=A;