@telia-ace/widget-conversation 1.0.22 → 1.0.25
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 +110 -210
- package/dist/conversation.3981560b.js +1100 -0
- package/dist/conversation.3981560b.js.map +1 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +432 -760
- package/dist/index.js.map +1 -1
- package/dist/return-button.8773c0de.js +159 -0
- package/dist/return-button.8773c0de.js.map +1 -0
- package/dist/types.d.ts +41 -34
- package/dist/{components/conversation/plugin.d.ts → ui/conversation/conversation-component.d.ts} +2 -13
- package/dist/ui/conversation/conversation-content.d.ts +11 -0
- package/dist/{components/conversation/ui/input.d.ts → ui/conversation/conversation-input.d.ts} +0 -0
- package/dist/ui/conversation/conversation-loader.d.ts +8 -0
- package/dist/ui/conversation/conversation-message.d.ts +7 -0
- package/dist/ui/conversation/conversation-styles.d.ts +11 -0
- package/dist/{components → ui}/conversation/conversation.d.ts +0 -0
- package/dist/ui/conversation/index.d.ts +2 -0
- package/dist/{components/conversation/ui → ui/conversation}/message-types/agent.d.ts +1 -1
- package/dist/ui/conversation/message-types/custom.d.ts +9 -0
- package/dist/{components/conversation/ui → ui/conversation}/message-types/index.d.ts +1 -0
- package/dist/{components/conversation/ui → ui/conversation}/message-types/system.d.ts +0 -0
- package/dist/{components/conversation/ui → ui/conversation}/message-types/timestamp.d.ts +0 -0
- package/dist/{components/conversation/ui → ui/conversation}/message-types/user.d.ts +0 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/return-button/index.d.ts +2 -0
- package/dist/{components/return-button/plugin.d.ts → ui/return-button/return-button-component.d.ts} +2 -1
- package/dist/{components → ui}/return-button/return-button.d.ts +0 -0
- package/package.json +13 -10
- package/dist/components/conversation/ui/content.d.ts +0 -2
- package/dist/components/conversation/ui/loader.d.ts +0 -8
- package/dist/components/conversation/ui/message-list-items/button-list.d.ts +0 -8
- package/dist/components/conversation/ui/message-list-items/custom.d.ts +0 -9
- package/dist/components/conversation/ui/message-list-items/html.d.ts +0 -5
- package/dist/components/conversation/ui/message-list-items/link-list.d.ts +0 -8
- package/dist/components/conversation/ui/message-list-items/separator.d.ts +0 -2
- package/dist/components/conversation/ui/message-list-items/text.d.ts +0 -6
- package/dist/components/conversation/ui/message-list-items/video-request.d.ts +0 -8
- package/dist/components/conversation/ui/message-types/message-list.d.ts +0 -9
- package/dist/components/conversation/ui/message.d.ts +0 -7
- package/dist/components/conversation/ui/overlay-outlets.d.ts +0 -13
- package/dist/components/conversation/ui/styles.d.ts +0 -27
- package/dist/conversation.js +0 -1394
- package/dist/conversation.js.map +0 -1
- package/dist/return-button.js +0 -174
- package/dist/return-button.js.map +0 -1
- package/dist/utils/map-actions.d.ts +0 -1
package/dist/index.js
CHANGED
|
@@ -1,371 +1,235 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
var U = Object.defineProperty, F = Object.defineProperties;
|
|
2
|
+
var _ = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var C = Object.getOwnPropertySymbols;
|
|
4
|
+
var T = Object.prototype.hasOwnProperty, D = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var N = (i, t, e) => t in i ? U(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e, p = (i, t) => {
|
|
6
|
+
for (var e in t || (t = {}))
|
|
7
|
+
T.call(t, e) && N(i, e, t[e]);
|
|
8
|
+
if (C)
|
|
9
|
+
for (var e of C(t))
|
|
10
|
+
D.call(t, e) && N(i, e, t[e]);
|
|
11
|
+
return i;
|
|
12
|
+
}, g = (i, t) => F(i, _(t));
|
|
13
|
+
var R = (i, t) => {
|
|
14
|
+
var e = {};
|
|
15
|
+
for (var s in i)
|
|
16
|
+
T.call(i, s) && t.indexOf(s) < 0 && (e[s] = i[s]);
|
|
17
|
+
if (i != null && C)
|
|
18
|
+
for (var s of C(i))
|
|
19
|
+
t.indexOf(s) < 0 && D.call(i, s) && (e[s] = i[s]);
|
|
20
|
+
return e;
|
|
18
21
|
};
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
22
|
+
var S = (i, t, e) => new Promise((s, r) => {
|
|
23
|
+
var n = (c) => {
|
|
24
|
+
try {
|
|
25
|
+
a(e.next(c));
|
|
26
|
+
} catch (h) {
|
|
27
|
+
r(h);
|
|
29
28
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
step(generator.next(value));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
reject(e);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var rejected = (value) => {
|
|
42
|
-
try {
|
|
43
|
-
step(generator.throw(value));
|
|
44
|
-
} catch (e) {
|
|
45
|
-
reject(e);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
import { ComponentPlatform } from "@telia-ace/widget-core";
|
|
53
|
-
import { createStorageWriter, StorageCategory, StorageMedium, StorageScope, readStorage } from "@telia-ace/widget-services";
|
|
54
|
-
import { uuid, lock } from "@telia-ace/widget-utilities";
|
|
55
|
-
import { FormBuilder } from "@telia-ace/widget-forms";
|
|
56
|
-
import { closeAllModals } from "@telia-ace/widget-plugins";
|
|
57
|
-
import { createReactComponent } from "@telia-ace/widget-ui";
|
|
58
|
-
import { lazy } from "react";
|
|
59
|
-
class Agent {
|
|
60
|
-
constructor(provider, settings) {
|
|
61
|
-
this.provider = provider;
|
|
62
|
-
this.print = (settings2) => {
|
|
63
|
-
const sender = { name: this.name, avatar: this.avatar };
|
|
64
|
-
const normalized = getNormalizedMessageSettings(settings2);
|
|
65
|
-
return this.provider.createEntry(normalized.key, normalized.content, ConversationMessageType.Agent, sender, normalized.timestamp);
|
|
66
|
-
};
|
|
67
|
-
this.typing = () => {
|
|
68
|
-
return this.provider.setTypingState({ name: this.name, avatar: this.avatar });
|
|
69
|
-
};
|
|
70
|
-
this.name = settings.name;
|
|
71
|
-
this.avatar = settings.avatar;
|
|
72
|
-
}
|
|
73
|
-
update(settings) {
|
|
74
|
-
const { name, avatar } = settings;
|
|
75
|
-
if (avatar === null) {
|
|
76
|
-
this.avatar = void 0;
|
|
77
|
-
} else if (avatar) {
|
|
78
|
-
this.avatar = avatar;
|
|
79
|
-
}
|
|
80
|
-
if (name === null) {
|
|
81
|
-
this.name = void 0;
|
|
82
|
-
} else if (name) {
|
|
83
|
-
this.name = name;
|
|
29
|
+
}, o = (c) => {
|
|
30
|
+
try {
|
|
31
|
+
a(e.throw(c));
|
|
32
|
+
} catch (h) {
|
|
33
|
+
r(h);
|
|
84
34
|
}
|
|
35
|
+
}, a = (c) => c.done ? s(c.value) : Promise.resolve(c.value).then(n, o);
|
|
36
|
+
a((e = e.apply(i, t)).next());
|
|
37
|
+
});
|
|
38
|
+
import { ComponentPlatform as H } from "@telia-ace/widget-core";
|
|
39
|
+
import { createStorageWriter as z, StorageCategory as $, StorageMedium as m, StorageScope as L, readStorage as A } from "@telia-ace/widget-services";
|
|
40
|
+
import { uuid as j, lock as G } from "@telia-ace/widget-utilities";
|
|
41
|
+
import { FormBuilder as J } from "@telia-ace/widget-forms";
|
|
42
|
+
import { closeAllModals as M } from "@telia-ace/widget-plugins";
|
|
43
|
+
import { createReactComponent as Q } from "@telia-ace/widget-ui";
|
|
44
|
+
import { lazy as K } from "react";
|
|
45
|
+
class V {
|
|
46
|
+
constructor(t, e) {
|
|
47
|
+
this.provider = t, this.print = (s) => {
|
|
48
|
+
const r = { name: this.name, avatar: this.avatar }, n = x(s);
|
|
49
|
+
return this.provider.createEntry(n.key, n.content, E.Agent, r, n.timestamp);
|
|
50
|
+
}, this.typing = () => this.provider.setTypingState({ name: this.name, avatar: this.avatar }), this.name = e.name, this.avatar = e.avatar;
|
|
51
|
+
}
|
|
52
|
+
update(t) {
|
|
53
|
+
const { name: e, avatar: s } = t;
|
|
54
|
+
s === null ? this.avatar = void 0 : s && (this.avatar = s), e === null ? this.name = void 0 : e && (this.name = e);
|
|
85
55
|
}
|
|
86
56
|
}
|
|
87
|
-
class
|
|
88
|
-
constructor(
|
|
89
|
-
this.name =
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
createAgent(settings = {}) {
|
|
99
|
-
if (this.controller) {
|
|
100
|
-
return new Agent(this, settings);
|
|
101
|
-
}
|
|
57
|
+
class k {
|
|
58
|
+
constructor(t, e, s) {
|
|
59
|
+
this.name = t, this.container = e, this.controller = s, this.subscriptions = [], this.user = s == null ? void 0 : s.user;
|
|
60
|
+
}
|
|
61
|
+
static create(t, e, s) {
|
|
62
|
+
return new k(t, e, s);
|
|
63
|
+
}
|
|
64
|
+
createAgent(t = {}) {
|
|
65
|
+
if (this.controller)
|
|
66
|
+
return new V(this, t);
|
|
102
67
|
}
|
|
103
|
-
print(
|
|
104
|
-
var
|
|
105
|
-
return (
|
|
68
|
+
print(t) {
|
|
69
|
+
var e;
|
|
70
|
+
return (e = this.controller) == null ? void 0 : e.print(t);
|
|
106
71
|
}
|
|
107
|
-
setTypingState(
|
|
108
|
-
var
|
|
109
|
-
return (
|
|
72
|
+
setTypingState(t, e) {
|
|
73
|
+
var s;
|
|
74
|
+
return (s = this.controller) == null ? void 0 : s.setTypingState(t, e);
|
|
110
75
|
}
|
|
111
76
|
loading() {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
return this.controller.loader();
|
|
77
|
+
return this.controller ? this.controller.loader() : () => () => {
|
|
78
|
+
};
|
|
117
79
|
}
|
|
118
|
-
createEntry(
|
|
119
|
-
var
|
|
120
|
-
return (
|
|
80
|
+
createEntry(t, e, s, r, n) {
|
|
81
|
+
var o;
|
|
82
|
+
return (o = this.controller) == null ? void 0 : o.createEntry(t, e, s, r, n);
|
|
121
83
|
}
|
|
122
84
|
dispose() {
|
|
123
|
-
var
|
|
124
|
-
(
|
|
125
|
-
this.controller = null;
|
|
126
|
-
this.subscriptions.forEach((unsub) => unsub());
|
|
85
|
+
var t;
|
|
86
|
+
process.env.NODE_ENV !== "production" && console.log(`conversation-provider: dispose (${this.name})`), (t = this.controller) == null || t.disposeProvider(this), this.controller = null, this.subscriptions.forEach((e) => e());
|
|
127
87
|
}
|
|
128
|
-
onUnreadMessage(
|
|
129
|
-
var
|
|
88
|
+
onUnreadMessage(t) {
|
|
89
|
+
var e;
|
|
130
90
|
if (this.controller) {
|
|
131
|
-
const
|
|
132
|
-
this.subscriptions.push(
|
|
133
|
-
|
|
134
|
-
unsubscribe();
|
|
91
|
+
const s = (e = this.controller) == null ? void 0 : e.onUnreadMessage(t);
|
|
92
|
+
return this.subscriptions.push(s), () => {
|
|
93
|
+
s();
|
|
135
94
|
};
|
|
136
95
|
}
|
|
137
96
|
}
|
|
138
|
-
onMounted(
|
|
139
|
-
var
|
|
97
|
+
onMounted(t) {
|
|
98
|
+
var e;
|
|
140
99
|
if (this.controller) {
|
|
141
|
-
const
|
|
142
|
-
this.subscriptions.push(
|
|
143
|
-
|
|
144
|
-
return () => {
|
|
145
|
-
unsubscribe();
|
|
100
|
+
const s = (e = this.controller) == null ? void 0 : e.events.subscribe("conversation:component-mount-changed", t);
|
|
101
|
+
return this.subscriptions.push(s), t({}, this.controller.getComponentMountedState()), () => {
|
|
102
|
+
s();
|
|
146
103
|
};
|
|
147
104
|
}
|
|
148
105
|
}
|
|
149
106
|
}
|
|
150
|
-
class
|
|
151
|
-
constructor(
|
|
152
|
-
this.controller =
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return this.controller.createEntry(normalized.key, normalized.content, ConversationMessageType.User, void 0, normalized.timestamp);
|
|
107
|
+
class Y {
|
|
108
|
+
constructor(t) {
|
|
109
|
+
this.controller = t, this.print = (e) => {
|
|
110
|
+
const s = x(e);
|
|
111
|
+
return this.controller.createEntry(s.key, s.content, E.User, void 0, s.timestamp);
|
|
156
112
|
};
|
|
157
113
|
}
|
|
158
114
|
}
|
|
159
|
-
class
|
|
160
|
-
constructor(
|
|
161
|
-
this.writer =
|
|
115
|
+
class q {
|
|
116
|
+
constructor(t) {
|
|
117
|
+
this.writer = t;
|
|
162
118
|
}
|
|
163
|
-
update(
|
|
164
|
-
const
|
|
165
|
-
this.writer(
|
|
119
|
+
update(t) {
|
|
120
|
+
const e = this.getNormalizedSettings(t);
|
|
121
|
+
this.writer(e);
|
|
166
122
|
}
|
|
167
123
|
remove() {
|
|
168
124
|
this.writer(null);
|
|
169
125
|
}
|
|
170
|
-
getNormalizedSettings(
|
|
171
|
-
|
|
172
|
-
return { body: content };
|
|
173
|
-
else if (content.length > -1 && typeof content === "object")
|
|
174
|
-
return { items: content };
|
|
175
|
-
else
|
|
176
|
-
return content;
|
|
126
|
+
getNormalizedSettings(t) {
|
|
127
|
+
return typeof t == "string" ? { body: t } : t.length > -1 && typeof t == "object" ? { items: t } : t;
|
|
177
128
|
}
|
|
178
129
|
}
|
|
179
|
-
var
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
settings = settings || {};
|
|
199
|
-
if (settings.type) {
|
|
200
|
-
content = __spreadValues({}, settings);
|
|
201
|
-
} else {
|
|
202
|
-
content = {
|
|
203
|
-
body: settings.body,
|
|
204
|
-
actions: settings.actions,
|
|
205
|
-
title: settings.title
|
|
206
|
-
};
|
|
207
|
-
if (settings.key) {
|
|
208
|
-
key = settings.key;
|
|
209
|
-
}
|
|
210
|
-
if (settings.timestamp) {
|
|
211
|
-
timestamp = settings.timestamp;
|
|
212
|
-
}
|
|
213
|
-
if (settings.form) {
|
|
214
|
-
const builder = FormBuilder.create(key);
|
|
215
|
-
settings.form(builder);
|
|
216
|
-
const builtForm = builder.get();
|
|
217
|
-
content.form = builtForm;
|
|
218
|
-
}
|
|
219
|
-
if (settings.timestamp === null) {
|
|
220
|
-
timestamp = null;
|
|
221
|
-
}
|
|
130
|
+
var E = /* @__PURE__ */ ((i) => (i.User = "user", i.Agent = "agent", i.System = "system", i))(E || {});
|
|
131
|
+
const x = (i) => {
|
|
132
|
+
let t, e = j(), s = Date.now();
|
|
133
|
+
if (i.length > -1 && typeof i == "object")
|
|
134
|
+
typeof i[0] == "string" ? t = { items: [i] } : t = { items: i };
|
|
135
|
+
else if (typeof i == "string")
|
|
136
|
+
t = { body: i };
|
|
137
|
+
else if (i = i, i.type)
|
|
138
|
+
t = p({}, i);
|
|
139
|
+
else {
|
|
140
|
+
if (t = {
|
|
141
|
+
body: i.body,
|
|
142
|
+
actions: i.actions,
|
|
143
|
+
title: i.title
|
|
144
|
+
}, i.key && (e = i.key), i.timestamp && (s = i.timestamp), i.form) {
|
|
145
|
+
const r = J.create(e);
|
|
146
|
+
i.form(r);
|
|
147
|
+
const n = r.get();
|
|
148
|
+
t.form = n;
|
|
222
149
|
}
|
|
150
|
+
i.timestamp === null && (s = null);
|
|
223
151
|
}
|
|
224
|
-
return { content, key, timestamp };
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (!sender) {
|
|
152
|
+
return { content: t, key: e, timestamp: s };
|
|
153
|
+
}, O = (i, t) => {
|
|
154
|
+
if (!t)
|
|
228
155
|
return;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
return senderString === JSON.stringify(item);
|
|
233
|
-
});
|
|
234
|
-
if (indexToRemove > -1) {
|
|
235
|
-
return typingActors.splice(indexToRemove, 1);
|
|
236
|
-
}
|
|
156
|
+
const e = JSON.stringify(t), s = i.findIndex((r) => e === JSON.stringify(r));
|
|
157
|
+
if (s > -1)
|
|
158
|
+
return i.splice(s, 1);
|
|
237
159
|
};
|
|
238
|
-
class
|
|
239
|
-
constructor(
|
|
240
|
-
this.container =
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
this.user = new User(this);
|
|
244
|
-
this.providers = [];
|
|
245
|
-
this.active = false;
|
|
246
|
-
this.registeredProviders = [];
|
|
247
|
-
this.loaders = 0;
|
|
248
|
-
this.componentMounted = false;
|
|
249
|
-
this.messages = [];
|
|
250
|
-
this.typingActors = [];
|
|
251
|
-
this.print = (settings) => {
|
|
252
|
-
const normalized = getNormalizedMessageSettings(settings);
|
|
253
|
-
return this.createEntry(normalized.key, normalized.content, "system", void 0, normalized.timestamp);
|
|
160
|
+
class X {
|
|
161
|
+
constructor(t, e) {
|
|
162
|
+
this.container = t, this.id = e, this.formHandlers = {}, this.user = new Y(this), this.providers = [], this.active = !1, this.registeredProviders = [], this.loaders = 0, this.componentMounted = !1, this.messages = [], this.typingActors = [], this.print = (r) => {
|
|
163
|
+
const n = x(r);
|
|
164
|
+
return this.createEntry(n.key, n.content, "system", void 0, n.timestamp);
|
|
254
165
|
};
|
|
255
|
-
const
|
|
256
|
-
this.events =
|
|
257
|
-
}
|
|
258
|
-
setProviders(
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
this.providers.push(provider);
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
if (added.length || removed.length) {
|
|
280
|
-
this.events.dispatch("conversation:providers-changed", { added, removed });
|
|
281
|
-
}
|
|
166
|
+
const s = t.get("$widget");
|
|
167
|
+
this.events = s.events.createChild(this);
|
|
168
|
+
}
|
|
169
|
+
setProviders(t) {
|
|
170
|
+
const e = [], s = [];
|
|
171
|
+
this.providers.reduce((r, n) => (t.indexOf(n) === -1 && r.push(n), r), []).forEach((r) => {
|
|
172
|
+
const n = this.providers.indexOf(r);
|
|
173
|
+
n > -1 && (e.push(r), this.providers.splice(n, 1));
|
|
174
|
+
}), t.forEach((r) => {
|
|
175
|
+
this.providers.indexOf(r) === -1 && (s.push(r), this.providers.push(r));
|
|
176
|
+
}), (s.length || e.length) && this.events.dispatch("conversation:providers-changed", { added: s, removed: e });
|
|
177
|
+
}
|
|
178
|
+
createProvider(t) {
|
|
179
|
+
const e = this.providerIndex(t);
|
|
180
|
+
if (e > -1)
|
|
181
|
+
return this.registeredProviders[e];
|
|
182
|
+
const s = k.create(t, this.container, this);
|
|
183
|
+
return this.registeredProviders.push(s), s;
|
|
184
|
+
}
|
|
185
|
+
providerIndex(t) {
|
|
186
|
+
return this.registeredProviders.findIndex((e) => e.name === t);
|
|
282
187
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (index > -1) {
|
|
286
|
-
return this.registeredProviders[index];
|
|
287
|
-
}
|
|
288
|
-
const provider = ConversationProvider.create(name, this.container, this);
|
|
289
|
-
this.registeredProviders.push(provider);
|
|
290
|
-
return provider;
|
|
188
|
+
dispose() {
|
|
189
|
+
this.registeredProviders.forEach((t) => t.dispose()), this.messages = [], this.events.dispatch("conversation:controller-disposed", this), this.active = !1;
|
|
291
190
|
}
|
|
292
|
-
|
|
293
|
-
return this.
|
|
191
|
+
onDispose(t) {
|
|
192
|
+
return this.events.subscribe("conversation:controller-disposed", t);
|
|
294
193
|
}
|
|
295
|
-
|
|
296
|
-
this.
|
|
297
|
-
this.messages = [];
|
|
298
|
-
this.events.dispatch("conversation:controller-disposed", this);
|
|
299
|
-
this.active = false;
|
|
300
|
-
}
|
|
301
|
-
onDispose(fn) {
|
|
302
|
-
return this.events.subscribe("conversation:controller-disposed", fn);
|
|
303
|
-
}
|
|
304
|
-
onStarted(fn) {
|
|
305
|
-
return this.events.subscribe("conversation:started", fn);
|
|
306
|
-
}
|
|
307
|
-
disposeProvider(target) {
|
|
308
|
-
const index = this.providerIndex(target.name);
|
|
309
|
-
index > -1 && this.registeredProviders.splice(index, 1);
|
|
310
|
-
this.events.dispatch("conversation:providers-changed", { removed: [target.name] });
|
|
311
|
-
if (!this.registeredProviders.length) {
|
|
312
|
-
this.dispose();
|
|
313
|
-
}
|
|
194
|
+
onStarted(t) {
|
|
195
|
+
return this.events.subscribe("conversation:started", t);
|
|
314
196
|
}
|
|
315
|
-
|
|
316
|
-
|
|
197
|
+
disposeProvider(t) {
|
|
198
|
+
const e = this.providerIndex(t.name);
|
|
199
|
+
e > -1 && this.registeredProviders.splice(e, 1), this.events.dispatch("conversation:providers-changed", { removed: [t.name] }), this.registeredProviders.length || this.dispose();
|
|
317
200
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
this.componentMounted =
|
|
323
|
-
if (mounted) {
|
|
324
|
-
this.events.dispatch("conversation:unread-message", false);
|
|
325
|
-
this.events.dispatch("conversation:started", true);
|
|
326
|
-
this.active = true;
|
|
327
|
-
}
|
|
328
|
-
this.events.dispatch("conversation:component-mount-changed", mounted);
|
|
201
|
+
onProvidersChange(t) {
|
|
202
|
+
return this.events.subscribe("conversation:providers-changed", t);
|
|
203
|
+
}
|
|
204
|
+
setComponentMountedState(t) {
|
|
205
|
+
this.componentMounted !== t && (this.componentMounted = t, t && (this.events.dispatch("conversation:unread-message", !1), this.events.dispatch("conversation:started", !0), this.active = !0), this.events.dispatch("conversation:component-mount-changed", t));
|
|
329
206
|
}
|
|
330
207
|
getComponentMountedState() {
|
|
331
208
|
return this.componentMounted;
|
|
332
209
|
}
|
|
333
|
-
onUnreadMessage(
|
|
334
|
-
return this.events.subscribe("conversation:unread-message",
|
|
210
|
+
onUnreadMessage(t) {
|
|
211
|
+
return this.events.subscribe("conversation:unread-message", t);
|
|
335
212
|
}
|
|
336
|
-
createEntry(
|
|
337
|
-
const
|
|
338
|
-
key,
|
|
339
|
-
content,
|
|
340
|
-
type,
|
|
341
|
-
sender:
|
|
342
|
-
timestamp:
|
|
213
|
+
createEntry(t, e, s, r, n) {
|
|
214
|
+
const o = {
|
|
215
|
+
key: t,
|
|
216
|
+
content: e,
|
|
217
|
+
type: s,
|
|
218
|
+
sender: r || null,
|
|
219
|
+
timestamp: n || n === null ? n : Date.now()
|
|
343
220
|
};
|
|
344
|
-
this.messages.push(
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
message.content = content2;
|
|
350
|
-
if (updatedTimestamp) {
|
|
351
|
-
message.timestamp = updatedTimestamp;
|
|
352
|
-
}
|
|
221
|
+
this.messages.push(o), o.type === "agent" && O(this.typingActors, r);
|
|
222
|
+
const a = new q((c) => {
|
|
223
|
+
if (c !== null) {
|
|
224
|
+
const h = c, { timestamp: d = void 0 } = h, f = R(h, ["timestamp"]);
|
|
225
|
+
o.content = f, d && (o.timestamp = d);
|
|
353
226
|
} else {
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
if (indexToRemove > -1) {
|
|
357
|
-
this.messages.splice(indexToRemove, 1);
|
|
358
|
-
}
|
|
227
|
+
const d = this.messages.indexOf(o);
|
|
228
|
+
o.content = null, d > -1 && this.messages.splice(d, 1);
|
|
359
229
|
}
|
|
360
|
-
this.events.dispatch("conversation:message-updated", { message });
|
|
361
|
-
this.update();
|
|
230
|
+
this.events.dispatch("conversation:message-updated", { message: o }), this.update();
|
|
362
231
|
});
|
|
363
|
-
this.events.dispatch("conversation:message-created", { message });
|
|
364
|
-
this.update();
|
|
365
|
-
if (!this.componentMounted) {
|
|
366
|
-
this.events.dispatch("conversation:unread-message", true);
|
|
367
|
-
}
|
|
368
|
-
return entry;
|
|
232
|
+
return this.events.dispatch("conversation:message-created", { message: o }), this.update(), this.componentMounted || this.events.dispatch("conversation:unread-message", !0), a;
|
|
369
233
|
}
|
|
370
234
|
update() {
|
|
371
235
|
this.events.dispatch("conversation:updated", {
|
|
@@ -381,507 +245,315 @@ class ConversationController {
|
|
|
381
245
|
typingActors: this.typingActors
|
|
382
246
|
};
|
|
383
247
|
}
|
|
384
|
-
setTypingState(
|
|
385
|
-
|
|
386
|
-
this.typingActors.
|
|
387
|
-
this.update();
|
|
388
|
-
}
|
|
389
|
-
return () => {
|
|
390
|
-
removeTypingState(this.typingActors, sender);
|
|
391
|
-
this.update();
|
|
248
|
+
setTypingState(t, e) {
|
|
249
|
+
return this.typingActors.indexOf(t) === -1 && (this.typingActors.push(t), this.update()), () => {
|
|
250
|
+
O(this.typingActors, t), this.update();
|
|
392
251
|
};
|
|
393
252
|
}
|
|
394
253
|
loader() {
|
|
395
254
|
this.loaders = this.loaders + 1;
|
|
396
|
-
let
|
|
397
|
-
|
|
398
|
-
this.update();
|
|
399
|
-
}
|
|
400
|
-
return () => {
|
|
401
|
-
if (!dismissed) {
|
|
402
|
-
dismissed = true;
|
|
403
|
-
this.loaders = this.loaders - 1;
|
|
404
|
-
if (this.loaders === 0) {
|
|
405
|
-
this.update();
|
|
406
|
-
}
|
|
407
|
-
}
|
|
255
|
+
let t = !1;
|
|
256
|
+
return this.loaders === 1 && this.update(), () => {
|
|
257
|
+
t || (t = !0, this.loaders = this.loaders - 1, this.loaders === 0 && this.update());
|
|
408
258
|
};
|
|
409
259
|
}
|
|
410
|
-
submitForm(
|
|
411
|
-
this.formHandlers[
|
|
260
|
+
submitForm(t, e) {
|
|
261
|
+
this.formHandlers[t] = g(p({}, this.formHandlers[t]), { submit: e });
|
|
412
262
|
}
|
|
413
|
-
validateForm(
|
|
414
|
-
this.formHandlers[
|
|
263
|
+
validateForm(t, e) {
|
|
264
|
+
this.formHandlers[t] = g(p({}, this.formHandlers[t]), { validate: e });
|
|
415
265
|
}
|
|
416
266
|
}
|
|
417
|
-
const
|
|
418
|
-
const
|
|
419
|
-
return
|
|
420
|
-
}
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
trigger.action = "hide";
|
|
451
|
-
return chatWidget.invoke("setSettings", () => ({
|
|
452
|
-
data,
|
|
453
|
-
trigger,
|
|
454
|
-
activate: true
|
|
455
|
-
})).then(() => {
|
|
456
|
-
return chatWidget.container.getAsync("components").then((components) => {
|
|
457
|
-
const contactMethodsQuery = components.components().ofType("contact-method");
|
|
458
|
-
components.write({
|
|
459
|
-
key: "setContactMethodId",
|
|
460
|
-
attributes: {
|
|
461
|
-
properties: {
|
|
462
|
-
id: contactMethod.id,
|
|
463
|
-
guideId: contactMethod.guideId
|
|
464
|
-
}
|
|
465
|
-
},
|
|
466
|
-
target: contactMethodsQuery,
|
|
467
|
-
provider: "localStorage"
|
|
468
|
-
});
|
|
469
|
-
const conversationsQuery = components.components().ofType("conversation");
|
|
470
|
-
components.write({
|
|
471
|
-
key: "setConversationProvider",
|
|
472
|
-
attributes: {
|
|
473
|
-
properties: { providers: [contactMethod.clientName] }
|
|
474
|
-
},
|
|
475
|
-
target: conversationsQuery,
|
|
476
|
-
provider: "localStorage"
|
|
477
|
-
});
|
|
478
|
-
});
|
|
267
|
+
const Z = (i, t) => {
|
|
268
|
+
const e = i.split("_contact");
|
|
269
|
+
return t.widgets.get(e[0]);
|
|
270
|
+
}, I = (i) => {
|
|
271
|
+
const t = i.get("$widget"), { name: e, implementation: s } = i.get("$widget"), r = e.indexOf("_contact") > -1 ? Z(e, s) : t, { data: n } = i.get("$settings"), { trigger: o } = r.container.get("$settings"), a = `${e.replace("_contact-method", "").replace("_contact", "")}_contact-method`, c = s.widgets.get(a);
|
|
272
|
+
return c && !o ? { chatWidget: c, mainWidget: r, data: n } : { mainWidget: r, data: n };
|
|
273
|
+
}, tt = (i) => {
|
|
274
|
+
const { chatWidget: t } = I(i);
|
|
275
|
+
return !!t;
|
|
276
|
+
}, B = (i, t, e) => {
|
|
277
|
+
const { mainWidget: s, data: r, chatWidget: n } = I(i);
|
|
278
|
+
return n ? n.state === "activated" ? n.invoke("open").then(() => {
|
|
279
|
+
n.container.getAsync("conversation").then((o) => {
|
|
280
|
+
o.navigateToConversationIfActive(t.id).then(() => M(i));
|
|
281
|
+
});
|
|
282
|
+
}) : n.activate().then(() => {
|
|
283
|
+
const { trigger: o } = n.container.get("$settings");
|
|
284
|
+
return o.action = "hide", n.invoke("setSettings", () => ({
|
|
285
|
+
data: r,
|
|
286
|
+
trigger: o,
|
|
287
|
+
activate: !0
|
|
288
|
+
})).then(() => n.container.getAsync("components").then((a) => {
|
|
289
|
+
const c = a.components().ofType("contact-method");
|
|
290
|
+
a.write({
|
|
291
|
+
key: "setContactMethodId",
|
|
292
|
+
attributes: {
|
|
293
|
+
properties: {
|
|
294
|
+
id: t.id,
|
|
295
|
+
guideId: t.guideId
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
target: c,
|
|
299
|
+
provider: "localStorage"
|
|
479
300
|
});
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
key: "
|
|
483
|
-
|
|
484
|
-
|
|
301
|
+
const h = a.components().ofType("conversation");
|
|
302
|
+
a.write({
|
|
303
|
+
key: "setConversationProvider",
|
|
304
|
+
attributes: {
|
|
305
|
+
properties: { providers: [t.clientName] }
|
|
306
|
+
},
|
|
307
|
+
target: h,
|
|
308
|
+
provider: "localStorage"
|
|
485
309
|
});
|
|
486
|
-
})
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
});
|
|
499
|
-
return
|
|
500
|
-
};
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
return mainWidget.container.getAsync("conversation").then((platform) => {
|
|
509
|
-
var _a;
|
|
510
|
-
(_a = platform.setConversationEndedBehavior(ConversationEndedBehavior.Navigate)) == null ? void 0 : _a.then(() => {
|
|
511
|
-
mainWidget.container.getAsync("router").then((router) => {
|
|
512
|
-
mainWidget.container.getAsync("components").then((components) => {
|
|
513
|
-
const conversationQuery = components.components().ofType("conversation");
|
|
514
|
-
components.write({
|
|
310
|
+
}));
|
|
311
|
+
}).then(() => n.invoke("attach", {
|
|
312
|
+
key: "contact-method",
|
|
313
|
+
triggerDOMElement: e,
|
|
314
|
+
withRenderState: "open"
|
|
315
|
+
})).then(() => (z(n.container, "activeStickyWidget", $.Necessary, {
|
|
316
|
+
medium: m.Local,
|
|
317
|
+
scope: L.Implementation
|
|
318
|
+
}).then((o) => o(n.name)), n.container.getAsync("conversation").then((o) => {
|
|
319
|
+
o.setConversationEndedBehavior(P.Deactivate);
|
|
320
|
+
}).then(() => M(i)).then(() => !1))) : (s.container.getAsync("conversation").then((o) => o.navigateToConversationIfActive(t.id).then(() => o.setConversationEndedBehavior(P.Navigate))), !n);
|
|
321
|
+
}, et = (i, t, e = "conversation") => {
|
|
322
|
+
const { mainWidget: s, chatWidget: r } = I(i);
|
|
323
|
+
return r ? r.container.getAsync("router").then((n) => {
|
|
324
|
+
n.navigate(e, { id: t.id });
|
|
325
|
+
}) : s.container.getAsync("conversation").then((n) => {
|
|
326
|
+
var o;
|
|
327
|
+
(o = n.setConversationEndedBehavior(P.Navigate)) == null || o.then(() => {
|
|
328
|
+
s.container.getAsync("router").then((a) => {
|
|
329
|
+
s.container.getAsync("components").then((c) => {
|
|
330
|
+
const h = c.components().ofType("conversation");
|
|
331
|
+
c.write({
|
|
515
332
|
key: "setConversationProvider",
|
|
516
|
-
attributes: { properties: { providers: [
|
|
517
|
-
target:
|
|
333
|
+
attributes: { properties: { providers: [t.clientName] } },
|
|
334
|
+
target: h,
|
|
518
335
|
provider: "localStorage"
|
|
519
336
|
});
|
|
520
337
|
}).then(() => {
|
|
521
|
-
|
|
338
|
+
a.navigate(e, { id: t.id });
|
|
522
339
|
});
|
|
523
340
|
});
|
|
524
341
|
});
|
|
525
342
|
});
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
})(ConversationEndedBehavior || {});
|
|
534
|
-
class ConversationPlatform {
|
|
535
|
-
constructor(container, components) {
|
|
536
|
-
this.container = container;
|
|
537
|
-
this.components = components;
|
|
538
|
-
this.controllers = [];
|
|
539
|
-
this.providers = [];
|
|
540
|
-
this.disposeProviders = {};
|
|
541
|
-
this.subscriptions = [];
|
|
542
|
-
this.storageWriter = null;
|
|
543
|
-
this.router = null;
|
|
544
|
-
this.buttonQuery = null;
|
|
545
|
-
this.sessionInfo = null;
|
|
546
|
-
const widget = container.get("$widget");
|
|
547
|
-
this.events = widget.events.createChild(this);
|
|
343
|
+
}, y = "conversations";
|
|
344
|
+
var P = /* @__PURE__ */ ((i) => (i.Deactivate = "deactivate", i.Navigate = "navigate", i.None = "none", i))(P || {});
|
|
345
|
+
class b {
|
|
346
|
+
constructor(t, e) {
|
|
347
|
+
this.container = t, this.components = e, this.controllers = [], this.providers = [], this.disposeProviders = {}, this.subscriptions = [], this.storageWriter = null, this.router = null, this.buttonQuery = null, this.sessionInfo = null;
|
|
348
|
+
const s = t.get("$widget");
|
|
349
|
+
this.events = s.events.createChild(this);
|
|
548
350
|
}
|
|
549
351
|
initialize() {
|
|
550
|
-
|
|
551
|
-
medium:
|
|
552
|
-
}).then((
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
if (storedSession.id && storedSession.route) {
|
|
558
|
-
this.writeToComponents({ active: true, alert: { show: false } });
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
});
|
|
562
|
-
this.container.getAsync("router").then((router) => this.router = router);
|
|
563
|
-
this.events.subscribe("conversation:ended", (event, data) => {
|
|
564
|
-
var _a, _b, _c;
|
|
565
|
-
switch ((_a = this.sessionInfo) == null ? void 0 : _a.conversationEndedBehavior) {
|
|
352
|
+
z(this.container, y, $.Necessary, {
|
|
353
|
+
medium: m.Local
|
|
354
|
+
}).then((t) => this.storageWriter = t), A(this.container, y, m.Local).then((t) => {
|
|
355
|
+
this.buttonQuery = this.components.components().ofType("conversation-return-button"), t && (this.sessionInfo = t, t.id && t.route && this.writeToComponents({ active: !0, alert: { show: !1 } }));
|
|
356
|
+
}), this.container.getAsync("router").then((t) => this.router = t), this.events.subscribe("conversation:ended", (t, e) => {
|
|
357
|
+
var s, r, n;
|
|
358
|
+
switch ((s = this.sessionInfo) == null ? void 0 : s.conversationEndedBehavior) {
|
|
566
359
|
case "deactivate":
|
|
567
|
-
|
|
568
|
-
widget.deactivate();
|
|
360
|
+
this.container.get("$widget").deactivate();
|
|
569
361
|
break;
|
|
570
362
|
case "navigate":
|
|
571
|
-
const
|
|
572
|
-
|
|
573
|
-
(_c = this.router) == null ? void 0 : _c.navigate(initialRoute.name);
|
|
574
|
-
}
|
|
363
|
+
const a = (r = this.router) == null ? void 0 : r.getInitialRoute();
|
|
364
|
+
a && ((n = this.router) == null || n.navigate(a.name));
|
|
575
365
|
break;
|
|
576
366
|
}
|
|
577
|
-
this.writeToComponents({ active:
|
|
578
|
-
this.sessionInfo = null;
|
|
579
|
-
this.storageWriter && this.storageWriter();
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
addSubscription(sub) {
|
|
583
|
-
this.subscriptions.push(sub);
|
|
584
|
-
}
|
|
585
|
-
static getInstance(container, key = "conversation") {
|
|
586
|
-
return lock(container)(() => {
|
|
587
|
-
return container.getAsync(key).then((value) => {
|
|
588
|
-
let conversation = value;
|
|
589
|
-
if (!conversation) {
|
|
590
|
-
return ComponentPlatform.getInstance(container).then((components) => {
|
|
591
|
-
conversation = new ConversationPlatform(container, components);
|
|
592
|
-
conversation.initialize();
|
|
593
|
-
container.registerAsync(key, () => conversation);
|
|
594
|
-
return conversation;
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
return conversation;
|
|
598
|
-
});
|
|
367
|
+
this.writeToComponents({ active: !1 }), this.sessionInfo = null, this.storageWriter && this.storageWriter();
|
|
599
368
|
});
|
|
600
369
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
370
|
+
addSubscription(t) {
|
|
371
|
+
this.subscriptions.push(t);
|
|
372
|
+
}
|
|
373
|
+
static getInstance(t, e = "conversation") {
|
|
374
|
+
return G(t)(() => t.getAsync(e).then((s) => {
|
|
375
|
+
let r = s;
|
|
376
|
+
return r || H.getInstance(t).then((n) => (r = new b(t, n), r.initialize(), t.registerAsync(e, () => r), r));
|
|
377
|
+
}));
|
|
378
|
+
}
|
|
379
|
+
navigateToConversationIfActive(t) {
|
|
380
|
+
return A(this.container, y, m.Local).then((e) => {
|
|
381
|
+
var s;
|
|
382
|
+
if (e && e.id === t && e.route) {
|
|
383
|
+
const { name: r, params: n } = e.route;
|
|
384
|
+
(s = this.router) == null || s.navigate(r, n);
|
|
609
385
|
}
|
|
610
386
|
});
|
|
611
387
|
}
|
|
612
|
-
setConversationEndedBehavior(
|
|
613
|
-
return
|
|
614
|
-
let
|
|
615
|
-
|
|
616
|
-
storedSession.conversationEndedBehavior = behavior;
|
|
617
|
-
} else {
|
|
618
|
-
storedSession = { conversationEndedBehavior: behavior };
|
|
619
|
-
}
|
|
620
|
-
this.sessionInfo = storedSession;
|
|
621
|
-
return this.storageWriter && this.storageWriter(this.sessionInfo) || Promise.resolve();
|
|
388
|
+
setConversationEndedBehavior(t) {
|
|
389
|
+
return A(this.container, y, m.Local).then((e) => {
|
|
390
|
+
let s = e;
|
|
391
|
+
return s ? s.conversationEndedBehavior = t : s = { conversationEndedBehavior: t }, this.sessionInfo = s, this.storageWriter && this.storageWriter(this.sessionInfo) || Promise.resolve();
|
|
622
392
|
});
|
|
623
393
|
}
|
|
624
|
-
createController(
|
|
625
|
-
const
|
|
626
|
-
|
|
627
|
-
return this.controllers[index].conversation;
|
|
628
|
-
}
|
|
629
|
-
return new ConversationController(this.container, id);
|
|
394
|
+
createController(t) {
|
|
395
|
+
const e = this.controllers.findIndex((s) => s.conversation.id === t);
|
|
396
|
+
return e > -1 ? this.controllers[e].conversation : new X(this.container, t);
|
|
630
397
|
}
|
|
631
|
-
registerProvider(
|
|
632
|
-
const
|
|
633
|
-
name,
|
|
634
|
-
handler
|
|
398
|
+
registerProvider(t, e) {
|
|
399
|
+
const s = {
|
|
400
|
+
name: t,
|
|
401
|
+
handler: e
|
|
635
402
|
};
|
|
636
|
-
this.providers.push(
|
|
637
|
-
|
|
638
|
-
this.invokeHandler(provider, controller);
|
|
403
|
+
this.providers.push(s), this.controllers.filter((r) => r.conversation.providers.indexOf(t) > -1).forEach((r) => {
|
|
404
|
+
this.invokeHandler(s, r);
|
|
639
405
|
});
|
|
640
406
|
}
|
|
641
|
-
registerController(
|
|
642
|
-
const
|
|
643
|
-
let
|
|
644
|
-
if (
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
this.invokeHandler(provider, controller);
|
|
651
|
-
});
|
|
652
|
-
}
|
|
407
|
+
registerController(t, e) {
|
|
408
|
+
const s = this.controllers.findIndex((n) => n.conversation.id === t.id);
|
|
409
|
+
let r;
|
|
410
|
+
if (s < 0) {
|
|
411
|
+
r = { conversation: t, component: e }, this.controllers.push(r);
|
|
412
|
+
const n = (o) => {
|
|
413
|
+
o && this.providers.filter((a) => o.indexOf(a.name) > -1).forEach((a) => {
|
|
414
|
+
this.invokeHandler(a, r);
|
|
415
|
+
});
|
|
653
416
|
};
|
|
654
|
-
this.subscriptions.push(
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
removed.forEach((removedProvider) => {
|
|
663
|
-
this.disposeProviders[removedProvider].forEach((dispose) => {
|
|
664
|
-
dispose();
|
|
417
|
+
return this.subscriptions.push(t.onDispose((o, a) => {
|
|
418
|
+
const c = this.controllers.findIndex((h) => h.conversation === a);
|
|
419
|
+
c > -1 && this.controllers.splice(c, 1), this.components.components().ofType("conversation-return-button").select().writeProperties({ active: !1 }), this.events.dispatch("conversation:ended", {}, { bubbles: !0 });
|
|
420
|
+
})), this.subscriptions.push(t.onProvidersChange((o, a) => {
|
|
421
|
+
const { added: c, removed: h } = a;
|
|
422
|
+
h.forEach((d) => {
|
|
423
|
+
this.disposeProviders[d].forEach((f) => {
|
|
424
|
+
f();
|
|
665
425
|
});
|
|
666
|
-
});
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
route: (_a = this.router) == null ? void 0 : _a.getRouteData(),
|
|
674
|
-
conversationEndedBehavior: (_b = this.sessionInfo) == null ? void 0 : _b.conversationEndedBehavior
|
|
426
|
+
}), n(c);
|
|
427
|
+
})), this.subscriptions.push(t.onStarted((o, a) => {
|
|
428
|
+
var h, d;
|
|
429
|
+
const c = {
|
|
430
|
+
id: t.id,
|
|
431
|
+
route: (h = this.router) == null ? void 0 : h.getRouteData(),
|
|
432
|
+
conversationEndedBehavior: (d = this.sessionInfo) == null ? void 0 : d.conversationEndedBehavior
|
|
675
433
|
};
|
|
676
|
-
this.sessionInfo =
|
|
677
|
-
|
|
678
|
-
this.writeToComponents({
|
|
679
|
-
}));
|
|
680
|
-
this.subscriptions.push(conversation.onUnreadMessage((event, data) => {
|
|
681
|
-
this.events.dispatch("conversation:unread-message", data);
|
|
682
|
-
this.writeToComponents({ alert: { show: data } });
|
|
683
|
-
}));
|
|
684
|
-
invokeHandlers(conversation.providers);
|
|
685
|
-
return true;
|
|
686
|
-
}
|
|
687
|
-
controller = this.controllers[index];
|
|
688
|
-
return false;
|
|
689
|
-
}
|
|
690
|
-
writeToComponents(properties, key = "conversationReturnButtonState") {
|
|
691
|
-
if (this.buttonQuery) {
|
|
692
|
-
this.components.write({
|
|
693
|
-
key: "conversationReturnButtonState",
|
|
694
|
-
attributes: { properties },
|
|
695
|
-
target: this.buttonQuery,
|
|
696
|
-
provider: "localStorage"
|
|
697
|
-
});
|
|
434
|
+
this.sessionInfo = c, this.storageWriter && this.storageWriter(c), this.writeToComponents({ active: a });
|
|
435
|
+
})), this.subscriptions.push(t.onUnreadMessage((o, a) => {
|
|
436
|
+
this.events.dispatch("conversation:unread-message", a), this.writeToComponents({ alert: { show: a } });
|
|
437
|
+
})), n(t.providers), !0;
|
|
698
438
|
}
|
|
439
|
+
return r = this.controllers[s], !1;
|
|
440
|
+
}
|
|
441
|
+
writeToComponents(t, e = "conversationReturnButtonState") {
|
|
442
|
+
this.buttonQuery && this.components.write({
|
|
443
|
+
key: "conversationReturnButtonState",
|
|
444
|
+
attributes: { properties: t },
|
|
445
|
+
target: this.buttonQuery,
|
|
446
|
+
provider: "localStorage"
|
|
447
|
+
});
|
|
699
448
|
}
|
|
700
|
-
invokeHandler(
|
|
701
|
-
const
|
|
702
|
-
|
|
703
|
-
if (!this.disposeProviders[provider.name]) {
|
|
704
|
-
this.disposeProviders[provider.name] = [];
|
|
705
|
-
}
|
|
706
|
-
this.disposeProviders[provider.name].push(dispose);
|
|
707
|
-
}
|
|
449
|
+
invokeHandler(t, e) {
|
|
450
|
+
const s = t.handler(e.conversation.createProvider(t.name), e.component);
|
|
451
|
+
s && (this.disposeProviders[t.name] || (this.disposeProviders[t.name] = []), this.disposeProviders[t.name].push(s));
|
|
708
452
|
}
|
|
709
453
|
getComponentRoute() {
|
|
710
|
-
return
|
|
454
|
+
return A(this.container, y, m.Local).then((t) => t == null ? void 0 : t.route);
|
|
711
455
|
}
|
|
712
456
|
dispose() {
|
|
713
|
-
Object.keys(this.disposeProviders).forEach((
|
|
714
|
-
this.disposeProviders[
|
|
715
|
-
|
|
457
|
+
Object.keys(this.disposeProviders).forEach((t) => {
|
|
458
|
+
this.disposeProviders[t].forEach((e) => {
|
|
459
|
+
e();
|
|
716
460
|
});
|
|
717
|
-
})
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
this
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
event.preventDefault();
|
|
728
|
-
let triggerEl = document.getElementById("humany-dynamic-anchor");
|
|
729
|
-
if (!triggerEl) {
|
|
730
|
-
triggerEl = document.createElement("a");
|
|
731
|
-
triggerEl.setAttribute("href", "#");
|
|
732
|
-
triggerEl.id = "humany-dynamic-anchor";
|
|
733
|
-
document.body.appendChild(triggerEl);
|
|
734
|
-
}
|
|
735
|
-
openChatWidget(container, contactMethod, triggerEl);
|
|
461
|
+
}), this.subscriptions.forEach((t) => {
|
|
462
|
+
t();
|
|
463
|
+
}), this.controllers = [], this.providers = [];
|
|
464
|
+
}
|
|
465
|
+
static handleContactMethodClick(t, e, s, r) {
|
|
466
|
+
return S(this, null, function* () {
|
|
467
|
+
if (tt(e)) {
|
|
468
|
+
t.preventDefault();
|
|
469
|
+
let n = document.getElementById("humany-dynamic-anchor");
|
|
470
|
+
n || (n = document.createElement("a"), n.setAttribute("href", "#"), n.id = "humany-dynamic-anchor", document.body.appendChild(n)), B(e, s, n);
|
|
736
471
|
}
|
|
737
|
-
|
|
472
|
+
B(e, s);
|
|
738
473
|
});
|
|
739
474
|
}
|
|
740
|
-
static handleContactMethodSubmit(
|
|
741
|
-
return
|
|
742
|
-
return
|
|
475
|
+
static handleContactMethodSubmit(t, e) {
|
|
476
|
+
return S(this, null, function* () {
|
|
477
|
+
return et(t, e);
|
|
743
478
|
});
|
|
744
479
|
}
|
|
745
480
|
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
481
|
+
var st = /* @__PURE__ */ ((i) => (i.Header = "header", i.LinkList = "link-list", i.Separator = "separator", i.NoGoodAlternative = "no-good-alternative", i.ButtonList = "button-list", i.Text = "text", i.HTML = "html", i.FeedbackList = "feedback-list", i))(st || {});
|
|
482
|
+
const it = (i, t) => i.reduce((e, s, r) => {
|
|
483
|
+
var o, a;
|
|
484
|
+
const n = g(p({}, s), {
|
|
485
|
+
content: [g(p({}, s.content), { key: s.key })]
|
|
486
|
+
});
|
|
487
|
+
if (e.length > 0 && s.type !== E.System) {
|
|
488
|
+
const c = e[e.length - 1];
|
|
489
|
+
if ((!t && t !== 0 || Math.abs(c.timestamp - s.timestamp) < t) && ((o = c.sender) == null ? void 0 : o.name) === ((a = s.sender) == null ? void 0 : a.name) && c.type === s.type)
|
|
490
|
+
return c.timestamp = s.timestamp, c.content.push(g(p({}, s.content), { key: s.key })), e;
|
|
491
|
+
}
|
|
492
|
+
return e.push(n), e;
|
|
493
|
+
}, []), lt = (i) => Promise.all([
|
|
494
|
+
b.getInstance(i),
|
|
495
|
+
i.getAsync("router")
|
|
496
|
+
]).then(([t, e]) => Q(i, "conversation", import("./conversation.3981560b.js"), (s) => {
|
|
497
|
+
const n = e.getRouteData().params.id || s.node.name || "component", o = t.createController(n), a = t.registerController(o, s), c = 3 * 60 * 1e3, h = (l) => {
|
|
498
|
+
const { providers: u = [] } = l;
|
|
499
|
+
if (u) {
|
|
500
|
+
const v = Array.isArray(u) ? u : [u];
|
|
501
|
+
return o.setProviders(v), v;
|
|
761
502
|
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
};
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
const { providers = [] } = properties;
|
|
779
|
-
if (providers) {
|
|
780
|
-
const providerKeys = Array.isArray(providers) ? providers : [providers];
|
|
781
|
-
conversation.setProviders(providerKeys);
|
|
782
|
-
return providerKeys;
|
|
783
|
-
}
|
|
784
|
-
};
|
|
785
|
-
setProperties(component.properties(setProperties));
|
|
786
|
-
conversation.setComponentMountedState(true);
|
|
787
|
-
const writeMessages = (messageStream) => {
|
|
788
|
-
const { loading, typingActors, messages } = messageStream;
|
|
789
|
-
component.writeProperties({
|
|
790
|
-
loading,
|
|
791
|
-
typingActors,
|
|
792
|
-
messages: groupedMessages(messages, messageGroupingTimeout)
|
|
793
|
-
});
|
|
794
|
-
};
|
|
795
|
-
writeMessages(conversation.getMessageStream());
|
|
796
|
-
if (isNewController) {
|
|
797
|
-
component.actions.create("user-submit", (data, options) => {
|
|
798
|
-
if (options) {
|
|
799
|
-
const { preventDefault, validationPromise } = options;
|
|
800
|
-
if (preventDefault) {
|
|
801
|
-
if (validationPromise) {
|
|
802
|
-
validationPromise().then((text) => {
|
|
803
|
-
if (text) {
|
|
804
|
-
conversation.user.print(text);
|
|
805
|
-
}
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
return;
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
conversation.user.print(data.text);
|
|
812
|
-
});
|
|
813
|
-
component.actions.create("user-typing", (data, options) => {
|
|
814
|
-
});
|
|
815
|
-
component.actions.create("form", (data, options) => {
|
|
816
|
-
});
|
|
817
|
-
component.actions.create("action", (data, options) => {
|
|
818
|
-
});
|
|
819
|
-
component.actions.create("overlay-mounted", (data, options) => {
|
|
820
|
-
});
|
|
821
|
-
component.actions.create("show-overlay", (data, options) => {
|
|
822
|
-
component.writeProperties({
|
|
823
|
-
overlay: { conversation: false, secondary: false }
|
|
824
|
-
});
|
|
825
|
-
});
|
|
826
|
-
component.actions.create("hide-overlay", (data, options) => {
|
|
827
|
-
component.writeProperties({
|
|
828
|
-
overlay: null
|
|
829
|
-
});
|
|
830
|
-
});
|
|
831
|
-
component.actions.create("show-overlay-conversation", (data, options) => {
|
|
832
|
-
component.writeProperties({
|
|
833
|
-
overlay: { conversation: true, secondary: false }
|
|
834
|
-
});
|
|
835
|
-
});
|
|
836
|
-
component.actions.create("hide-overlay-conversation", (data, options) => {
|
|
837
|
-
component.writeProperties({
|
|
838
|
-
overlay: { conversation: false, secondary: false }
|
|
839
|
-
});
|
|
503
|
+
};
|
|
504
|
+
h(s.properties(h)), o.setComponentMountedState(!0);
|
|
505
|
+
const d = (l) => {
|
|
506
|
+
const { loading: u, typingActors: v, messages: w } = l;
|
|
507
|
+
s.writeProperties({
|
|
508
|
+
loading: u,
|
|
509
|
+
typingActors: v,
|
|
510
|
+
messages: it(w, c)
|
|
511
|
+
});
|
|
512
|
+
};
|
|
513
|
+
d(o.getMessageStream()), a && (s.actions.create("user-submit", (l, u) => {
|
|
514
|
+
if (u) {
|
|
515
|
+
const { preventDefault: v, validationPromise: w } = u;
|
|
516
|
+
if (v) {
|
|
517
|
+
w && w().then((W) => {
|
|
518
|
+
W && o.user.print(W);
|
|
840
519
|
});
|
|
520
|
+
return;
|
|
841
521
|
}
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
}
|
|
851
|
-
};
|
|
852
|
-
}, { reuseController: true });
|
|
522
|
+
}
|
|
523
|
+
o.user.print(l.text);
|
|
524
|
+
}), s.actions.create("user-typing", (l, u) => {
|
|
525
|
+
}), s.actions.create("form", (l, u) => {
|
|
526
|
+
}), s.actions.create("action", (l, u) => {
|
|
527
|
+
}));
|
|
528
|
+
const f = o.events.subscribe("conversation:updated", (l, u) => {
|
|
529
|
+
d(u);
|
|
853
530
|
});
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
});
|
|
867
|
-
});
|
|
531
|
+
return () => {
|
|
532
|
+
o.setComponentMountedState(!1), f(), o.active || d({ messages: [], typingActors: [], loading: !1 });
|
|
533
|
+
};
|
|
534
|
+
}, { reuseController: !0 })), pt = (i) => Promise.all([
|
|
535
|
+
H.getInstance(i),
|
|
536
|
+
b.getInstance(i),
|
|
537
|
+
i.getAsync("router")
|
|
538
|
+
]).then(([t, e, s]) => Q(i, "conversation-return-button", import("./return-button.8773c0de.js"), (r) => {
|
|
539
|
+
r.actions.create("toggle", (n = {}) => {
|
|
540
|
+
var o;
|
|
541
|
+
(o = e.getComponentRoute()) == null || o.then((a) => {
|
|
542
|
+
a && s.navigate(a.name, a.params);
|
|
868
543
|
});
|
|
869
544
|
});
|
|
545
|
+
})), vt = (i, t, e) => i.getAsync("componentResolver").then((s) => S(void 0, null, function* () {
|
|
546
|
+
(yield b.getInstance(i)).addSubscription(s.registerComponent(t, K(() => e)));
|
|
547
|
+
}));
|
|
548
|
+
export {
|
|
549
|
+
lt as ConversationComponent,
|
|
550
|
+
X as ConversationController,
|
|
551
|
+
P as ConversationEndedBehavior,
|
|
552
|
+
q as ConversationEntry,
|
|
553
|
+
st as ConversationMessageListItemType,
|
|
554
|
+
E as ConversationMessageType,
|
|
555
|
+
b as ConversationPlatform,
|
|
556
|
+
pt as ConversationReturnButtonComponent,
|
|
557
|
+
vt as registerCustomMessageComponent
|
|
870
558
|
};
|
|
871
|
-
var ConversationMessageListItemType = /* @__PURE__ */ ((ConversationMessageListItemType2) => {
|
|
872
|
-
ConversationMessageListItemType2["LinkList"] = "link-list";
|
|
873
|
-
ConversationMessageListItemType2["Separator"] = "separator";
|
|
874
|
-
ConversationMessageListItemType2["ButtonList"] = "button-list";
|
|
875
|
-
ConversationMessageListItemType2["Text"] = "text";
|
|
876
|
-
ConversationMessageListItemType2["HTML"] = "html";
|
|
877
|
-
ConversationMessageListItemType2["VideoRequest"] = "video-request";
|
|
878
|
-
return ConversationMessageListItemType2;
|
|
879
|
-
})(ConversationMessageListItemType || {});
|
|
880
|
-
const registerCustomMessageComponent = (container, type, component) => {
|
|
881
|
-
return container.getAsync("componentResolver").then((o) => __async(this, null, function* () {
|
|
882
|
-
const platform = yield ConversationPlatform.getInstance(container);
|
|
883
|
-
platform.addSubscription(o.registerComponent(type, lazy(() => component)));
|
|
884
|
-
}));
|
|
885
|
-
};
|
|
886
|
-
export { ConversationComponent, ConversationController, ConversationEndedBehavior, ConversationEntry, ConversationMessageListItemType, ConversationMessageType, ConversationPlatform, ConversationReturnButtonComponent, registerCustomMessageComponent };
|
|
887
559
|
//# sourceMappingURL=index.js.map
|