@opencx/widget 2.4.4 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -30
- package/dist/basic.cjs +74 -74
- package/dist/basic.cjs.map +1 -1
- package/dist/basic.js +9385 -9395
- package/dist/basic.js.map +1 -1
- package/dist/core/types/messages.d.ts +11 -1
- package/dist/core/types/schemas-v2.d.ts +3 -3
- package/dist/core/utils/genUuid.d.ts +1 -0
- package/dist/genUuid-BkZtn1k9.cjs +2 -0
- package/dist/genUuid-BkZtn1k9.cjs.map +1 -0
- package/dist/{schemas-v2-DZ3nwfID.js → genUuid-CDpI3ugS.js} +17 -19
- package/dist/genUuid-CDpI3ugS.js.map +1 -0
- package/dist/index-1bY4_hBw.cjs +18 -0
- package/dist/index-1bY4_hBw.cjs.map +1 -0
- package/dist/{index-B6Q20SQP.js → index-D84Xc70r.js} +327 -344
- package/dist/index-D84Xc70r.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +141 -131
- package/dist/index.js.map +1 -1
- package/dist/package.json.d.ts +2 -1
- package/dist/react-web/utils/getters.d.ts +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +34 -12
- package/dist/react.js.map +1 -1
- package/dist/src/@components/BotOrAgentMessage.d.ts +9 -0
- package/dist/src/@components/BotOrAgentMessageGroup.d.ts +7 -0
- package/dist/src/@components/{BotMessageWrapper.d.ts → BotOrAgentMessageWrapper.d.ts} +1 -1
- package/dist/src/@components/index.d.ts +2 -2
- package/dist/src/components/UserMessageGroup.d.ts +5 -0
- package/dist/src/designs/basic/screens/chat-screen/ChatMain.d.ts +2 -0
- package/dist/src/designs/basic/utils/group-messages-by-type.d.ts +5 -0
- package/dist/style.css +1 -1
- package/dist-embed/script.js +134 -144
- package/dist-embed/script.js.map +1 -1
- package/package.json +2 -1
- package/dist/index-B6Q20SQP.js.map +0 -1
- package/dist/index-DAb3AX4O.cjs +0 -18
- package/dist/index-DAb3AX4O.cjs.map +0 -1
- package/dist/schemas-v2-BiJWHypc.cjs +0 -2
- package/dist/schemas-v2-BiJWHypc.cjs.map +0 -1
- package/dist/schemas-v2-DZ3nwfID.js.map +0 -1
- package/dist/src/@components/BotMessage.d.ts +0 -9
- package/dist/src/components/userMessage.d.ts +0 -8
package/dist/index.js
CHANGED
|
@@ -3,28 +3,28 @@ var D = (t) => {
|
|
|
3
3
|
throw TypeError(t);
|
|
4
4
|
};
|
|
5
5
|
var B = (t, e, s) => e in t ? j(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var h = (t, e, s) => B(t, typeof e != "symbol" ? e + "" : e, s), R = (t, e, s) => e.has(t) || D("Cannot " + s);
|
|
7
|
+
var S = (t, e, s) => (R(t, e, "read from private field"), s ? s.call(t) : e.get(t)), M = (t, e, s) => e.has(t) ? D("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, s), _ = (t, e, s, i) => (R(t, e, "write to private field"), i ? i.call(t, s) : e.set(t, s), s);
|
|
8
8
|
import H from "lodash.isequal";
|
|
9
|
-
import { g as
|
|
10
|
-
import { M as me, c as ge } from "./
|
|
11
|
-
var G = /* @__PURE__ */ ((t) => (t.INIT = "init", t.STATE_CHANGE = "stateChange", t.BEFORE_UPDATE = "beforeUpdate", t.AFTER_UPDATE = "afterUpdate", t.DESTROY = "destroy", t.ERROR = "error", t))(G || {}), y,
|
|
9
|
+
import { g as L } from "./genUuid-CDpI3ugS.js";
|
|
10
|
+
import { M as me, c as ge } from "./genUuid-CDpI3ugS.js";
|
|
11
|
+
var G = /* @__PURE__ */ ((t) => (t.INIT = "init", t.STATE_CHANGE = "stateChange", t.BEFORE_UPDATE = "beforeUpdate", t.AFTER_UPDATE = "afterUpdate", t.DESTROY = "destroy", t.ERROR = "error", t))(G || {}), y, T;
|
|
12
12
|
class C {
|
|
13
13
|
constructor(e) {
|
|
14
|
-
|
|
14
|
+
h(this, "subscribers", /* @__PURE__ */ new Set());
|
|
15
15
|
M(this, y);
|
|
16
|
-
|
|
17
|
-
M(this,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
16
|
+
h(this, "initialState");
|
|
17
|
+
M(this, T);
|
|
18
|
+
h(this, "lifecycleListeners", /* @__PURE__ */ new Map());
|
|
19
|
+
h(this, "emitLifecycle", (e, s) => {
|
|
20
|
+
const i = this.lifecycleListeners.get(e);
|
|
21
|
+
if (i) {
|
|
22
22
|
const m = {
|
|
23
23
|
type: e,
|
|
24
24
|
timestamp: Date.now(),
|
|
25
25
|
data: s
|
|
26
26
|
};
|
|
27
|
-
|
|
27
|
+
i.forEach((n) => n(m));
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
/**
|
|
@@ -32,57 +32,57 @@ class C {
|
|
|
32
32
|
* @param callback Function to call when state changes
|
|
33
33
|
* @returns Unsubscribe function
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
h(this, "subscribe", (e) => (this.subscribers.add(e), e(S(this, y)), () => {
|
|
36
36
|
this.subscribers.delete(e);
|
|
37
37
|
}));
|
|
38
|
-
|
|
38
|
+
h(this, "onLifecycle", (e, s) => {
|
|
39
39
|
this.lifecycleListeners.has(e) || this.lifecycleListeners.set(e, /* @__PURE__ */ new Set());
|
|
40
|
-
const
|
|
41
|
-
return
|
|
42
|
-
|
|
40
|
+
const i = this.lifecycleListeners.get(e);
|
|
41
|
+
return i.add(s), () => {
|
|
42
|
+
i.delete(s), i.size === 0 && this.lifecycleListeners.delete(e);
|
|
43
43
|
};
|
|
44
44
|
});
|
|
45
45
|
/**
|
|
46
46
|
* Get the current state
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
h(this, "getState", () => S(this, y));
|
|
49
49
|
/**
|
|
50
50
|
* Set the state and notify subscribers if the state changes
|
|
51
51
|
* @param newState The new state to set
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
h(this, "setState", (e) => {
|
|
54
54
|
this.emitLifecycle("beforeUpdate", {
|
|
55
|
-
previousState:
|
|
55
|
+
previousState: S(this, y),
|
|
56
56
|
nextState: e
|
|
57
|
-
}), H(
|
|
57
|
+
}), H(S(this, y), e) || (_(this, y, e), _(this, T, Date.now()), this.emitLifecycle("stateChange", { state: e }), this.subscribers.forEach((s) => {
|
|
58
58
|
try {
|
|
59
59
|
s(e);
|
|
60
|
-
} catch (
|
|
61
|
-
this.emitLifecycle("error", { error:
|
|
60
|
+
} catch (i) {
|
|
61
|
+
this.emitLifecycle("error", { error: i });
|
|
62
62
|
}
|
|
63
63
|
})), this.emitLifecycle("afterUpdate", { state: e });
|
|
64
64
|
});
|
|
65
|
-
|
|
66
|
-
const s = { ...
|
|
65
|
+
h(this, "setStatePartial", (e) => {
|
|
66
|
+
const s = { ...S(this, y), ...e };
|
|
67
67
|
this.setState(s);
|
|
68
68
|
});
|
|
69
69
|
/**
|
|
70
70
|
* Clear all subscriptions
|
|
71
71
|
*/
|
|
72
|
-
|
|
72
|
+
h(this, "clear", () => {
|
|
73
73
|
this.emitLifecycle(
|
|
74
74
|
"destroy"
|
|
75
75
|
/* DESTROY */
|
|
76
76
|
), this.subscribers.clear(), this.lifecycleListeners.clear();
|
|
77
77
|
});
|
|
78
|
-
|
|
78
|
+
h(this, "reset", () => {
|
|
79
79
|
this.setState(this.initialState);
|
|
80
80
|
});
|
|
81
|
-
|
|
82
|
-
_(this, y, e), this.initialState = e, _(this,
|
|
81
|
+
h(this, "lastUpdated", () => S(this, T));
|
|
82
|
+
_(this, y, e), this.initialState = e, _(this, T, Date.now()), this.emitLifecycle("init", { initialState: S(this, y) });
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
y = new WeakMap(),
|
|
85
|
+
y = new WeakMap(), T = new WeakMap();
|
|
86
86
|
function ee(t) {
|
|
87
87
|
return new C(t);
|
|
88
88
|
}
|
|
@@ -121,7 +121,7 @@ class ne extends v {
|
|
|
121
121
|
super(e), this.name = "FileUploadError";
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
-
function
|
|
124
|
+
function P(t) {
|
|
125
125
|
if (!t) return !1;
|
|
126
126
|
try {
|
|
127
127
|
return typeof t.isAvailable == "function" ? t.isAvailable() : !0;
|
|
@@ -129,7 +129,7 @@ function L(t) {
|
|
|
129
129
|
return !1;
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
async function
|
|
132
|
+
async function O(t, e) {
|
|
133
133
|
try {
|
|
134
134
|
return { success: !0, result: await t() };
|
|
135
135
|
} catch (s) {
|
|
@@ -145,9 +145,10 @@ const k = {
|
|
|
145
145
|
MESSAGES: 5e3
|
|
146
146
|
// every 5 seconds
|
|
147
147
|
};
|
|
148
|
-
function
|
|
148
|
+
function x(t) {
|
|
149
|
+
var s;
|
|
149
150
|
const e = {
|
|
150
|
-
id: t.publicId ||
|
|
151
|
+
id: t.publicId || L(),
|
|
151
152
|
timestamp: t.sentAt || "",
|
|
152
153
|
attachments: t.attachments || void 0
|
|
153
154
|
};
|
|
@@ -156,6 +157,15 @@ function $(t) {
|
|
|
156
157
|
type: "FROM_USER",
|
|
157
158
|
content: t.content.text || "",
|
|
158
159
|
deliveredAt: t.sentAt || ""
|
|
160
|
+
} : t.sender.kind === "agent" ? {
|
|
161
|
+
id: t.publicId || L(),
|
|
162
|
+
type: "FROM_AGENT",
|
|
163
|
+
component: t.type,
|
|
164
|
+
data: {
|
|
165
|
+
text: t.content.text
|
|
166
|
+
},
|
|
167
|
+
timestamp: (s = t.sentAt) == null ? void 0 : s.toISOString(),
|
|
168
|
+
attachments: t.attachments || void 0
|
|
159
169
|
} : {
|
|
160
170
|
...e,
|
|
161
171
|
type: "FROM_BOT",
|
|
@@ -172,13 +182,13 @@ function $(t) {
|
|
|
172
182
|
};
|
|
173
183
|
}
|
|
174
184
|
function X(t, e, s) {
|
|
175
|
-
async function o
|
|
185
|
+
async function i(o) {
|
|
176
186
|
const l = e.getState().messages;
|
|
177
187
|
if (l.length === 0) {
|
|
178
|
-
s == null || s.debug("No messages yet, fetching all history", { sessionId:
|
|
179
|
-
const g = await t.getSessionHistory(
|
|
188
|
+
s == null || s.debug("No messages yet, fetching all history", { sessionId: o.id });
|
|
189
|
+
const g = await t.getSessionHistory(o.id, "");
|
|
180
190
|
g && g.length > 0 && e.setStatePartial({
|
|
181
|
-
messages: g.map(
|
|
191
|
+
messages: g.map(x)
|
|
182
192
|
});
|
|
183
193
|
return;
|
|
184
194
|
}
|
|
@@ -186,13 +196,13 @@ function X(t, e, s) {
|
|
|
186
196
|
r.setSeconds(r.getSeconds() + 1);
|
|
187
197
|
const u = r.toISOString();
|
|
188
198
|
s == null || s.debug("Fetching history messages after timestamp", {
|
|
189
|
-
sessionId:
|
|
199
|
+
sessionId: o.id,
|
|
190
200
|
lastMessageTimestamp: u,
|
|
191
201
|
currentMessageCount: l.length
|
|
192
202
|
});
|
|
193
|
-
const E = await t.getSessionHistory(
|
|
203
|
+
const E = await t.getSessionHistory(o.id, u);
|
|
194
204
|
if (E && E.length > 0) {
|
|
195
|
-
const g = E.map(
|
|
205
|
+
const g = E.map(x).filter((p) => !l.some((I) => I.id === p.id));
|
|
196
206
|
g.length > 0 && (s == null || s.debug("Adding new messages to state", {
|
|
197
207
|
count: g.length,
|
|
198
208
|
messageIds: g.map((p) => p.id),
|
|
@@ -202,32 +212,32 @@ function X(t, e, s) {
|
|
|
202
212
|
}));
|
|
203
213
|
}
|
|
204
214
|
}
|
|
205
|
-
function m(
|
|
215
|
+
function m(o, l) {
|
|
206
216
|
return {
|
|
207
|
-
id:
|
|
217
|
+
id: L(),
|
|
208
218
|
type: "FROM_USER",
|
|
209
|
-
content:
|
|
219
|
+
content: o,
|
|
210
220
|
deliveredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
211
221
|
attachments: l,
|
|
212
222
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
213
223
|
};
|
|
214
224
|
}
|
|
215
|
-
function n(
|
|
216
|
-
if (
|
|
225
|
+
function n(o) {
|
|
226
|
+
if (o.success && o.autopilotResponse)
|
|
217
227
|
return {
|
|
218
228
|
type: "FROM_BOT",
|
|
219
|
-
id:
|
|
229
|
+
id: o.autopilotResponse.id || L(),
|
|
220
230
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
221
231
|
component: "TEXT",
|
|
222
232
|
data: {
|
|
223
|
-
message:
|
|
233
|
+
message: o.autopilotResponse.value.content
|
|
224
234
|
}
|
|
225
235
|
};
|
|
226
|
-
if (
|
|
227
|
-
const l =
|
|
236
|
+
if (o.success && o.uiResponse) {
|
|
237
|
+
const l = o.uiResponse.value;
|
|
228
238
|
return {
|
|
229
239
|
type: "FROM_BOT",
|
|
230
|
-
id:
|
|
240
|
+
id: L(),
|
|
231
241
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
232
242
|
component: l.name,
|
|
233
243
|
data: l.request_response
|
|
@@ -235,29 +245,29 @@ function X(t, e, s) {
|
|
|
235
245
|
}
|
|
236
246
|
return null;
|
|
237
247
|
}
|
|
238
|
-
function a(
|
|
248
|
+
function a(o) {
|
|
239
249
|
return {
|
|
240
250
|
type: "FROM_BOT",
|
|
241
|
-
id:
|
|
251
|
+
id: L(),
|
|
242
252
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
243
253
|
component: "TEXT",
|
|
244
254
|
data: {
|
|
245
|
-
message:
|
|
255
|
+
message: o,
|
|
246
256
|
variant: "error"
|
|
247
257
|
}
|
|
248
258
|
};
|
|
249
259
|
}
|
|
250
260
|
return {
|
|
251
|
-
fetchHistoryMessages:
|
|
261
|
+
fetchHistoryMessages: i,
|
|
252
262
|
addUserMessage: m,
|
|
253
263
|
addBotMessage: n,
|
|
254
264
|
addErrorMessage: a
|
|
255
265
|
};
|
|
256
266
|
}
|
|
257
|
-
function z(t, e, s,
|
|
267
|
+
function z(t, e, s, i, m, n) {
|
|
258
268
|
var U, N;
|
|
259
269
|
const a = (U = n.platform) == null ? void 0 : U.logger;
|
|
260
|
-
let
|
|
270
|
+
let o = null;
|
|
261
271
|
const l = (N = n.platform) == null ? void 0 : N.storage, c = `${m.getConfig().user.external_id}:${m.getConfig().token}:session`, r = n.config.getSettings().persistSession;
|
|
262
272
|
async function u() {
|
|
263
273
|
if (l)
|
|
@@ -266,7 +276,7 @@ function z(t, e, s, o, m, n) {
|
|
|
266
276
|
const d = await l.getItem(c);
|
|
267
277
|
if (d) {
|
|
268
278
|
const f = JSON.parse(d);
|
|
269
|
-
a == null || a.info("Session restored from storage", { sessionId: f.id }), e.setState(f), await
|
|
279
|
+
a == null || a.info("Session restored from storage", { sessionId: f.id }), e.setState(f), await i.fetchHistoryMessages(f), g();
|
|
270
280
|
}
|
|
271
281
|
} catch (d) {
|
|
272
282
|
a == null || a.error("Error restoring session from storage:", d);
|
|
@@ -288,7 +298,7 @@ function z(t, e, s, o, m, n) {
|
|
|
288
298
|
}));
|
|
289
299
|
}
|
|
290
300
|
function g() {
|
|
291
|
-
if (
|
|
301
|
+
if (o) return;
|
|
292
302
|
a == null || a.debug("Starting polling");
|
|
293
303
|
const d = [];
|
|
294
304
|
d.push(
|
|
@@ -307,12 +317,12 @@ function z(t, e, s, o, m, n) {
|
|
|
307
317
|
const f = e.getState();
|
|
308
318
|
if (f != null && f.id)
|
|
309
319
|
try {
|
|
310
|
-
await
|
|
320
|
+
await i.fetchHistoryMessages(f);
|
|
311
321
|
} catch (w) {
|
|
312
322
|
a == null || a.error("Error polling messages:", w);
|
|
313
323
|
}
|
|
314
324
|
}, k.MESSAGES)
|
|
315
|
-
),
|
|
325
|
+
), o = () => {
|
|
316
326
|
a == null || a.debug("Stopping polling"), d.forEach(clearInterval);
|
|
317
327
|
};
|
|
318
328
|
}
|
|
@@ -343,7 +353,7 @@ function z(t, e, s, o, m, n) {
|
|
|
343
353
|
const d = e.getState();
|
|
344
354
|
if (d != null && d.id)
|
|
345
355
|
try {
|
|
346
|
-
|
|
356
|
+
o && (o(), o = null), e.setState(null), r && l && P(l) && l.removeItem(c), s.setState({
|
|
347
357
|
messages: [],
|
|
348
358
|
keyboard: null,
|
|
349
359
|
loading: { isLoading: !1 },
|
|
@@ -359,9 +369,9 @@ function z(t, e, s, o, m, n) {
|
|
|
359
369
|
});
|
|
360
370
|
}
|
|
361
371
|
}
|
|
362
|
-
function
|
|
372
|
+
function A(d = !1) {
|
|
363
373
|
try {
|
|
364
|
-
|
|
374
|
+
o && (o(), o = null), d && r && l && P(l) && l.removeItem(c), s.setState({
|
|
365
375
|
messages: [],
|
|
366
376
|
keyboard: null,
|
|
367
377
|
loading: { isLoading: !1 },
|
|
@@ -386,27 +396,27 @@ function z(t, e, s, o, m, n) {
|
|
|
386
396
|
const f = await F(d.id);
|
|
387
397
|
return f && e.setState(f), f;
|
|
388
398
|
}
|
|
389
|
-
return r &&
|
|
399
|
+
return r && P(l) && (u(), E()), {
|
|
390
400
|
createSession: p,
|
|
391
401
|
clearSession: I,
|
|
392
|
-
cleanup:
|
|
402
|
+
cleanup: A,
|
|
393
403
|
startPolling: g,
|
|
394
404
|
fetchSession: F,
|
|
395
405
|
refetchSession: q
|
|
396
406
|
};
|
|
397
407
|
}
|
|
398
|
-
function
|
|
399
|
-
var
|
|
400
|
-
const e = (
|
|
408
|
+
function ie(t) {
|
|
409
|
+
var o;
|
|
410
|
+
const e = (o = t.platform) == null ? void 0 : o.logger;
|
|
401
411
|
e == null || e.info("Initializing chat");
|
|
402
412
|
const s = new C({
|
|
403
413
|
messages: [],
|
|
404
414
|
keyboard: null,
|
|
405
415
|
loading: { isLoading: !1 },
|
|
406
416
|
error: { hasError: !1 }
|
|
407
|
-
}),
|
|
417
|
+
}), i = new C(null), m = X(t.api, s, e), n = z(
|
|
408
418
|
t.api,
|
|
409
|
-
|
|
419
|
+
i,
|
|
410
420
|
s,
|
|
411
421
|
m,
|
|
412
422
|
t.config,
|
|
@@ -414,7 +424,7 @@ function oe(t) {
|
|
|
414
424
|
);
|
|
415
425
|
async function a(l) {
|
|
416
426
|
var r;
|
|
417
|
-
let c =
|
|
427
|
+
let c = i.getState();
|
|
418
428
|
if (!(c != null && c.id) && (e == null || e.debug("No active session, creating new session"), c = await n.createSession(), !c))
|
|
419
429
|
return !1;
|
|
420
430
|
c.assignee.kind === "ai" && (c = await n.refetchSession() ?? c);
|
|
@@ -442,16 +452,16 @@ function oe(t) {
|
|
|
442
452
|
e == null || e.debug("Message sent successfully");
|
|
443
453
|
const I = m.addBotMessage(p);
|
|
444
454
|
if (I) {
|
|
445
|
-
const
|
|
455
|
+
const A = s.getState().messages;
|
|
446
456
|
s.setStatePartial({
|
|
447
|
-
messages: [...
|
|
457
|
+
messages: [...A, I]
|
|
448
458
|
});
|
|
449
459
|
}
|
|
450
460
|
} else {
|
|
451
461
|
e == null || e.warn("Message send failed", p.error);
|
|
452
|
-
const I = m.addErrorMessage(((r = p.error) == null ? void 0 : r.message) || "Unknown error occurred"),
|
|
462
|
+
const I = m.addErrorMessage(((r = p.error) == null ? void 0 : r.message) || "Unknown error occurred"), A = s.getState().messages;
|
|
453
463
|
s.setStatePartial({
|
|
454
|
-
messages: [...
|
|
464
|
+
messages: [...A, I]
|
|
455
465
|
});
|
|
456
466
|
}
|
|
457
467
|
return !0;
|
|
@@ -471,21 +481,21 @@ function oe(t) {
|
|
|
471
481
|
}
|
|
472
482
|
return {
|
|
473
483
|
chatState: s,
|
|
474
|
-
sessionState:
|
|
484
|
+
sessionState: i,
|
|
475
485
|
sendMessage: a,
|
|
476
486
|
createSession: n.createSession,
|
|
477
487
|
clearSession: n.clearSession,
|
|
478
488
|
cleanup: (l = !1) => n.cleanup(l)
|
|
479
489
|
};
|
|
480
490
|
}
|
|
481
|
-
function
|
|
491
|
+
function oe(t) {
|
|
482
492
|
const e = t.config.getConfig();
|
|
483
493
|
t.config.getConfig;
|
|
484
|
-
const s = `${e.token}:contact:${e.user.external_id}`,
|
|
494
|
+
const s = `${e.token}:contact:${e.user.external_id}`, i = P(t.platform.storage) ? t.platform.storage : void 0;
|
|
485
495
|
let m = null;
|
|
486
|
-
|
|
496
|
+
i && O(
|
|
487
497
|
async () => {
|
|
488
|
-
const r = await
|
|
498
|
+
const r = await i.getItem(s);
|
|
489
499
|
return r ? JSON.parse(r) : null;
|
|
490
500
|
},
|
|
491
501
|
"Error loading contact from storage"
|
|
@@ -497,10 +507,10 @@ function ie(t) {
|
|
|
497
507
|
loading: { isLoading: !1 },
|
|
498
508
|
error: { hasError: !1 }
|
|
499
509
|
});
|
|
500
|
-
|
|
501
|
-
|
|
510
|
+
P(i) && n.subscribe((r) => {
|
|
511
|
+
O(
|
|
502
512
|
async () => {
|
|
503
|
-
r.contact ? await
|
|
513
|
+
r.contact ? await i.setItem(s, JSON.stringify(r.contact)) : i.removeItem(s);
|
|
504
514
|
},
|
|
505
515
|
"Error persisting contact state"
|
|
506
516
|
).then((u) => {
|
|
@@ -518,10 +528,10 @@ function ie(t) {
|
|
|
518
528
|
if (n.setStatePartial({
|
|
519
529
|
loading: { isLoading: !0, reason: "loading_contact" },
|
|
520
530
|
error: { hasError: !1 }
|
|
521
|
-
}),
|
|
522
|
-
const r = await
|
|
531
|
+
}), i) {
|
|
532
|
+
const r = await O(
|
|
523
533
|
async () => {
|
|
524
|
-
const u = await
|
|
534
|
+
const u = await i.getItem(s);
|
|
525
535
|
return u ? JSON.parse(u) : null;
|
|
526
536
|
},
|
|
527
537
|
"Error loading contact"
|
|
@@ -548,7 +558,7 @@ function ie(t) {
|
|
|
548
558
|
});
|
|
549
559
|
}
|
|
550
560
|
}
|
|
551
|
-
async function
|
|
561
|
+
async function o(r) {
|
|
552
562
|
try {
|
|
553
563
|
n.setStatePartial({
|
|
554
564
|
loading: { isLoading: !0, reason: "saving_contact" },
|
|
@@ -561,9 +571,9 @@ function ie(t) {
|
|
|
561
571
|
avatar_url: r.avatar_url ?? (u == null ? void 0 : u.avatar_url) ?? null,
|
|
562
572
|
email: r.email ?? (u == null ? void 0 : u.email) ?? null
|
|
563
573
|
};
|
|
564
|
-
if (
|
|
565
|
-
const g = await
|
|
566
|
-
() =>
|
|
574
|
+
if (P(i)) {
|
|
575
|
+
const g = await O(
|
|
576
|
+
() => i.setItem(s, JSON.stringify(E)),
|
|
567
577
|
"Error saving contact"
|
|
568
578
|
);
|
|
569
579
|
if (!g.success)
|
|
@@ -601,9 +611,9 @@ function ie(t) {
|
|
|
601
611
|
if (n.setStatePartial({
|
|
602
612
|
loading: { isLoading: !0, reason: "cleaning_up" },
|
|
603
613
|
error: { hasError: !1 }
|
|
604
|
-
}),
|
|
605
|
-
const r = await
|
|
606
|
-
() =>
|
|
614
|
+
}), i) {
|
|
615
|
+
const r = await O(
|
|
616
|
+
() => i.removeItem(s),
|
|
607
617
|
"Error removing contact data"
|
|
608
618
|
);
|
|
609
619
|
if (!r.success)
|
|
@@ -632,18 +642,18 @@ function ie(t) {
|
|
|
632
642
|
contactState: n,
|
|
633
643
|
shouldCollectData: l,
|
|
634
644
|
loadContact: a,
|
|
635
|
-
saveContact:
|
|
645
|
+
saveContact: o,
|
|
636
646
|
cleanup: c
|
|
637
647
|
};
|
|
638
648
|
}
|
|
639
649
|
const V = {
|
|
640
650
|
messageArrived: "https://cloud.opencopilot.so/sfx/notification3.mp3"
|
|
641
|
-
},
|
|
651
|
+
}, $ = {
|
|
642
652
|
primaryColor: "hsl(211,65%,59%)",
|
|
643
653
|
triggerOffset: "20px"
|
|
644
654
|
}, K = 1e3 * 3;
|
|
645
655
|
function ce(t) {
|
|
646
|
-
var s,
|
|
656
|
+
var s, i, m, n, a, o, l, c, r;
|
|
647
657
|
if (!t.token)
|
|
648
658
|
throw new Error("Token is required");
|
|
649
659
|
if (t.pollingInterval && t.pollingInterval < K)
|
|
@@ -658,7 +668,7 @@ function ce(t) {
|
|
|
658
668
|
pathParams: t.pathParams ?? {},
|
|
659
669
|
bot: {
|
|
660
670
|
name: ((s = t.bot) == null ? void 0 : s.name) ?? "Bot",
|
|
661
|
-
avatarUrl: (
|
|
671
|
+
avatarUrl: (i = t.bot) == null ? void 0 : i.avatarUrl,
|
|
662
672
|
id: ((m = t.bot) == null ? void 0 : m.id) ?? null,
|
|
663
673
|
is_ai: ((n = t.bot) == null ? void 0 : n.is_ai) ?? !0
|
|
664
674
|
},
|
|
@@ -670,8 +680,8 @@ function ce(t) {
|
|
|
670
680
|
messageArrived: ((a = t.soundEffectFiles) == null ? void 0 : a.messageArrived) ?? V.messageArrived
|
|
671
681
|
},
|
|
672
682
|
theme: {
|
|
673
|
-
primaryColor: ((
|
|
674
|
-
triggerOffset: ((l = t.theme) == null ? void 0 : l.triggerOffset) ??
|
|
683
|
+
primaryColor: ((o = t.theme) == null ? void 0 : o.primaryColor) ?? $.primaryColor,
|
|
684
|
+
triggerOffset: ((l = t.theme) == null ? void 0 : l.triggerOffset) ?? $.triggerOffset
|
|
675
685
|
},
|
|
676
686
|
settings: {
|
|
677
687
|
persistSession: ((c = t.settings) == null ? void 0 : c.persistSession) ?? !1,
|
|
@@ -697,8 +707,8 @@ function ce(t) {
|
|
|
697
707
|
};
|
|
698
708
|
}
|
|
699
709
|
function Y(t = {}) {
|
|
700
|
-
const e = [], s = [],
|
|
701
|
-
let
|
|
710
|
+
const e = [], s = [], i = [], m = async (n, a = {}) => {
|
|
711
|
+
let o = {
|
|
702
712
|
...t,
|
|
703
713
|
...a,
|
|
704
714
|
headers: {
|
|
@@ -708,15 +718,15 @@ function Y(t = {}) {
|
|
|
708
718
|
};
|
|
709
719
|
try {
|
|
710
720
|
for (const u of e)
|
|
711
|
-
|
|
712
|
-
const l =
|
|
713
|
-
let r = await fetch(c,
|
|
721
|
+
o = await u(o);
|
|
722
|
+
const l = o.params ? "?" + new URLSearchParams(o.params).toString() : "", c = o.baseURL ? `${o.baseURL}${n}${l}`.replace(/([^:]\/)\/+/g, "$1") : `${n}${l}`;
|
|
723
|
+
let r = await fetch(c, o);
|
|
714
724
|
for (const u of s)
|
|
715
725
|
r = await u(r);
|
|
716
726
|
return r;
|
|
717
727
|
} catch (l) {
|
|
718
728
|
let c = l;
|
|
719
|
-
for (const r of
|
|
729
|
+
for (const r of i)
|
|
720
730
|
c = await r(c);
|
|
721
731
|
throw c;
|
|
722
732
|
}
|
|
@@ -729,9 +739,9 @@ function Y(t = {}) {
|
|
|
729
739
|
}
|
|
730
740
|
},
|
|
731
741
|
response: {
|
|
732
|
-
use: (n, a) => (s.push(n), a &&
|
|
742
|
+
use: (n, a) => (s.push(n), a && i.push(a), s.length - 1),
|
|
733
743
|
eject: (n) => {
|
|
734
|
-
s.splice(n, 1),
|
|
744
|
+
s.splice(n, 1), i.splice(n, 1);
|
|
735
745
|
}
|
|
736
746
|
}
|
|
737
747
|
}, m;
|
|
@@ -741,14 +751,14 @@ class le {
|
|
|
741
751
|
constructor(e) {
|
|
742
752
|
M(this, b);
|
|
743
753
|
this.options = e;
|
|
744
|
-
const s = this.options.config.user,
|
|
754
|
+
const s = this.options.config.user, i = {
|
|
745
755
|
claim: "",
|
|
746
756
|
value: ""
|
|
747
757
|
};
|
|
748
|
-
s != null && s.email ? (
|
|
758
|
+
s != null && s.email ? (i.claim = "email", i.value = s.email) : s != null && s.phone && (i.claim = "phone", i.value = s.phone);
|
|
749
759
|
const m = {
|
|
750
760
|
"X-Bot-Token": this.options.config.token,
|
|
751
|
-
"X-Consumer-Id": `${
|
|
761
|
+
"X-Consumer-Id": `${i.claim}:${i.value}`,
|
|
752
762
|
"Content-Type": "application/json",
|
|
753
763
|
Accept: "application/json"
|
|
754
764
|
};
|
|
@@ -758,32 +768,32 @@ class le {
|
|
|
758
768
|
}));
|
|
759
769
|
}
|
|
760
770
|
async me() {
|
|
761
|
-
return (await
|
|
771
|
+
return (await S(this, b).call(this, "/me")).json();
|
|
762
772
|
}
|
|
763
773
|
async widgetPrelude() {
|
|
764
|
-
return (await
|
|
774
|
+
return (await S(this, b).call(this, "/prelude")).json();
|
|
765
775
|
}
|
|
766
776
|
async handleMessage(e) {
|
|
767
|
-
return (await
|
|
777
|
+
return (await S(this, b).call(this, "/chat/send", {
|
|
768
778
|
method: "POST",
|
|
769
779
|
body: JSON.stringify(e)
|
|
770
780
|
})).json();
|
|
771
781
|
}
|
|
772
782
|
async getSessionHistory(e, s) {
|
|
773
|
-
const
|
|
783
|
+
const i = new URLSearchParams({
|
|
774
784
|
lastMessageTimestamp: s || ""
|
|
775
|
-
}), m = `/session/history/${e}?${
|
|
776
|
-
return (await
|
|
785
|
+
}), m = `/session/history/${e}?${i.toString()}`;
|
|
786
|
+
return (await S(this, b).call(this, m, {
|
|
777
787
|
method: "GET"
|
|
778
788
|
})).json();
|
|
779
789
|
}
|
|
780
790
|
async createSession() {
|
|
781
|
-
return (await
|
|
791
|
+
return (await S(this, b).call(this, "/create-session", {
|
|
782
792
|
method: "POST"
|
|
783
793
|
})).json();
|
|
784
794
|
}
|
|
785
795
|
async getSession(e) {
|
|
786
|
-
return (await
|
|
796
|
+
return (await S(this, b).call(this, `/session/${e}`, {
|
|
787
797
|
method: "GET"
|
|
788
798
|
})).json();
|
|
789
799
|
}
|
|
@@ -793,7 +803,7 @@ function ue(t = {}) {
|
|
|
793
803
|
const {
|
|
794
804
|
level: e = "info",
|
|
795
805
|
prefix: s = "[openCx]",
|
|
796
|
-
enabled:
|
|
806
|
+
enabled: i = !0
|
|
797
807
|
} = t;
|
|
798
808
|
let m = e;
|
|
799
809
|
const n = {
|
|
@@ -803,9 +813,9 @@ function ue(t = {}) {
|
|
|
803
813
|
error: 3
|
|
804
814
|
};
|
|
805
815
|
function a(c) {
|
|
806
|
-
return
|
|
816
|
+
return i && n[c] >= n[m];
|
|
807
817
|
}
|
|
808
|
-
function
|
|
818
|
+
function o(c) {
|
|
809
819
|
return `${s} ${c}`;
|
|
810
820
|
}
|
|
811
821
|
function l(c) {
|
|
@@ -827,16 +837,16 @@ function ue(t = {}) {
|
|
|
827
837
|
}
|
|
828
838
|
return {
|
|
829
839
|
debug(c, ...r) {
|
|
830
|
-
a("debug") && console.debug(
|
|
840
|
+
a("debug") && console.debug(o(c), ...l(r));
|
|
831
841
|
},
|
|
832
842
|
info(c, ...r) {
|
|
833
|
-
a("info") && console.info(
|
|
843
|
+
a("info") && console.info(o(c), ...l(r));
|
|
834
844
|
},
|
|
835
845
|
warn(c, ...r) {
|
|
836
|
-
a("warn") && console.warn(
|
|
846
|
+
a("warn") && console.warn(o(c), ...l(r));
|
|
837
847
|
},
|
|
838
848
|
error(c, ...r) {
|
|
839
|
-
a("error") && console.error(
|
|
849
|
+
a("error") && console.error(o(c), ...l(r));
|
|
840
850
|
},
|
|
841
851
|
setLevel(c) {
|
|
842
852
|
m = c;
|
|
@@ -856,12 +866,12 @@ export {
|
|
|
856
866
|
re as SessionNotDefinedError,
|
|
857
867
|
ae as TransportError,
|
|
858
868
|
ge as chatAttachmentSchema,
|
|
859
|
-
|
|
869
|
+
ie as createChat,
|
|
860
870
|
ce as createConfig,
|
|
861
|
-
|
|
871
|
+
oe as createContact,
|
|
862
872
|
ue as createLogger,
|
|
863
873
|
ee as createPubSub,
|
|
864
|
-
|
|
865
|
-
|
|
874
|
+
P as isStorageAvailable,
|
|
875
|
+
O as safeStorageOperation
|
|
866
876
|
};
|
|
867
877
|
//# sourceMappingURL=index.js.map
|