@opencx/widget 3.0.84 → 3.0.86
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/dist/designs.cjs +24 -24
- package/dist/designs.cjs.map +1 -1
- package/dist/designs.js +3412 -3185
- package/dist/designs.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/is-exhaustive-9o43S91P.cjs +2 -0
- package/dist/is-exhaustive-9o43S91P.cjs.map +1 -0
- package/dist/is-exhaustive-DGJzQK69.js +7 -0
- package/dist/is-exhaustive-DGJzQK69.js.map +1 -0
- package/dist/react.cjs +1 -1
- package/dist/react.js +2 -2
- package/dist/src/designs/react/components/Header.d.ts +3 -0
- package/dist/src/designs/react/components/lib/DynamicIcon.d.ts +6 -0
- package/dist/src/designs/react/components/lib/dialog.d.ts +8 -2
- package/dist/src/designs/react/hooks/useSetWidgetSize.d.ts +8 -0
- package/dist/src/headless/core/context/router.ctx.d.ts +6 -5
- package/dist/src/headless/core/context/session.ctx.d.ts +32 -1
- package/dist/src/headless/core/index.d.ts +4 -2
- package/dist/src/headless/core/types/icons.d.ts +3 -0
- package/dist/src/headless/core/types/widget-config.d.ts +45 -0
- package/dist/src/headless/core/utils/is-exhaustive.d.ts +1 -0
- package/dist/src/headless/react/hooks/useSessions.d.ts +32 -0
- package/dist/src/headless/react/hooks/useWidgetRouter.d.ts +1 -1
- package/dist/{useWidgetTrigger-38gyi4gE.js → useWidgetTrigger-Bi12WVrs.js} +59 -58
- package/dist/useWidgetTrigger-Bi12WVrs.js.map +1 -0
- package/dist/{useWidgetTrigger-OXlF9nHb.cjs → useWidgetTrigger-Bplu_1C-.cjs} +2 -2
- package/dist/useWidgetTrigger-Bplu_1C-.cjs.map +1 -0
- package/dist/{widget.ctx-r2Nzp00O.js → widget.ctx-DFFwNHvy.js} +254 -241
- package/dist/widget.ctx-DFFwNHvy.js.map +1 -0
- package/dist/widget.ctx-oIT8sGvJ.cjs +5 -0
- package/dist/widget.ctx-oIT8sGvJ.cjs.map +1 -0
- package/dist-embed/script.js +147 -82
- package/dist-embed/script.js.map +1 -1
- package/package.json +2 -1
- package/dist/src/designs/react/components/WidgetHeader.d.ts +0 -2
- package/dist/src/designs/react/hooks/useWidgetSize.d.ts +0 -4
- package/dist/useWidgetTrigger-38gyi4gE.js.map +0 -1
- package/dist/useWidgetTrigger-OXlF9nHb.cjs.map +0 -1
- package/dist/widget.ctx-CoJrM0OY.cjs +0 -5
- package/dist/widget.ctx-CoJrM0OY.cjs.map +0 -1
- package/dist/widget.ctx-r2Nzp00O.js.map +0 -1
|
@@ -6,45 +6,45 @@ const F = (d) => {
|
|
|
6
6
|
}, _ = (d) => {
|
|
7
7
|
const n = M({
|
|
8
8
|
baseUrl: d.baseUrl
|
|
9
|
-
}),
|
|
9
|
+
}), a = {
|
|
10
10
|
onRequest: d.onRequest,
|
|
11
11
|
onResponse: d.onResponse,
|
|
12
12
|
onError: d.onError || F
|
|
13
13
|
};
|
|
14
|
-
return n.use(
|
|
14
|
+
return n.use(a), n;
|
|
15
15
|
};
|
|
16
16
|
class T {
|
|
17
17
|
constructor({ config: n }) {
|
|
18
|
-
var
|
|
18
|
+
var o, e;
|
|
19
19
|
this.userToken = null, this.constructClientOptions = (t) => {
|
|
20
|
-
const
|
|
20
|
+
const s = this.config.apiUrl || "https://api.open.cx", i = {
|
|
21
21
|
"X-Bot-Token": this.config.token,
|
|
22
22
|
"Content-Type": "application/json",
|
|
23
23
|
Accept: "application/json",
|
|
24
24
|
Authorization: t ? `Bearer ${t}` : void 0
|
|
25
25
|
};
|
|
26
|
-
return { baseUrl:
|
|
26
|
+
return { baseUrl: s, headers: i };
|
|
27
27
|
}, this.createOpenAPIClient = ({
|
|
28
28
|
baseUrl: t,
|
|
29
|
-
headers:
|
|
29
|
+
headers: s
|
|
30
30
|
}) => _({
|
|
31
31
|
baseUrl: t,
|
|
32
|
-
onRequest: ({ request:
|
|
33
|
-
Object.entries(
|
|
34
|
-
r &&
|
|
32
|
+
onRequest: ({ request: i }) => {
|
|
33
|
+
Object.entries(s).forEach(([c, r]) => {
|
|
34
|
+
r && i.headers.set(c, r);
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
}), this.setAuthToken = (t) => {
|
|
38
38
|
this.userToken = t;
|
|
39
|
-
const { baseUrl:
|
|
40
|
-
this.client = this.createOpenAPIClient({ baseUrl:
|
|
39
|
+
const { baseUrl: s, headers: i } = this.constructClientOptions(t);
|
|
40
|
+
this.client = this.createOpenAPIClient({ baseUrl: s, headers: i });
|
|
41
41
|
}, this.getExternalWidgetConfig = async () => await this.client.GET("/backend/widget/v2/config", {
|
|
42
42
|
params: { header: { "X-Bot-Token": this.config.token } }
|
|
43
43
|
}), this.widgetPrelude = async () => await this.client.GET("/backend/widget/v2/prelude", {
|
|
44
44
|
params: { header: { "X-Bot-Token": this.config.token } }
|
|
45
|
-
}), this.sendMessage = async (t,
|
|
45
|
+
}), this.sendMessage = async (t, s) => await this.client.POST("/backend/widget/v2/chat/send", {
|
|
46
46
|
body: t,
|
|
47
|
-
signal:
|
|
47
|
+
signal: s
|
|
48
48
|
}), this.createUnverifiedContact = async (t) => await this.client.POST(
|
|
49
49
|
"/backend/widget/v2/contact/create-unverified",
|
|
50
50
|
{
|
|
@@ -55,92 +55,92 @@ class T {
|
|
|
55
55
|
body: t
|
|
56
56
|
}), this.pollSessionAndHistory = async ({
|
|
57
57
|
sessionId: t,
|
|
58
|
-
lastMessageTimestamp:
|
|
59
|
-
abortSignal:
|
|
58
|
+
lastMessageTimestamp: s,
|
|
59
|
+
abortSignal: i
|
|
60
60
|
}) => {
|
|
61
|
-
const
|
|
61
|
+
const c = s ? { lastMessageTimestamp: s } : void 0;
|
|
62
62
|
return await this.client.GET("/backend/widget/v2/poll/{sessionId}", {
|
|
63
|
-
params: { path: { sessionId: t }, query:
|
|
64
|
-
signal:
|
|
63
|
+
params: { path: { sessionId: t }, query: c },
|
|
64
|
+
signal: i
|
|
65
65
|
});
|
|
66
66
|
}, this.getSessions = async ({
|
|
67
67
|
cursor: t,
|
|
68
|
-
filters:
|
|
69
|
-
abortSignal:
|
|
68
|
+
filters: s,
|
|
69
|
+
abortSignal: i
|
|
70
70
|
}) => await this.client.GET("/backend/widget/v2/sessions", {
|
|
71
|
-
params: { query: { cursor: t, filters: JSON.stringify(
|
|
72
|
-
signal:
|
|
71
|
+
params: { query: { cursor: t, filters: JSON.stringify(s) } },
|
|
72
|
+
signal: i
|
|
73
73
|
}), this.uploadFile = async ({
|
|
74
74
|
file: t,
|
|
75
|
-
abortSignal:
|
|
76
|
-
onProgress:
|
|
77
|
-
}) => new Promise((
|
|
75
|
+
abortSignal: s,
|
|
76
|
+
onProgress: i
|
|
77
|
+
}) => new Promise((c, r) => {
|
|
78
78
|
var v;
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
}),
|
|
79
|
+
const h = new FormData();
|
|
80
|
+
h.append("file", t);
|
|
81
|
+
const l = new XMLHttpRequest();
|
|
82
|
+
if (s && (s.addEventListener("abort", () => {
|
|
83
|
+
l.abort(), r(new DOMException("Aborted", "AbortError"));
|
|
84
|
+
}), s.aborted)) {
|
|
85
85
|
r(new DOMException("Aborted", "AbortError"));
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
if (u.lengthComputable &&
|
|
90
|
-
const
|
|
91
|
-
|
|
88
|
+
l.upload.addEventListener("progress", (u) => {
|
|
89
|
+
if (u.lengthComputable && i) {
|
|
90
|
+
const S = Math.round(u.loaded / u.total * 100);
|
|
91
|
+
i(S);
|
|
92
92
|
}
|
|
93
|
-
}),
|
|
94
|
-
if (
|
|
93
|
+
}), l.addEventListener("load", () => {
|
|
94
|
+
if (l.status >= 200 && l.status < 300)
|
|
95
95
|
try {
|
|
96
|
-
const u = JSON.parse(
|
|
97
|
-
|
|
96
|
+
const u = JSON.parse(l.responseText);
|
|
97
|
+
c(u);
|
|
98
98
|
} catch (u) {
|
|
99
99
|
r(new Error(`Failed to parse response: ${u}`));
|
|
100
100
|
}
|
|
101
101
|
else
|
|
102
|
-
r(new Error(`Upload failed with status: ${
|
|
103
|
-
}),
|
|
102
|
+
r(new Error(`Upload failed with status: ${l.status}`));
|
|
103
|
+
}), l.addEventListener("error", () => {
|
|
104
104
|
r(new Error("Network error occurred"));
|
|
105
|
-
}),
|
|
105
|
+
}), l.addEventListener("timeout", () => {
|
|
106
106
|
r(new Error("Upload timed out"));
|
|
107
107
|
});
|
|
108
|
-
const { baseUrl:
|
|
109
|
-
|
|
110
|
-
}), this.vote = async (t) => await this.client.POST("/backend/widget/v2/chat/vote", { body: t }), this.resolveSession = async (t,
|
|
108
|
+
const { baseUrl: f } = this.constructClientOptions(this.userToken), p = `${f}/backend/widget/v2/upload`;
|
|
109
|
+
l.open("POST", p), l.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((v = this.config.user) == null ? void 0 : v.token) ? l.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : console.error("User token not set"), l.send(h);
|
|
110
|
+
}), this.vote = async (t) => await this.client.POST("/backend/widget/v2/chat/vote", { body: t }), this.resolveSession = async (t, s) => await this.client.POST("/backend/widget/v2/session/resolve", {
|
|
111
111
|
body: t,
|
|
112
|
-
signal:
|
|
113
|
-
}), this.config = n, this.userToken = ((
|
|
114
|
-
const { baseUrl:
|
|
115
|
-
(
|
|
112
|
+
signal: s
|
|
113
|
+
}), this.config = n, this.userToken = ((o = n.user) == null ? void 0 : o.token) || null;
|
|
114
|
+
const { baseUrl: a, headers: g } = this.constructClientOptions(
|
|
115
|
+
(e = n.user) == null ? void 0 : e.token
|
|
116
116
|
);
|
|
117
|
-
this.client = this.createOpenAPIClient({ baseUrl:
|
|
117
|
+
this.client = this.createOpenAPIClient({ baseUrl: a, headers: g });
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
class P {
|
|
121
121
|
constructor(n) {
|
|
122
|
-
this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (
|
|
123
|
-
O(this.state,
|
|
124
|
-
}, this.setPartial = (
|
|
125
|
-
if (
|
|
126
|
-
const
|
|
127
|
-
this.set(
|
|
122
|
+
this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (a) => {
|
|
123
|
+
O(this.state, a) || (this.state = a, this.notifySubscribers(a));
|
|
124
|
+
}, this.setPartial = (a) => {
|
|
125
|
+
if (a == null) return;
|
|
126
|
+
const g = { ...this.state, ...a };
|
|
127
|
+
this.set(g);
|
|
128
128
|
}, this.reset = () => {
|
|
129
129
|
this.set(this.initialState);
|
|
130
|
-
}, this.notifySubscribers = (
|
|
131
|
-
Array.from(this.subscribers).forEach((
|
|
130
|
+
}, this.notifySubscribers = (a) => {
|
|
131
|
+
Array.from(this.subscribers).forEach((o) => {
|
|
132
132
|
try {
|
|
133
|
-
a
|
|
134
|
-
} catch (
|
|
135
|
-
console.error(
|
|
133
|
+
o(a);
|
|
134
|
+
} catch (e) {
|
|
135
|
+
console.error(e);
|
|
136
136
|
}
|
|
137
137
|
});
|
|
138
|
-
}, this.subscribe = (
|
|
139
|
-
this.subscribers.delete(
|
|
138
|
+
}, this.subscribe = (a) => (this.subscribers.add(a), () => {
|
|
139
|
+
this.subscribers.delete(a);
|
|
140
140
|
}), this.state = n, this.initialState = n;
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
class
|
|
143
|
+
class R {
|
|
144
144
|
constructor() {
|
|
145
145
|
this.state = new P({
|
|
146
146
|
isPolling: !1,
|
|
@@ -148,23 +148,23 @@ class A {
|
|
|
148
148
|
}), this.abortController = new AbortController(), this.reset = () => {
|
|
149
149
|
var n;
|
|
150
150
|
this.abortController.abort("Resetting poller"), (n = this.stopPolling) == null || n.call(this), this.stopPolling = null;
|
|
151
|
-
}, this.stopPolling = null, this.startPolling = (n,
|
|
151
|
+
}, this.stopPolling = null, this.startPolling = (n, a) => {
|
|
152
152
|
if (this.stopPolling) return;
|
|
153
|
-
const
|
|
153
|
+
const g = [], o = async () => {
|
|
154
154
|
this.abortController = new AbortController(), this.state.setPartial({ isPolling: !0 });
|
|
155
155
|
try {
|
|
156
156
|
await n(this.abortController.signal);
|
|
157
|
-
} catch (
|
|
157
|
+
} catch (e) {
|
|
158
158
|
if (this.abortController.signal.aborted)
|
|
159
159
|
return;
|
|
160
|
-
console.error("Failed to poll:",
|
|
160
|
+
console.error("Failed to poll:", e), this.state.setPartial({ isError: !0 });
|
|
161
161
|
} finally {
|
|
162
162
|
this.state.setPartial({ isPolling: !1 });
|
|
163
163
|
}
|
|
164
|
-
this.abortController.signal.aborted ? console.log("Poller aborted, not scheduling anymore") :
|
|
164
|
+
this.abortController.signal.aborted ? console.log("Poller aborted, not scheduling anymore") : g.push(setTimeout(o, a));
|
|
165
165
|
};
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
o(), this.stopPolling = () => {
|
|
167
|
+
g.forEach(clearTimeout), this.state.reset();
|
|
168
168
|
};
|
|
169
169
|
};
|
|
170
170
|
}
|
|
@@ -172,7 +172,7 @@ class A {
|
|
|
172
172
|
function D(d) {
|
|
173
173
|
try {
|
|
174
174
|
const n = d();
|
|
175
|
-
return n instanceof Promise ? n.then((
|
|
175
|
+
return n instanceof Promise ? n.then((a) => ({ data: a })).catch((a) => ({ error: a })) : { data: n };
|
|
176
176
|
} catch (n) {
|
|
177
177
|
return { error: n };
|
|
178
178
|
}
|
|
@@ -180,51 +180,51 @@ function D(d) {
|
|
|
180
180
|
class L {
|
|
181
181
|
constructor({
|
|
182
182
|
api: n,
|
|
183
|
-
config:
|
|
184
|
-
sessionCtx:
|
|
185
|
-
messageCtx:
|
|
186
|
-
sessionPollingIntervalSeconds:
|
|
183
|
+
config: a,
|
|
184
|
+
sessionCtx: g,
|
|
185
|
+
messageCtx: o,
|
|
186
|
+
sessionPollingIntervalSeconds: e
|
|
187
187
|
}) {
|
|
188
|
-
this.poller = new
|
|
188
|
+
this.poller = new R(), this.registerPolling = () => {
|
|
189
189
|
this.sessionCtx.sessionState.subscribe(({ session: t }) => {
|
|
190
|
-
t != null && t.id ? this.poller.startPolling(async (
|
|
191
|
-
this.hackAndSlash(t.id,
|
|
190
|
+
t != null && t.id ? this.poller.startPolling(async (s) => {
|
|
191
|
+
this.hackAndSlash(t.id, s);
|
|
192
192
|
}, this.sessionPollingIntervalSeconds * 1e3) : this.poller.reset();
|
|
193
193
|
});
|
|
194
|
-
}, this.hackAndSlash = async (t,
|
|
195
|
-
var
|
|
194
|
+
}, this.hackAndSlash = async (t, s) => {
|
|
195
|
+
var h;
|
|
196
196
|
this.messageCtx.state.get().messages.length === 0 && this.messageCtx.state.setPartial({ isInitialFetchLoading: !0 });
|
|
197
|
-
const
|
|
197
|
+
const i = this.messageCtx.state.get().messages, c = i.length > 0 ? (h = i[i.length - 1]) == null ? void 0 : h.timestamp : void 0, { data: r } = await this.api.pollSessionAndHistory({
|
|
198
198
|
sessionId: t,
|
|
199
|
-
abortSignal:
|
|
200
|
-
lastMessageTimestamp:
|
|
199
|
+
abortSignal: s,
|
|
200
|
+
lastMessageTimestamp: c
|
|
201
201
|
});
|
|
202
202
|
if (r != null && r.session && (this.sessionCtx.sessionState.setPartial({ session: r.session }), this.sessionCtx.setSessions([r.session])), r != null && r.history && r.history.length > 0) {
|
|
203
|
-
const
|
|
204
|
-
(x) => !
|
|
203
|
+
const l = this.messageCtx.state.get().messages, f = r.history.map(this.mapHistoryToMessage).filter(
|
|
204
|
+
(x) => !l.some((p) => p.id === x.id)
|
|
205
205
|
);
|
|
206
206
|
this.messageCtx.state.setPartial({
|
|
207
|
-
messages: [...
|
|
207
|
+
messages: [...l, ...f]
|
|
208
208
|
});
|
|
209
209
|
}
|
|
210
210
|
this.messageCtx.state.get().isInitialFetchLoading && this.messageCtx.state.setPartial({ isInitialFetchLoading: !1 });
|
|
211
211
|
}, this.mapHistoryToMessage = (t) => {
|
|
212
|
-
var
|
|
213
|
-
const
|
|
212
|
+
var c, r;
|
|
213
|
+
const s = {
|
|
214
214
|
id: t.publicId,
|
|
215
215
|
timestamp: t.sentAt || "",
|
|
216
216
|
attachments: t.attachments || void 0
|
|
217
217
|
};
|
|
218
218
|
if (t.sender.kind === "user")
|
|
219
219
|
return {
|
|
220
|
-
...
|
|
220
|
+
...s,
|
|
221
221
|
type: "FROM_USER",
|
|
222
222
|
content: t.content.text || "",
|
|
223
223
|
deliveredAt: t.sentAt || ""
|
|
224
224
|
};
|
|
225
225
|
if (t.sender.kind === "agent")
|
|
226
226
|
return {
|
|
227
|
-
...
|
|
227
|
+
...s,
|
|
228
228
|
type: "FROM_AGENT",
|
|
229
229
|
component: "agent_message",
|
|
230
230
|
data: {
|
|
@@ -237,87 +237,87 @@ class L {
|
|
|
237
237
|
isAi: !1
|
|
238
238
|
}
|
|
239
239
|
};
|
|
240
|
-
const
|
|
240
|
+
const i = t.actionCalls && t.actionCalls.length > 0 ? t.actionCalls[t.actionCalls.length - 1] : void 0;
|
|
241
241
|
return {
|
|
242
|
-
...
|
|
242
|
+
...s,
|
|
243
243
|
type: "FROM_BOT",
|
|
244
244
|
component: "bot_message",
|
|
245
245
|
agent: {
|
|
246
246
|
id: null,
|
|
247
|
-
name: ((
|
|
247
|
+
name: ((c = this.config.bot) == null ? void 0 : c.name) || "",
|
|
248
248
|
isAi: !0,
|
|
249
249
|
avatar: ((r = this.config.bot) == null ? void 0 : r.avatar) || ""
|
|
250
250
|
},
|
|
251
251
|
data: {
|
|
252
252
|
message: t.content.text || "",
|
|
253
|
-
action:
|
|
254
|
-
name:
|
|
255
|
-
data: this.extractActionResult(
|
|
253
|
+
action: i ? {
|
|
254
|
+
name: i.actionName,
|
|
255
|
+
data: this.extractActionResult(i)
|
|
256
256
|
} : void 0
|
|
257
257
|
}
|
|
258
258
|
};
|
|
259
259
|
}, this.extractActionResult = (t) => {
|
|
260
|
-
const
|
|
261
|
-
if (
|
|
262
|
-
if ("responseBodyText" in
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
260
|
+
const s = t.result;
|
|
261
|
+
if (s === null || typeof s != "object") return s;
|
|
262
|
+
if ("responseBodyText" in s && typeof s.responseBodyText == "string") {
|
|
263
|
+
const i = s.responseBodyText, c = D(() => JSON.parse(i)).data;
|
|
264
|
+
if (c) return c;
|
|
265
265
|
}
|
|
266
266
|
return t.result;
|
|
267
|
-
}, this.api = n, this.config =
|
|
267
|
+
}, this.api = n, this.config = a, this.sessionCtx = g, this.messageCtx = o, this.sessionPollingIntervalSeconds = e, this.registerPolling();
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
class B {
|
|
271
271
|
constructor({
|
|
272
272
|
config: n,
|
|
273
|
-
api:
|
|
274
|
-
storageCtx:
|
|
273
|
+
api: a,
|
|
274
|
+
storageCtx: g
|
|
275
275
|
}) {
|
|
276
|
-
var
|
|
276
|
+
var o;
|
|
277
277
|
this.shouldCollectData = () => {
|
|
278
|
-
var
|
|
279
|
-
return !!(!((
|
|
278
|
+
var e;
|
|
279
|
+
return !!(!((e = this.state.get().contact) != null && e.token) && this.config.collectUserData);
|
|
280
280
|
}, this.autoCreateUnverifiedUserIfNotExists = async () => {
|
|
281
|
-
var
|
|
282
|
-
if (!((
|
|
283
|
-
if (this.config.collectUserData && !((
|
|
284
|
-
if ((
|
|
281
|
+
var e, t, s, i, c, r, h, l, f, x, p, b, v, u;
|
|
282
|
+
if (!((e = this.config.user) != null && e.token)) {
|
|
283
|
+
if (this.config.collectUserData && !((s = (t = this.config.user) == null ? void 0 : t.data) != null && s.email)) {
|
|
284
|
+
if ((i = this.config.extraDataCollectionFields) != null && i.length)
|
|
285
285
|
return;
|
|
286
|
-
const
|
|
287
|
-
|
|
286
|
+
const S = await ((c = this.storageCtx) == null ? void 0 : c.getContactToken());
|
|
287
|
+
S && await this.setUnverifiedContact(S);
|
|
288
288
|
return;
|
|
289
289
|
}
|
|
290
|
-
if (!((
|
|
291
|
-
const
|
|
292
|
-
if (
|
|
293
|
-
await this.setUnverifiedContact(
|
|
290
|
+
if (!((h = (r = this.config.user) == null ? void 0 : r.data) != null && h.email)) {
|
|
291
|
+
const S = await ((l = this.storageCtx) == null ? void 0 : l.getContactToken());
|
|
292
|
+
if (S) {
|
|
293
|
+
await this.setUnverifiedContact(S);
|
|
294
294
|
return;
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
await this.createUnverifiedContact({
|
|
298
|
-
email: (x = (
|
|
298
|
+
email: (x = (f = this.config.user) == null ? void 0 : f.data) == null ? void 0 : x.email,
|
|
299
299
|
non_verified_name: ((b = (p = this.config.user) == null ? void 0 : p.data) == null ? void 0 : b.name) || "Anonymous",
|
|
300
300
|
non_verified_custom_data: (u = (v = this.config.user) == null ? void 0 : v.data) == null ? void 0 : u.customData
|
|
301
301
|
});
|
|
302
302
|
}
|
|
303
|
-
}, this.createUnverifiedContact = async (
|
|
303
|
+
}, this.createUnverifiedContact = async (e, t) => {
|
|
304
304
|
this.state.setPartial({ extraCollectedData: t });
|
|
305
305
|
try {
|
|
306
306
|
this.state.setPartial({
|
|
307
307
|
isCreatingUnverifiedContact: !0,
|
|
308
308
|
isErrorCreatingUnverifiedContact: !1
|
|
309
309
|
});
|
|
310
|
-
const { data:
|
|
311
|
-
|
|
310
|
+
const { data: s } = await this.api.createUnverifiedContact(e);
|
|
311
|
+
s != null && s.token ? await this.setUnverifiedContact(s.token) : this.state.setPartial({ isErrorCreatingUnverifiedContact: !0 });
|
|
312
312
|
} finally {
|
|
313
313
|
this.state.setPartial({ isCreatingUnverifiedContact: !1 });
|
|
314
314
|
}
|
|
315
|
-
}, this.setUnverifiedContact = async (
|
|
316
|
-
var
|
|
317
|
-
const t = await ((
|
|
318
|
-
this.api.setAuthToken(
|
|
319
|
-
}, this.config = n, this.storageCtx =
|
|
320
|
-
contact: (
|
|
315
|
+
}, this.setUnverifiedContact = async (e) => {
|
|
316
|
+
var i, c, r, h;
|
|
317
|
+
const t = await ((i = this.storageCtx) == null ? void 0 : i.getExternalContactId()), s = ((c = this.config.user) == null ? void 0 : c.externalId) || t || E();
|
|
318
|
+
this.api.setAuthToken(e), await ((r = this.storageCtx) == null ? void 0 : r.setContactToken(e)), await ((h = this.storageCtx) == null ? void 0 : h.setExternalContactId(s)), this.state.setPartial({ contact: { token: e, externalId: s } });
|
|
319
|
+
}, this.config = n, this.storageCtx = g, this.api = a, this.state = new P({
|
|
320
|
+
contact: (o = n.user) != null && o.token ? {
|
|
321
321
|
token: n.user.token,
|
|
322
322
|
// Set optional externalId from config... not local storage
|
|
323
323
|
externalId: n.user.externalId
|
|
@@ -334,12 +334,13 @@ function y() {
|
|
|
334
334
|
class q {
|
|
335
335
|
constructor({
|
|
336
336
|
api: n,
|
|
337
|
-
contactCtx:
|
|
338
|
-
sessionsPollingIntervalSeconds:
|
|
337
|
+
contactCtx: a,
|
|
338
|
+
sessionsPollingIntervalSeconds: g
|
|
339
339
|
}) {
|
|
340
|
-
this.sessionsRefresher = new
|
|
340
|
+
this.sessionsRefresher = new R(), this.sessionState = new P({
|
|
341
341
|
session: null,
|
|
342
|
-
isCreatingSession: !1
|
|
342
|
+
isCreatingSession: !1,
|
|
343
|
+
isResolvingSession: !1
|
|
343
344
|
}), this.sessionsState = new P({
|
|
344
345
|
data: [],
|
|
345
346
|
cursor: void 0,
|
|
@@ -352,73 +353,75 @@ class q {
|
|
|
352
353
|
}), this.reset = async () => {
|
|
353
354
|
this.sessionState.reset();
|
|
354
355
|
}, this.registerSessionsRefresherWrapper = () => {
|
|
355
|
-
var
|
|
356
|
+
var o;
|
|
356
357
|
// If the widget config was initially provided with a contact token, no state change would be triggered, so we just fetch
|
|
357
|
-
(
|
|
358
|
-
|
|
358
|
+
(o = this.contactCtx.state.get().contact) != null && o.token && !this.sessionsState.get().didStartInitialFetch ? this.registerSessionsRefresher() : this.contactCtx.state.subscribe(({ contact: e }) => {
|
|
359
|
+
e != null && e.token && !this.sessionsState.get().didStartInitialFetch && this.registerSessionsRefresher();
|
|
359
360
|
});
|
|
360
361
|
}, this.registerSessionsRefresher = () => {
|
|
361
362
|
this.sessionsRefresher.startPolling(async () => {
|
|
362
363
|
this.sessionsState.get().didStartInitialFetch === !1 && this.sessionsState.setPartial({ didStartInitialFetch: !0 }), await this.refreshSessions(), this.sessionsState.get().isInitialFetchLoading === !0 && this.sessionsState.setPartial({ isInitialFetchLoading: !1 });
|
|
363
364
|
}, this.sessionsPollingIntervalSeconds * 1e3);
|
|
364
365
|
}, this.createSession = async () => {
|
|
365
|
-
var
|
|
366
|
+
var s;
|
|
366
367
|
this.sessionState.setPartial({ session: null, isCreatingSession: !0 });
|
|
367
|
-
const
|
|
368
|
-
customData:
|
|
369
|
-
external_id:
|
|
368
|
+
const o = (s = this.contactCtx.state.get().contact) == null ? void 0 : s.externalId, { data: e, error: t } = await this.api.createSession({
|
|
369
|
+
customData: o ? {
|
|
370
|
+
external_id: o
|
|
370
371
|
} : void 0
|
|
371
372
|
});
|
|
372
|
-
return
|
|
373
|
+
return e ? (this.sessionState.setPartial({ session: e, isCreatingSession: !1 }), e) : (this.sessionState.setPartial({ isCreatingSession: !1 }), console.error("Failed to create session:", t), null);
|
|
373
374
|
}, this.loadMoreSessions = async () => {
|
|
374
375
|
if (this.sessionsState.get().isLastPage) return;
|
|
375
|
-
const { data:
|
|
376
|
+
const { data: o } = await this.getSessions({
|
|
376
377
|
cursor: this.sessionsState.get().cursor
|
|
377
378
|
});
|
|
378
|
-
if (
|
|
379
|
-
const t = [...this.sessionsState.get().data, ...
|
|
380
|
-
(
|
|
379
|
+
if (o) {
|
|
380
|
+
const t = [...this.sessionsState.get().data, ...o.items].filter(
|
|
381
|
+
(s, i, c) => i === c.findIndex((r) => s.id === r.id)
|
|
381
382
|
);
|
|
382
383
|
this.sessionsState.setPartial({
|
|
383
384
|
data: t,
|
|
384
|
-
cursor:
|
|
385
|
-
isLastPage:
|
|
385
|
+
cursor: o.next || void 0,
|
|
386
|
+
isLastPage: o.next === null
|
|
386
387
|
});
|
|
387
388
|
}
|
|
388
|
-
}, this.getSessions = async ({ cursor:
|
|
389
|
-
var t,
|
|
389
|
+
}, this.getSessions = async ({ cursor: o }) => {
|
|
390
|
+
var t, s;
|
|
390
391
|
if (!((t = this.contactCtx.state.get().contact) != null && t.token)) return { data: null };
|
|
391
|
-
const
|
|
392
|
+
const e = (s = this.contactCtx.state.get().contact) == null ? void 0 : s.externalId;
|
|
392
393
|
return await this.api.getSessions({
|
|
393
|
-
cursor:
|
|
394
|
-
filters:
|
|
395
|
-
external_id:
|
|
394
|
+
cursor: o,
|
|
395
|
+
filters: e ? {
|
|
396
|
+
external_id: e
|
|
396
397
|
} : {}
|
|
397
398
|
});
|
|
398
|
-
}, this.setSessions = (
|
|
399
|
-
const
|
|
400
|
-
(t,
|
|
399
|
+
}, this.setSessions = (o) => {
|
|
400
|
+
const e = [...o, ...this.sessionsState.get().data].filter(
|
|
401
|
+
(t, s, i) => s === i.findIndex((c) => t.id === c.id)
|
|
401
402
|
);
|
|
402
|
-
this.sessionsState.setPartial({ data:
|
|
403
|
+
this.sessionsState.setPartial({ data: e });
|
|
403
404
|
}, this.refreshSessions = async () => {
|
|
404
|
-
const { data:
|
|
405
|
-
|
|
405
|
+
const { data: o } = await this.getSessions({ cursor: void 0 });
|
|
406
|
+
o && this.setSessions(o.items);
|
|
406
407
|
}, this.resolveSession = async () => {
|
|
407
|
-
const
|
|
408
|
-
if (!
|
|
409
|
-
|
|
410
|
-
|
|
408
|
+
const o = this.sessionState.get().session;
|
|
409
|
+
if (!o || !o.isOpened)
|
|
410
|
+
return { success: !1, error: "Session is not opened" };
|
|
411
|
+
this.sessionState.setPartial({ isResolvingSession: !0 });
|
|
412
|
+
const { data: e, error: t } = await this.api.resolveSession({
|
|
413
|
+
session_id: o.id
|
|
411
414
|
});
|
|
412
|
-
|
|
413
|
-
}, this.api = n, this.contactCtx =
|
|
415
|
+
return e ? (this.sessionState.setPartial({ session: e, isResolvingSession: !1 }), { success: !0, data: e }) : (this.sessionState.setPartial({ isResolvingSession: !1 }), { success: !1, error: t });
|
|
416
|
+
}, this.api = n, this.contactCtx = a, this.sessionsPollingIntervalSeconds = g, this.registerSessionsRefresherWrapper();
|
|
414
417
|
}
|
|
415
418
|
}
|
|
416
419
|
class $ {
|
|
417
420
|
constructor({
|
|
418
421
|
config: n,
|
|
419
|
-
api:
|
|
420
|
-
sessionCtx:
|
|
421
|
-
contactCtx:
|
|
422
|
+
api: a,
|
|
423
|
+
sessionCtx: g,
|
|
424
|
+
contactCtx: o
|
|
422
425
|
}) {
|
|
423
426
|
this.state = new P({
|
|
424
427
|
messages: [],
|
|
@@ -427,15 +430,15 @@ class $ {
|
|
|
427
430
|
isInitialFetchLoading: !1
|
|
428
431
|
}), this.sendMessageAbortController = new AbortController(), this.reset = () => {
|
|
429
432
|
this.sendMessageAbortController.abort("Resetting chat"), this.state.reset();
|
|
430
|
-
}, this.sendMessage = async (
|
|
431
|
-
var r,
|
|
432
|
-
if (!
|
|
433
|
+
}, this.sendMessage = async (e) => {
|
|
434
|
+
var r, h, l, f, x, p, b, v;
|
|
435
|
+
if (!e.content.trim() && (!e.attachments || e.attachments.length === 0)) {
|
|
433
436
|
console.warn("Cannot send an empty message of no content or attachments");
|
|
434
437
|
return;
|
|
435
438
|
}
|
|
436
|
-
const t = this.state.get().isSendingMessage,
|
|
437
|
-
if (
|
|
438
|
-
|
|
439
|
+
const t = this.state.get().isSendingMessage, s = ((r = this.sessionCtx.sessionState.get().session) == null ? void 0 : r.assignee.kind) === "ai", i = this.state.get().messages, c = i.length > 0 ? i[i.length - 1] : void 0;
|
|
440
|
+
if (s && t || // If last message is from user, then bot response did not arrive yet
|
|
441
|
+
s && (c == null ? void 0 : c.type) === "FROM_USER") {
|
|
439
442
|
console.warn("Cannot send messages while awaiting AI response");
|
|
440
443
|
return;
|
|
441
444
|
}
|
|
@@ -443,21 +446,21 @@ class $ {
|
|
|
443
446
|
try {
|
|
444
447
|
this.state.setPartial({ isSendingMessage: !0 });
|
|
445
448
|
const u = this.toUserMessage(
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
),
|
|
449
|
+
e.content.trim(),
|
|
450
|
+
e.attachments || void 0
|
|
451
|
+
), S = this.state.get().messages;
|
|
449
452
|
if (this.state.setPartial({
|
|
450
|
-
messages: [...
|
|
451
|
-
}), !((
|
|
453
|
+
messages: [...S, u]
|
|
454
|
+
}), !((h = this.sessionCtx.sessionState.get().session) != null && h.id)) {
|
|
452
455
|
if (!await this.sessionCtx.createSession()) {
|
|
453
456
|
console.error("Failed to create session");
|
|
454
457
|
return;
|
|
455
458
|
}
|
|
456
459
|
this.sessionCtx.refreshSessions();
|
|
457
460
|
}
|
|
458
|
-
const k = (
|
|
461
|
+
const k = (l = this.sessionCtx.sessionState.get().session) == null ? void 0 : l.id;
|
|
459
462
|
if (!k) return;
|
|
460
|
-
const { data:
|
|
463
|
+
const { data: C } = await this.api.sendMessage(
|
|
461
464
|
{
|
|
462
465
|
uuid: u.id,
|
|
463
466
|
bot_token: this.config.token,
|
|
@@ -466,36 +469,36 @@ class $ {
|
|
|
466
469
|
body_properties: this.config.bodyProperties,
|
|
467
470
|
session_id: k,
|
|
468
471
|
content: u.content,
|
|
469
|
-
attachments:
|
|
472
|
+
attachments: e.attachments,
|
|
470
473
|
clientContext: this.config.context,
|
|
471
474
|
custom_data: {
|
|
472
475
|
...this.config.messageCustomData || {},
|
|
473
|
-
...
|
|
476
|
+
...e.customData || {}
|
|
474
477
|
},
|
|
475
478
|
language: this.config.language
|
|
476
479
|
},
|
|
477
480
|
this.sendMessageAbortController.signal
|
|
478
481
|
);
|
|
479
|
-
if (
|
|
480
|
-
const w = this.toBotMessage(
|
|
482
|
+
if (C != null && C.success) {
|
|
483
|
+
const w = this.toBotMessage(C);
|
|
481
484
|
if (w) {
|
|
482
485
|
const I = this.state.get().messages;
|
|
483
486
|
if (!!I.some(
|
|
484
|
-
(
|
|
487
|
+
(A) => A.id === w.id
|
|
485
488
|
)) {
|
|
486
489
|
this.state.setPartial({
|
|
487
|
-
lastAIResMightSolveUserIssue: ((
|
|
490
|
+
lastAIResMightSolveUserIssue: ((f = C.autopilotResponse) == null ? void 0 : f.mightSolveUserIssue) || ((x = C.uiResponse) == null ? void 0 : x.mightSolveUserIssue)
|
|
488
491
|
});
|
|
489
492
|
return;
|
|
490
493
|
}
|
|
491
494
|
this.state.setPartial({
|
|
492
495
|
messages: [...I, w],
|
|
493
|
-
lastAIResMightSolveUserIssue: ((p =
|
|
496
|
+
lastAIResMightSolveUserIssue: ((p = C.autopilotResponse) == null ? void 0 : p.mightSolveUserIssue) || ((b = C.uiResponse) == null ? void 0 : b.mightSolveUserIssue)
|
|
494
497
|
});
|
|
495
498
|
}
|
|
496
499
|
} else {
|
|
497
500
|
const w = this.toBotErrorMessage(
|
|
498
|
-
((v =
|
|
501
|
+
((v = C == null ? void 0 : C.error) == null ? void 0 : v.message) || "Unknown error occurred"
|
|
499
502
|
), I = this.state.get().messages;
|
|
500
503
|
this.state.setPartial({
|
|
501
504
|
messages: [...I, w]
|
|
@@ -506,27 +509,27 @@ class $ {
|
|
|
506
509
|
} finally {
|
|
507
510
|
this.state.setPartial({ isSendingMessage: !1 });
|
|
508
511
|
}
|
|
509
|
-
}, this.toUserMessage = (
|
|
510
|
-
const
|
|
511
|
-
const
|
|
512
|
-
return this.state.get().messages.length === 0 &&
|
|
512
|
+
}, this.toUserMessage = (e, t) => {
|
|
513
|
+
const s = (() => {
|
|
514
|
+
const i = this.contactCtx.state.get().extraCollectedData;
|
|
515
|
+
return this.state.get().messages.length === 0 && i && Object.keys(i).length > 0 ? `${Object.entries(i).filter(([r, h]) => !!h).map(([r, h]) => `${r}: ${h}`).join(`
|
|
513
516
|
`)}
|
|
514
517
|
|
|
515
|
-
${
|
|
518
|
+
${e}` : e;
|
|
516
519
|
})();
|
|
517
520
|
return {
|
|
518
521
|
id: y(),
|
|
519
522
|
type: "FROM_USER",
|
|
520
|
-
content:
|
|
523
|
+
content: s,
|
|
521
524
|
deliveredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
522
525
|
attachments: t,
|
|
523
526
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
524
527
|
};
|
|
525
|
-
}, this.toBotMessage = (
|
|
528
|
+
}, this.toBotMessage = (e) => {
|
|
526
529
|
var t;
|
|
527
|
-
return
|
|
530
|
+
return e.success && e.autopilotResponse ? {
|
|
528
531
|
type: "FROM_BOT",
|
|
529
|
-
id:
|
|
532
|
+
id: e.autopilotResponse.id || y(),
|
|
530
533
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
531
534
|
component: "bot_message",
|
|
532
535
|
agent: this.config.bot ? {
|
|
@@ -536,54 +539,64 @@ ${s}` : s;
|
|
|
536
539
|
id: null
|
|
537
540
|
} : void 0,
|
|
538
541
|
data: {
|
|
539
|
-
message:
|
|
540
|
-
action: (t =
|
|
541
|
-
name:
|
|
542
|
-
data:
|
|
542
|
+
message: e.autopilotResponse.value.content,
|
|
543
|
+
action: (t = e.uiResponse) != null && t.value.name ? {
|
|
544
|
+
name: e.uiResponse.value.name,
|
|
545
|
+
data: e.uiResponse.value.request_response
|
|
543
546
|
} : void 0
|
|
544
547
|
}
|
|
545
548
|
} : null;
|
|
546
|
-
}, this.toBotErrorMessage = (
|
|
549
|
+
}, this.toBotErrorMessage = (e) => ({
|
|
547
550
|
type: "FROM_BOT",
|
|
548
551
|
id: y(),
|
|
549
552
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
550
553
|
component: "TEXT",
|
|
551
554
|
data: {
|
|
552
|
-
message:
|
|
555
|
+
message: e,
|
|
553
556
|
variant: "error",
|
|
554
557
|
action: void 0
|
|
555
558
|
}
|
|
556
|
-
}), this.config = n, this.api =
|
|
559
|
+
}), this.config = n, this.api = a, this.sessionCtx = g, this.contactCtx = o;
|
|
557
560
|
}
|
|
558
561
|
}
|
|
559
562
|
class N {
|
|
560
563
|
constructor({
|
|
561
564
|
config: n,
|
|
562
|
-
contactCtx:
|
|
563
|
-
sessionCtx:
|
|
564
|
-
resetChat:
|
|
565
|
+
contactCtx: a,
|
|
566
|
+
sessionCtx: g,
|
|
567
|
+
resetChat: o
|
|
565
568
|
}) {
|
|
569
|
+
var e;
|
|
566
570
|
this.registerRoutingListener = () => {
|
|
567
|
-
this.contactCtx.state.subscribe(({ contact:
|
|
568
|
-
|
|
571
|
+
this.contactCtx.state.subscribe(({ contact: t }) => {
|
|
572
|
+
var s;
|
|
573
|
+
t != null && t.token && this.state.get().screen === "welcome" && this.state.setPartial({
|
|
574
|
+
screen: (s = this.config.router) != null && s.chatScreenOnly ? "chat" : "sessions"
|
|
575
|
+
});
|
|
569
576
|
}), this.sessionCtx.sessionsState.subscribe(
|
|
570
|
-
({ isInitialFetchLoading:
|
|
571
|
-
var
|
|
572
|
-
|
|
577
|
+
({ isInitialFetchLoading: t, data: s }) => {
|
|
578
|
+
var i, c, r, h;
|
|
579
|
+
if ((i = this.config.router) != null && i.chatScreenOnly && // Do not route to a chat if we are currently inside one already
|
|
580
|
+
// This also applies to newly created sessions; the new session will be in `sessionState` before it is refreshed and included in `sessionsState`
|
|
581
|
+
!((c = this.sessionCtx.sessionState.get().session) != null && c.id)) {
|
|
582
|
+
const l = (r = s.find((f) => f.isOpened)) == null ? void 0 : r.id;
|
|
583
|
+
return l ? this.toChatScreen(l) : void 0;
|
|
584
|
+
}
|
|
585
|
+
s.length || ((h = this.config.router) == null ? void 0 : h.goToChatIfNoSessions) !== !1 && !t && this.state.get().screen !== "chat" && this.toChatScreen();
|
|
573
586
|
}
|
|
574
587
|
);
|
|
575
588
|
}, this.toSessionsScreen = () => {
|
|
576
589
|
this.resetChat(), this.state.setPartial({ screen: "sessions" });
|
|
577
|
-
}, this.toChatScreen = (
|
|
578
|
-
if (this.resetChat(),
|
|
579
|
-
const
|
|
580
|
-
if (!
|
|
581
|
-
this.sessionCtx.sessionState.setPartial({ session:
|
|
590
|
+
}, this.toChatScreen = (t) => {
|
|
591
|
+
if (this.resetChat(), t) {
|
|
592
|
+
const s = this.sessionCtx.sessionsState.get().data.find((i) => i.id === t);
|
|
593
|
+
if (!s) return;
|
|
594
|
+
this.sessionCtx.sessionState.setPartial({ session: s });
|
|
582
595
|
}
|
|
583
596
|
this.state.setPartial({ screen: "chat" });
|
|
584
|
-
}, this.state = new P({
|
|
585
|
-
screen:
|
|
586
|
-
}), this.
|
|
597
|
+
}, this.config = n, this.contactCtx = a, this.sessionCtx = g, this.resetChat = o, this.state = new P({
|
|
598
|
+
screen: this.contactCtx.shouldCollectData() ? "welcome" : (e = this.config.router) != null && e.chatScreenOnly ? "chat" : "sessions"
|
|
599
|
+
}), this.registerRoutingListener();
|
|
587
600
|
}
|
|
588
601
|
}
|
|
589
602
|
class H {
|
|
@@ -591,32 +604,32 @@ class H {
|
|
|
591
604
|
this.KEYS = {
|
|
592
605
|
contactToken: "opencx__widget__contactToken",
|
|
593
606
|
externalContactId: "opencx__widget__externalContactId"
|
|
594
|
-
}, this.setContactToken = async (
|
|
595
|
-
await this.storage.set(this.KEYS.contactToken,
|
|
596
|
-
}, this.getContactToken = async () => this.storage.get(this.KEYS.contactToken), this.setExternalContactId = async (
|
|
597
|
-
await this.storage.set(this.KEYS.externalContactId,
|
|
607
|
+
}, this.setContactToken = async (a) => {
|
|
608
|
+
await this.storage.set(this.KEYS.contactToken, a);
|
|
609
|
+
}, this.getContactToken = async () => this.storage.get(this.KEYS.contactToken), this.setExternalContactId = async (a) => {
|
|
610
|
+
await this.storage.set(this.KEYS.externalContactId, a);
|
|
598
611
|
}, this.getExternalContactId = async () => this.storage.get(this.KEYS.externalContactId), this.storage = n;
|
|
599
612
|
}
|
|
600
613
|
}
|
|
601
|
-
const
|
|
614
|
+
const m = class m {
|
|
602
615
|
constructor({
|
|
603
616
|
config: n,
|
|
604
|
-
storage:
|
|
617
|
+
storage: a
|
|
605
618
|
}) {
|
|
606
619
|
if (this.resetChat = () => {
|
|
607
620
|
this.sessionCtx.reset(), this.messageCtx.reset();
|
|
608
|
-
}, !
|
|
621
|
+
}, !m.pollingIntervalsSeconds)
|
|
609
622
|
throw Error(
|
|
610
623
|
"Widget polling values are not defined, did you call WidgetCtx.initialize()"
|
|
611
624
|
);
|
|
612
|
-
this.config = n, this.api = new T({ config: n }), this.storageCtx =
|
|
625
|
+
this.config = n, this.api = new T({ config: n }), this.storageCtx = a ? new H({ storage: a }) : void 0, this.contactCtx = new B({
|
|
613
626
|
api: this.api,
|
|
614
627
|
config: this.config,
|
|
615
628
|
storageCtx: this.storageCtx
|
|
616
629
|
}), this.sessionCtx = new q({
|
|
617
630
|
api: this.api,
|
|
618
631
|
contactCtx: this.contactCtx,
|
|
619
|
-
sessionsPollingIntervalSeconds:
|
|
632
|
+
sessionsPollingIntervalSeconds: m.pollingIntervalsSeconds.sessions
|
|
620
633
|
}), this.messageCtx = new $({
|
|
621
634
|
config: this.config,
|
|
622
635
|
api: this.api,
|
|
@@ -627,7 +640,7 @@ const S = class S {
|
|
|
627
640
|
config: this.config,
|
|
628
641
|
sessionCtx: this.sessionCtx,
|
|
629
642
|
messageCtx: this.messageCtx,
|
|
630
|
-
sessionPollingIntervalSeconds:
|
|
643
|
+
sessionPollingIntervalSeconds: m.pollingIntervalsSeconds.session
|
|
631
644
|
}), this.routerCtx = new N({
|
|
632
645
|
config: this.config,
|
|
633
646
|
contactCtx: this.contactCtx,
|
|
@@ -636,25 +649,25 @@ const S = class S {
|
|
|
636
649
|
});
|
|
637
650
|
}
|
|
638
651
|
};
|
|
639
|
-
|
|
652
|
+
m.pollingIntervalsSeconds = null, m.initialize = async ({
|
|
640
653
|
config: n,
|
|
641
|
-
storage:
|
|
654
|
+
storage: a
|
|
642
655
|
}) => {
|
|
643
|
-
var
|
|
644
|
-
const
|
|
656
|
+
var o, e;
|
|
657
|
+
const g = await new T({
|
|
645
658
|
config: n
|
|
646
659
|
}).getExternalWidgetConfig();
|
|
647
|
-
return
|
|
648
|
-
session: ((
|
|
649
|
-
sessions: ((
|
|
650
|
-
}, new
|
|
660
|
+
return m.pollingIntervalsSeconds = {
|
|
661
|
+
session: ((o = g.data) == null ? void 0 : o.sessionPollingIntervalSeconds) || 10,
|
|
662
|
+
sessions: ((e = g.data) == null ? void 0 : e.sessionsPollingIntervalSeconds) || 60
|
|
663
|
+
}, new m({
|
|
651
664
|
config: n,
|
|
652
|
-
storage:
|
|
665
|
+
storage: a
|
|
653
666
|
});
|
|
654
667
|
};
|
|
655
|
-
let U =
|
|
668
|
+
let U = m;
|
|
656
669
|
export {
|
|
657
670
|
P,
|
|
658
671
|
U as W
|
|
659
672
|
};
|
|
660
|
-
//# sourceMappingURL=widget.ctx-
|
|
673
|
+
//# sourceMappingURL=widget.ctx-DFFwNHvy.js.map
|