@meetelise/chat 1.47.1 → 1.48.0
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/src/main/MEChat.d.ts +43 -2
- package/package.json +1 -1
- package/public/dist/index.js +36 -36
- package/src/main/MEChat.ts +168 -4
- package/src/replaceSelectButtonsWithNewLink.ts +3 -1
package/src/main/MEChat.ts
CHANGED
|
@@ -34,6 +34,47 @@ interface PositioningOptions {
|
|
|
34
34
|
export interface HealthcareOptions extends PositioningOptions {
|
|
35
35
|
id: string;
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
export type StudioWebchatMode = "host_managed_context";
|
|
39
|
+
|
|
40
|
+
export type StudioWebchatSessionScopeType =
|
|
41
|
+
| "building"
|
|
42
|
+
| "building_group"
|
|
43
|
+
| "site";
|
|
44
|
+
|
|
45
|
+
export interface StudioWebchatSessionScope {
|
|
46
|
+
type: StudioWebchatSessionScopeType;
|
|
47
|
+
key: string;
|
|
48
|
+
buildingSlug?: string;
|
|
49
|
+
siteId?: string;
|
|
50
|
+
buildingGroupId?: string | number;
|
|
51
|
+
defaultBuildingSlug?: string;
|
|
52
|
+
allowedBuildingSlugs?: string[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface StudioWebchatContext {
|
|
56
|
+
source?: "elise_studio";
|
|
57
|
+
siteId?: string;
|
|
58
|
+
propertyId?: string | number | null;
|
|
59
|
+
organization?: string | null;
|
|
60
|
+
building?: string | null;
|
|
61
|
+
buildingGroupId?: string | number | null;
|
|
62
|
+
sessionScope?: StudioWebchatSessionScope;
|
|
63
|
+
path?: string;
|
|
64
|
+
pageId?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface StudioWebchatClearContext {
|
|
68
|
+
source?: "elise_studio";
|
|
69
|
+
reason?: "no_property_for_route" | "webchat_disabled" | "ambiguous_route" | string;
|
|
70
|
+
preserveCache?: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface StudioWebchatOptions {
|
|
74
|
+
siteId: string;
|
|
75
|
+
mode?: StudioWebchatMode;
|
|
76
|
+
}
|
|
77
|
+
|
|
37
78
|
export default class MEChat {
|
|
38
79
|
static meChat: MEChatLitElement | null = null;
|
|
39
80
|
static healthChat: HealthChatLitElement | null = null;
|
|
@@ -45,6 +86,11 @@ export default class MEChat {
|
|
|
45
86
|
static brandColor = "";
|
|
46
87
|
static backgroundColor = "";
|
|
47
88
|
static healthcareId = "";
|
|
89
|
+
static activeStudioOrgSlug = "";
|
|
90
|
+
static activeStudioBuildingSlug = "";
|
|
91
|
+
static activeStudioSessionScopeKey = "";
|
|
92
|
+
static activeStudioOptions: Options | null = null;
|
|
93
|
+
static studioUpdateToken = 0;
|
|
48
94
|
static overridePlacement: {
|
|
49
95
|
right?: number;
|
|
50
96
|
bottom?: number;
|
|
@@ -91,7 +137,7 @@ export default class MEChat {
|
|
|
91
137
|
this.orgSlug =
|
|
92
138
|
opts.organization === "Pacific Urban Residential"
|
|
93
139
|
? "cbc11aba-21c4-4571-bc43-ff9d86a029e3"
|
|
94
|
-
: opts.organization;
|
|
140
|
+
: opts.organization || "";
|
|
95
141
|
this.hasBuildingSlug = !!opts.building;
|
|
96
142
|
this.overridePlacement = {
|
|
97
143
|
right: opts?.position?.right,
|
|
@@ -102,6 +148,11 @@ export default class MEChat {
|
|
|
102
148
|
}
|
|
103
149
|
installFont();
|
|
104
150
|
|
|
151
|
+
if (opts.studio && !opts.building) {
|
|
152
|
+
this.handleStudioContext(opts);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
105
156
|
let meChatElement:
|
|
106
157
|
| MEChatLitElement
|
|
107
158
|
| UtilitiesChatElement
|
|
@@ -131,7 +182,7 @@ export default class MEChat {
|
|
|
131
182
|
"orgSlug",
|
|
132
183
|
opts.organization === "Pacific Urban Residential"
|
|
133
184
|
? "cbc11aba-21c4-4571-bc43-ff9d86a029e3"
|
|
134
|
-
: opts.organization
|
|
185
|
+
: opts.organization || ""
|
|
135
186
|
);
|
|
136
187
|
meChatElement.setAttribute(
|
|
137
188
|
"widgetType",
|
|
@@ -216,6 +267,15 @@ export default class MEChat {
|
|
|
216
267
|
}
|
|
217
268
|
|
|
218
269
|
static async remove(): Promise<void> {
|
|
270
|
+
this.studioUpdateToken += 1;
|
|
271
|
+
await this.removeWidget();
|
|
272
|
+
this.activeStudioOrgSlug = "";
|
|
273
|
+
this.activeStudioBuildingSlug = "";
|
|
274
|
+
this.activeStudioSessionScopeKey = "";
|
|
275
|
+
this.activeStudioOptions = null;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
static async removeWidget(): Promise<void> {
|
|
219
279
|
if (!this.meChat) {
|
|
220
280
|
return;
|
|
221
281
|
}
|
|
@@ -224,6 +284,84 @@ export default class MEChat {
|
|
|
224
284
|
MEChat.meChat = null;
|
|
225
285
|
}
|
|
226
286
|
|
|
287
|
+
static handleStudioContext(opts: Options): void {
|
|
288
|
+
if (!opts.studio) return;
|
|
289
|
+
|
|
290
|
+
this.activeStudioOptions = opts;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
static updateStudioContext(context: StudioWebchatContext): void {
|
|
294
|
+
const opts = this.activeStudioOptions;
|
|
295
|
+
if (!opts?.studio) return;
|
|
296
|
+
const updateToken = ++this.studioUpdateToken;
|
|
297
|
+
|
|
298
|
+
if (context.siteId && context.siteId !== opts.studio.siteId) {
|
|
299
|
+
sendLoggingEvent({
|
|
300
|
+
logType: LogType.warn,
|
|
301
|
+
logTitle: "[STUDIO_WEBCHAT_CONTEXT_SITE_MISMATCH]",
|
|
302
|
+
logData: {
|
|
303
|
+
activeSiteId: opts.studio.siteId,
|
|
304
|
+
contextSiteId: context.siteId,
|
|
305
|
+
url: window.location.href,
|
|
306
|
+
},
|
|
307
|
+
});
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const orgSlug = coerceStudioContextString(context.organization);
|
|
312
|
+
const buildingSlug = coerceStudioContextString(context.building);
|
|
313
|
+
|
|
314
|
+
if (!orgSlug || !buildingSlug) {
|
|
315
|
+
this.clearStudioContext({
|
|
316
|
+
source: "elise_studio",
|
|
317
|
+
reason: "missing_context",
|
|
318
|
+
preserveCache: true,
|
|
319
|
+
});
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const sessionScopeKey = coerceStudioSessionScopeKey(
|
|
324
|
+
context.sessionScope,
|
|
325
|
+
buildingSlug
|
|
326
|
+
);
|
|
327
|
+
const normalizedOrgSlug = normalizeOrgSlug(orgSlug);
|
|
328
|
+
|
|
329
|
+
if (
|
|
330
|
+
this.activeStudioOrgSlug === normalizedOrgSlug &&
|
|
331
|
+
this.activeStudioBuildingSlug === buildingSlug &&
|
|
332
|
+
this.activeStudioSessionScopeKey === sessionScopeKey
|
|
333
|
+
) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
void this.removeWidget().then(() => {
|
|
338
|
+
if (updateToken !== this.studioUpdateToken) return;
|
|
339
|
+
|
|
340
|
+
this.activeStudioOrgSlug = normalizedOrgSlug;
|
|
341
|
+
this.activeStudioBuildingSlug = buildingSlug;
|
|
342
|
+
this.activeStudioSessionScopeKey = sessionScopeKey;
|
|
343
|
+
this.orgSlug = normalizedOrgSlug;
|
|
344
|
+
|
|
345
|
+
this.start(
|
|
346
|
+
{
|
|
347
|
+
...opts,
|
|
348
|
+
organization: orgSlug,
|
|
349
|
+
building: buildingSlug,
|
|
350
|
+
},
|
|
351
|
+
false
|
|
352
|
+
);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
static clearStudioContext(_context?: StudioWebchatClearContext): void {
|
|
357
|
+
void _context;
|
|
358
|
+
this.studioUpdateToken += 1;
|
|
359
|
+
this.activeStudioOrgSlug = "";
|
|
360
|
+
this.activeStudioBuildingSlug = "";
|
|
361
|
+
this.activeStudioSessionScopeKey = "";
|
|
362
|
+
void this.removeWidget();
|
|
363
|
+
}
|
|
364
|
+
|
|
227
365
|
static async handleBuildingslug(
|
|
228
366
|
meChat: MEChatLitElement,
|
|
229
367
|
orgSlug?: string,
|
|
@@ -369,9 +507,35 @@ export default class MEChat {
|
|
|
369
507
|
}
|
|
370
508
|
}
|
|
371
509
|
|
|
510
|
+
function coerceStudioContextString(value: string | null | undefined): string {
|
|
511
|
+
if (typeof value !== "string") {
|
|
512
|
+
return "";
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
return value.trim();
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function normalizeOrgSlug(orgSlug: string): string {
|
|
519
|
+
return orgSlug === "Pacific Urban Residential"
|
|
520
|
+
? "cbc11aba-21c4-4571-bc43-ff9d86a029e3"
|
|
521
|
+
: orgSlug;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function coerceStudioSessionScopeKey(
|
|
525
|
+
sessionScope: StudioWebchatSessionScope | undefined,
|
|
526
|
+
buildingSlug: string
|
|
527
|
+
): string {
|
|
528
|
+
if (!sessionScope?.key) {
|
|
529
|
+
return `building:${buildingSlug}`;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
return sessionScope.key;
|
|
533
|
+
}
|
|
534
|
+
|
|
372
535
|
export interface Options {
|
|
373
|
-
building
|
|
374
|
-
organization
|
|
536
|
+
building?: string;
|
|
537
|
+
organization?: string;
|
|
538
|
+
studio?: StudioWebchatOptions;
|
|
375
539
|
avatarSrc?: string;
|
|
376
540
|
mini?: boolean;
|
|
377
541
|
launcherStyles?: StyleInfo;
|
|
@@ -94,7 +94,9 @@ const getMutatedApplicationLink = (
|
|
|
94
94
|
"apply here",
|
|
95
95
|
];
|
|
96
96
|
if (relevantText.some((t) => buttonText.toLowerCase().includes(t))) {
|
|
97
|
-
return
|
|
97
|
+
return newApplicationLink.endsWith("/units")
|
|
98
|
+
? newApplicationLink
|
|
99
|
+
: `${newApplicationLink}/units`;
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
return newApplicationLink;
|