@ada-support/embed2 1.8.4 → 1.8.5
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.
|
@@ -37,6 +37,7 @@ export interface EmbedRequestPayloadByEvent {
|
|
|
37
37
|
TRIGGER_PROACTIVE: TriggerProactiveParams;
|
|
38
38
|
INJECT_PROACTIVE_CONVERSATION: {
|
|
39
39
|
key: string;
|
|
40
|
+
messageParams: Record<string, string>;
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
export declare type EmbedRequestEvent = keyof EmbedRequestPayloadByEvent;
|
package/dist/npm-entry/index.js
CHANGED
|
@@ -13949,7 +13949,7 @@ const client = new BrowserClient({
|
|
|
13949
13949
|
return event;
|
|
13950
13950
|
},
|
|
13951
13951
|
environment: "production",
|
|
13952
|
-
release: "1.8.
|
|
13952
|
+
release: "1.8.5-7c0137e",
|
|
13953
13953
|
sampleRate: 0.25,
|
|
13954
13954
|
autoSessionTracking: false,
|
|
13955
13955
|
// Integrations don't seem to work with Sentry: https://github.com/getsentry/sentry-javascript/issues/2541
|
|
@@ -14524,7 +14524,7 @@ function getEmbedURL(_ref) {
|
|
|
14524
14524
|
} else {
|
|
14525
14525
|
host = `http://${handle}.localhost:9001`;
|
|
14526
14526
|
}
|
|
14527
|
-
return `${host}/embed/${frameName}/${"
|
|
14527
|
+
return `${host}/embed/${frameName}/${"7c0137e"}/index.html`;
|
|
14528
14528
|
}
|
|
14529
14529
|
function constructQueryString(query) {
|
|
14530
14530
|
return Object.keys(query).map(key => {
|
|
@@ -15702,9 +15702,9 @@ async function log(message, extra, options) {
|
|
|
15702
15702
|
service: "embed",
|
|
15703
15703
|
env: "production",
|
|
15704
15704
|
embedVersion: 2,
|
|
15705
|
-
version: "1.8.
|
|
15705
|
+
version: "1.8.5",
|
|
15706
15706
|
isNpm: true,
|
|
15707
|
-
commitHash: "
|
|
15707
|
+
commitHash: "7c0137e"
|
|
15708
15708
|
}))
|
|
15709
15709
|
});
|
|
15710
15710
|
}
|
|
@@ -16276,25 +16276,51 @@ function recordProactiveTrigger(proactiveConversationKey, frequency, handle) {
|
|
|
16276
16276
|
function proactiveTriggerImpl(_ref) {
|
|
16277
16277
|
let {
|
|
16278
16278
|
proactiveConversation,
|
|
16279
|
-
messageKey,
|
|
16280
16279
|
adaSettings,
|
|
16281
16280
|
messageService,
|
|
16282
|
-
|
|
16281
|
+
setRecentProactiveConversationConfig,
|
|
16283
16282
|
clearProactiveConversation
|
|
16284
16283
|
} = _ref;
|
|
16285
16284
|
const {
|
|
16286
16285
|
handle
|
|
16287
16286
|
} = adaSettings;
|
|
16287
|
+
const {
|
|
16288
|
+
key,
|
|
16289
|
+
params = {},
|
|
16290
|
+
is_template: isTemplate
|
|
16291
|
+
} = proactiveConversation;
|
|
16292
|
+
const messageKey = String(key);
|
|
16288
16293
|
const {
|
|
16289
16294
|
duration,
|
|
16290
16295
|
delay,
|
|
16291
16296
|
frequency,
|
|
16292
16297
|
active
|
|
16293
16298
|
} = proactiveConversation.modality_config.chat;
|
|
16299
|
+
const lang = adaSettings.language || get_browser_language();
|
|
16300
|
+
let proactiveMessage = proactiveConversation.messages[lang][0];
|
|
16294
16301
|
if (!active) {
|
|
16295
16302
|
warn("Proactive message is not active");
|
|
16296
16303
|
return;
|
|
16297
16304
|
}
|
|
16305
|
+
if (isTemplate) {
|
|
16306
|
+
if (Object.keys(params).length === 0) {
|
|
16307
|
+
warn("Proactive message is a template but no parameters were provided");
|
|
16308
|
+
return;
|
|
16309
|
+
}
|
|
16310
|
+
|
|
16311
|
+
// Replace the template variables with the param values
|
|
16312
|
+
const missingParams = [];
|
|
16313
|
+
proactiveMessage = proactiveMessage.replace(/{{(.*?)}}/g, (match, variableKey) => {
|
|
16314
|
+
if (!(variableKey in params)) {
|
|
16315
|
+
missingParams.push(variableKey);
|
|
16316
|
+
}
|
|
16317
|
+
return params[variableKey];
|
|
16318
|
+
});
|
|
16319
|
+
if (missingParams.length > 0) {
|
|
16320
|
+
warn(`Missing parameters for template message: ${missingParams.join(", ")}`);
|
|
16321
|
+
return;
|
|
16322
|
+
}
|
|
16323
|
+
}
|
|
16298
16324
|
|
|
16299
16325
|
// Check if the proactive message has been shown within the specified frequency
|
|
16300
16326
|
const doesPassFrequencyCheck = !proactiveShownWithinFrequency(messageKey, frequency, handle);
|
|
@@ -16304,13 +16330,14 @@ function proactiveTriggerImpl(_ref) {
|
|
|
16304
16330
|
|
|
16305
16331
|
// Record the proactive message as being shown
|
|
16306
16332
|
recordProactiveTrigger(messageKey, frequency, handle);
|
|
16307
|
-
|
|
16333
|
+
setRecentProactiveConversationConfig({
|
|
16334
|
+
key: messageKey,
|
|
16335
|
+
params
|
|
16336
|
+
});
|
|
16308
16337
|
clearProactiveConversation();
|
|
16309
16338
|
const localChannel = messageService.getChannel("local");
|
|
16310
|
-
const lang = adaSettings.language || get_browser_language();
|
|
16311
|
-
const message = proactiveConversation.messages[lang][0];
|
|
16312
16339
|
localChannel.postMessage(CREATE_PROACTIVE, {
|
|
16313
|
-
body:
|
|
16340
|
+
body: proactiveMessage,
|
|
16314
16341
|
duration,
|
|
16315
16342
|
delay
|
|
16316
16343
|
});
|
|
@@ -16853,7 +16880,7 @@ class ChatFrame extends d {
|
|
|
16853
16880
|
const hostPageUrlParams = new URL(window.location.href).searchParams;
|
|
16854
16881
|
const smsToken = hostPageUrlParams.get("adaSMSToken");
|
|
16855
16882
|
const queryParams = {
|
|
16856
|
-
embedVersion: "
|
|
16883
|
+
embedVersion: "7c0137e".slice(0, 7),
|
|
16857
16884
|
greeting,
|
|
16858
16885
|
language,
|
|
16859
16886
|
skipGreeting,
|
|
@@ -17730,7 +17757,7 @@ class Container extends d {
|
|
|
17730
17757
|
chatVersion: undefined,
|
|
17731
17758
|
readyToRenderChatFrame: false,
|
|
17732
17759
|
proactiveConversation: null,
|
|
17733
|
-
|
|
17760
|
+
recentProactiveConversationConfig: null
|
|
17734
17761
|
});
|
|
17735
17762
|
_defineProperty(this, "resetChatBound", this.resetChat.bind(this));
|
|
17736
17763
|
_defineProperty(this, "locationChangeHandlerBound", this.locationChangeHandler.bind(this));
|
|
@@ -17847,7 +17874,7 @@ class Container extends d {
|
|
|
17847
17874
|
campaignTriggerOptions,
|
|
17848
17875
|
followUpResponseId,
|
|
17849
17876
|
proactiveConversation,
|
|
17850
|
-
|
|
17877
|
+
recentProactiveConversationConfig
|
|
17851
17878
|
} = this.state;
|
|
17852
17879
|
|
|
17853
17880
|
/* We wait for all necessary preconditions (e.g. necessary connections established) to be true,
|
|
@@ -17876,11 +17903,10 @@ class Container extends d {
|
|
|
17876
17903
|
if (proactiveConversation && appConnectionState === ConnectionState.Done) {
|
|
17877
17904
|
proactiveTriggerImpl({
|
|
17878
17905
|
proactiveConversation,
|
|
17879
|
-
messageKey: proactiveConversation.key,
|
|
17880
17906
|
adaSettings,
|
|
17881
17907
|
messageService,
|
|
17882
|
-
|
|
17883
|
-
|
|
17908
|
+
setRecentProactiveConversationConfig: config => this.setState({
|
|
17909
|
+
recentProactiveConversationConfig: config
|
|
17884
17910
|
}),
|
|
17885
17911
|
clearProactiveConversation: () => this.setState({
|
|
17886
17912
|
proactiveConversation: null
|
|
@@ -17906,7 +17932,7 @@ class Container extends d {
|
|
|
17906
17932
|
});
|
|
17907
17933
|
}
|
|
17908
17934
|
}
|
|
17909
|
-
if (isChatWebsocketConnected && isDrawerOpen &&
|
|
17935
|
+
if (isChatWebsocketConnected && isDrawerOpen && recentProactiveConversationConfig) {
|
|
17910
17936
|
const chatChannel = messageService.getChannel(CHAT_IFRAME);
|
|
17911
17937
|
if (chatChannel) {
|
|
17912
17938
|
// Set meta field to indicate that a proactive conversation has been injected
|
|
@@ -17917,14 +17943,15 @@ class Container extends d {
|
|
|
17917
17943
|
}
|
|
17918
17944
|
});
|
|
17919
17945
|
chatChannel.postMessage(INJECT_PROACTIVE_CONVERSATION, {
|
|
17920
|
-
key:
|
|
17946
|
+
key: recentProactiveConversationConfig.key,
|
|
17947
|
+
messageParams: recentProactiveConversationConfig.params
|
|
17921
17948
|
});
|
|
17922
17949
|
log("Proactive message clicked", {
|
|
17923
17950
|
handle: adaSettings.handle,
|
|
17924
17951
|
embedSettings: adaSettings
|
|
17925
17952
|
});
|
|
17926
17953
|
this.setState({
|
|
17927
|
-
|
|
17954
|
+
recentProactiveConversationConfig: null
|
|
17928
17955
|
});
|
|
17929
17956
|
}
|
|
17930
17957
|
}
|
|
@@ -18147,7 +18174,8 @@ class Container extends d {
|
|
|
18147
18174
|
Object.entries(proactiveConversations).forEach(_ref => {
|
|
18148
18175
|
let [key, conversation] = _ref;
|
|
18149
18176
|
const chatConfig = conversation.modality_config.chat;
|
|
18150
|
-
|
|
18177
|
+
const isTemplate = conversation.is_template;
|
|
18178
|
+
if (chatConfig.active && !isTemplate && evaluateUrlTriggerConditions(chatConfig.url_trigger_conditions, currentUrl)) {
|
|
18151
18179
|
this.handleProactiveTrigger(Container_objectSpread({
|
|
18152
18180
|
key
|
|
18153
18181
|
}, conversation));
|
|
@@ -18435,12 +18463,14 @@ class Container extends d {
|
|
|
18435
18463
|
throw new AdaEmbedError("`client` is not defined");
|
|
18436
18464
|
}
|
|
18437
18465
|
const {
|
|
18438
|
-
messageKey
|
|
18466
|
+
messageKey,
|
|
18467
|
+
params
|
|
18439
18468
|
} = payload;
|
|
18440
18469
|
if ((_client$proactive_con = client.proactive_conversations) !== null && _client$proactive_con !== void 0 && _client$proactive_con[messageKey]) {
|
|
18441
18470
|
const proactiveConversation = client.proactive_conversations[messageKey];
|
|
18442
18471
|
this.handleProactiveTrigger(Container_objectSpread(Container_objectSpread({}, proactiveConversation), {}, {
|
|
18443
|
-
key: messageKey
|
|
18472
|
+
key: messageKey,
|
|
18473
|
+
params
|
|
18444
18474
|
}));
|
|
18445
18475
|
} else {
|
|
18446
18476
|
warn(`Proactive message with key ${messageKey} not found`);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { StartOptions } from "@ada-support/embed-types";
|
|
2
2
|
import type { MessageService } from "client/lib/message-service";
|
|
3
|
-
import type { ProactiveConversation, UrlTriggerCondition } from "./types";
|
|
4
|
-
export declare function proactiveTriggerImpl({ proactiveConversation,
|
|
3
|
+
import type { ProactiveConversation, RecentProactiveConversationConfig, UrlTriggerCondition } from "./types";
|
|
4
|
+
export declare function proactiveTriggerImpl({ proactiveConversation, adaSettings, messageService, setRecentProactiveConversationConfig, clearProactiveConversation, }: {
|
|
5
5
|
proactiveConversation: ProactiveConversation;
|
|
6
|
-
messageKey: string;
|
|
7
6
|
adaSettings: StartOptions;
|
|
8
7
|
messageService: MessageService;
|
|
9
|
-
|
|
8
|
+
setRecentProactiveConversationConfig: (config: RecentProactiveConversationConfig) => void;
|
|
10
9
|
clearProactiveConversation: () => void;
|
|
11
10
|
}): void;
|
|
12
11
|
export declare function evaluateUrlTriggerConditions(conditions: UrlTriggerCondition[], url: string): boolean;
|
|
@@ -11,11 +11,17 @@ export interface ProactiveConversation {
|
|
|
11
11
|
frequency: ProactiveConversationFrequency;
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
|
+
is_template: boolean;
|
|
15
|
+
params?: Record<string, string>;
|
|
14
16
|
key?: string;
|
|
15
17
|
}
|
|
16
18
|
export interface ProactiveConversations {
|
|
17
19
|
[messageKey: string]: ProactiveConversation;
|
|
18
20
|
}
|
|
21
|
+
export interface RecentProactiveConversationConfig {
|
|
22
|
+
key: string;
|
|
23
|
+
params: Record<string, string>;
|
|
24
|
+
}
|
|
19
25
|
export declare type ProactiveConversationFrequency = "always" | "session";
|
|
20
26
|
export declare type ProactiveConversationUrlTriggerConditionType = "equals" | "ends-with" | "regex" | "contains";
|
|
21
27
|
export interface UrlTriggerCondition {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ada-support/embed2",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/npm-entry",
|
|
6
6
|
"typings": "dist/npm-entry/index-npm.d.ts",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"webpack-merge": "^5.8.0"
|
|
97
97
|
},
|
|
98
98
|
"dependencies": {
|
|
99
|
-
"@ada-support/embed-types": "^1.8.
|
|
99
|
+
"@ada-support/embed-types": "^1.8.1",
|
|
100
100
|
"@ada-support/web-storage": "^1.2.9",
|
|
101
101
|
"@babel/runtime-corejs3": "^7.15.4",
|
|
102
102
|
"@sentry/browser": "^8.33.0",
|