@ada-support/embed2 1.8.4 → 1.8.6

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.
@@ -2,12 +2,14 @@ export declare enum ActionCreators {
2
2
  SET_STATE_ACTION = "setState",
3
3
  TOGGLE_CHAT_ACTION = "toggleChat",
4
4
  SET_CONNECTION_STATE = "setConnectionState",
5
- SEND_UNREAD_MESSAGES_ACTION = "sendUnreadMessages"
5
+ SEND_UNREAD_MESSAGES_ACTION = "sendUnreadMessages",
6
+ FOCUS_OFF_ADA_ACTION = "focusOffAda"
6
7
  }
7
8
  export declare enum ActionTypes {
8
9
  SET_STATE_TYPE = "SET_STATE",
9
10
  TOGGLE_CHAT_TYPE = "TOGGLE_CHAT",
10
11
  SET_META_FIELDS_TYPE = "SET_META_FIELDS",
11
12
  SET_CONNECTION_STATE_TYPE = "SET_CONNECTION_STATE",
12
- INCREMENT_MESSAGE_COUNT_TYPE = "INCREMENT_MESSAGE_COUNT"
13
+ INCREMENT_MESSAGE_COUNT_TYPE = "INCREMENT_MESSAGE_COUNT",
14
+ FOCUS_OFF_ADA_TYPE = "FOCUS_OFF_ADA"
13
15
  }
@@ -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;
@@ -14,6 +14,7 @@ export interface StoreState extends StartOptionsNoFunction {
14
14
  zdMessagingExternalUserId?: string | null;
15
15
  zdMessagingChatterCreated?: string | null;
16
16
  drawerHasBeenOpened: boolean;
17
+ focusIsOnAda: boolean;
17
18
  isIntroShown: boolean;
18
19
  isButtonShown: boolean;
19
20
  introDimensions: {
@@ -13949,7 +13949,7 @@ const client = new BrowserClient({
13949
13949
  return event;
13950
13950
  },
13951
13951
  environment: "production",
13952
- release: "1.8.4-20e63ea",
13952
+ release: "1.8.6-e6fb8a1",
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
@@ -14386,6 +14386,7 @@ let ActionCreators = /*#__PURE__*/function (ActionCreators) {
14386
14386
  ActionCreators["TOGGLE_CHAT_ACTION"] = "toggleChat";
14387
14387
  ActionCreators["SET_CONNECTION_STATE"] = "setConnectionState";
14388
14388
  ActionCreators["SEND_UNREAD_MESSAGES_ACTION"] = "sendUnreadMessages";
14389
+ ActionCreators["FOCUS_OFF_ADA_ACTION"] = "focusOffAda";
14389
14390
  return ActionCreators;
14390
14391
  }({});
14391
14392
  let ActionTypes = /*#__PURE__*/function (ActionTypes) {
@@ -14394,6 +14395,7 @@ let ActionTypes = /*#__PURE__*/function (ActionTypes) {
14394
14395
  ActionTypes["SET_META_FIELDS_TYPE"] = "SET_META_FIELDS";
14395
14396
  ActionTypes["SET_CONNECTION_STATE_TYPE"] = "SET_CONNECTION_STATE";
14396
14397
  ActionTypes["INCREMENT_MESSAGE_COUNT_TYPE"] = "INCREMENT_MESSAGE_COUNT";
14398
+ ActionTypes["FOCUS_OFF_ADA_TYPE"] = "FOCUS_OFF_ADA";
14397
14399
  return ActionTypes;
14398
14400
  }({});
14399
14401
  ;// CONCATENATED MODULE: ./src/client/helpers/event-subscriptions/index.ts
@@ -14524,7 +14526,7 @@ function getEmbedURL(_ref) {
14524
14526
  } else {
14525
14527
  host = `http://${handle}.localhost:9001`;
14526
14528
  }
14527
- return `${host}/embed/${frameName}/${"20e63ea"}/index.html`;
14529
+ return `${host}/embed/${frameName}/${"e6fb8a1"}/index.html`;
14528
14530
  }
14529
14531
  function constructQueryString(query) {
14530
14532
  return Object.keys(query).map(key => {
@@ -14711,6 +14713,15 @@ const actions = {
14711
14713
  type: ActionTypes.SET_CONNECTION_STATE_TYPE,
14712
14714
  payload: payload
14713
14715
  };
14716
+ },
14717
+ focusOffAda: _ref5 => {
14718
+ let {
14719
+ payload
14720
+ } = _ref5;
14721
+ return {
14722
+ type: ActionTypes.FOCUS_OFF_ADA_TYPE,
14723
+ payload: payload
14724
+ };
14714
14725
  }
14715
14726
  };
14716
14727
  // EXTERNAL MODULE: ./node_modules/@ada-support/web-storage/dist/index.js
@@ -14740,6 +14751,7 @@ const mutations = (state, action) => {
14740
14751
  isDrawerOpen: !state.isDrawerOpen,
14741
14752
  isIntroShown: false,
14742
14753
  drawerHasBeenOpened: true,
14754
+ focusIsOnAda: true,
14743
14755
  unreadMessageCount: 0,
14744
14756
  hasChatOpenedAfterProactiveMessagesShown
14745
14757
  });
@@ -14779,6 +14791,12 @@ const mutations = (state, action) => {
14779
14791
  appConnectionState
14780
14792
  });
14781
14793
  }
14794
+ case ActionTypes.FOCUS_OFF_ADA_TYPE:
14795
+ {
14796
+ return mutations_objectSpread(mutations_objectSpread({}, state), {}, {
14797
+ focusIsOnAda: false
14798
+ });
14799
+ }
14782
14800
  default:
14783
14801
  return state;
14784
14802
  }
@@ -15016,6 +15034,7 @@ const getInitialState = adaSettings => ({
15016
15034
  parentElement: undefined,
15017
15035
  isDrawerOpen: false,
15018
15036
  drawerHasBeenOpened: false,
15037
+ focusIsOnAda: false,
15019
15038
  enabledLanguages: ["en"],
15020
15039
  client: undefined,
15021
15040
  isIntroShown: false,
@@ -15702,9 +15721,9 @@ async function log(message, extra, options) {
15702
15721
  service: "embed",
15703
15722
  env: "production",
15704
15723
  embedVersion: 2,
15705
- version: "1.8.4",
15724
+ version: "1.8.6",
15706
15725
  isNpm: true,
15707
- commitHash: "20e63ea"
15726
+ commitHash: "e6fb8a1"
15708
15727
  }))
15709
15728
  });
15710
15729
  }
@@ -16276,25 +16295,51 @@ function recordProactiveTrigger(proactiveConversationKey, frequency, handle) {
16276
16295
  function proactiveTriggerImpl(_ref) {
16277
16296
  let {
16278
16297
  proactiveConversation,
16279
- messageKey,
16280
16298
  adaSettings,
16281
16299
  messageService,
16282
- setRecentProactiveConversationKey,
16300
+ setRecentProactiveConversationConfig,
16283
16301
  clearProactiveConversation
16284
16302
  } = _ref;
16285
16303
  const {
16286
16304
  handle
16287
16305
  } = adaSettings;
16306
+ const {
16307
+ key,
16308
+ params = {},
16309
+ is_template: isTemplate
16310
+ } = proactiveConversation;
16311
+ const messageKey = String(key);
16288
16312
  const {
16289
16313
  duration,
16290
16314
  delay,
16291
16315
  frequency,
16292
16316
  active
16293
16317
  } = proactiveConversation.modality_config.chat;
16318
+ const lang = adaSettings.language || get_browser_language();
16319
+ let proactiveMessage = proactiveConversation.messages[lang][0];
16294
16320
  if (!active) {
16295
16321
  warn("Proactive message is not active");
16296
16322
  return;
16297
16323
  }
16324
+ if (isTemplate) {
16325
+ if (Object.keys(params).length === 0) {
16326
+ warn("Proactive message is a template but no parameters were provided");
16327
+ return;
16328
+ }
16329
+
16330
+ // Replace the template variables with the param values
16331
+ const missingParams = [];
16332
+ proactiveMessage = proactiveMessage.replace(/{{(.*?)}}/g, (match, variableKey) => {
16333
+ if (!(variableKey in params)) {
16334
+ missingParams.push(variableKey);
16335
+ }
16336
+ return params[variableKey];
16337
+ });
16338
+ if (missingParams.length > 0) {
16339
+ warn(`Missing parameters for template message: ${missingParams.join(", ")}`);
16340
+ return;
16341
+ }
16342
+ }
16298
16343
 
16299
16344
  // Check if the proactive message has been shown within the specified frequency
16300
16345
  const doesPassFrequencyCheck = !proactiveShownWithinFrequency(messageKey, frequency, handle);
@@ -16304,13 +16349,14 @@ function proactiveTriggerImpl(_ref) {
16304
16349
 
16305
16350
  // Record the proactive message as being shown
16306
16351
  recordProactiveTrigger(messageKey, frequency, handle);
16307
- setRecentProactiveConversationKey(messageKey);
16352
+ setRecentProactiveConversationConfig({
16353
+ key: messageKey,
16354
+ params
16355
+ });
16308
16356
  clearProactiveConversation();
16309
16357
  const localChannel = messageService.getChannel("local");
16310
- const lang = adaSettings.language || get_browser_language();
16311
- const message = proactiveConversation.messages[lang][0];
16312
16358
  localChannel.postMessage(CREATE_PROACTIVE, {
16313
- body: message,
16359
+ body: proactiveMessage,
16314
16360
  duration,
16315
16361
  delay
16316
16362
  });
@@ -16853,7 +16899,7 @@ class ChatFrame extends d {
16853
16899
  const hostPageUrlParams = new URL(window.location.href).searchParams;
16854
16900
  const smsToken = hostPageUrlParams.get("adaSMSToken");
16855
16901
  const queryParams = {
16856
- embedVersion: "20e63ea".slice(0, 7),
16902
+ embedVersion: "e6fb8a1".slice(0, 7),
16857
16903
  greeting,
16858
16904
  language,
16859
16905
  skipGreeting,
@@ -17730,7 +17776,7 @@ class Container extends d {
17730
17776
  chatVersion: undefined,
17731
17777
  readyToRenderChatFrame: false,
17732
17778
  proactiveConversation: null,
17733
- recentProactiveConversationKey: null
17779
+ recentProactiveConversationConfig: null
17734
17780
  });
17735
17781
  _defineProperty(this, "resetChatBound", this.resetChat.bind(this));
17736
17782
  _defineProperty(this, "locationChangeHandlerBound", this.locationChangeHandler.bind(this));
@@ -17847,7 +17893,7 @@ class Container extends d {
17847
17893
  campaignTriggerOptions,
17848
17894
  followUpResponseId,
17849
17895
  proactiveConversation,
17850
- recentProactiveConversationKey
17896
+ recentProactiveConversationConfig
17851
17897
  } = this.state;
17852
17898
 
17853
17899
  /* We wait for all necessary preconditions (e.g. necessary connections established) to be true,
@@ -17876,11 +17922,10 @@ class Container extends d {
17876
17922
  if (proactiveConversation && appConnectionState === ConnectionState.Done) {
17877
17923
  proactiveTriggerImpl({
17878
17924
  proactiveConversation,
17879
- messageKey: proactiveConversation.key,
17880
17925
  adaSettings,
17881
17926
  messageService,
17882
- setRecentProactiveConversationKey: key => this.setState({
17883
- recentProactiveConversationKey: key
17927
+ setRecentProactiveConversationConfig: config => this.setState({
17928
+ recentProactiveConversationConfig: config
17884
17929
  }),
17885
17930
  clearProactiveConversation: () => this.setState({
17886
17931
  proactiveConversation: null
@@ -17906,7 +17951,7 @@ class Container extends d {
17906
17951
  });
17907
17952
  }
17908
17953
  }
17909
- if (isChatWebsocketConnected && isDrawerOpen && recentProactiveConversationKey) {
17954
+ if (isChatWebsocketConnected && isDrawerOpen && recentProactiveConversationConfig) {
17910
17955
  const chatChannel = messageService.getChannel(CHAT_IFRAME);
17911
17956
  if (chatChannel) {
17912
17957
  // Set meta field to indicate that a proactive conversation has been injected
@@ -17917,14 +17962,15 @@ class Container extends d {
17917
17962
  }
17918
17963
  });
17919
17964
  chatChannel.postMessage(INJECT_PROACTIVE_CONVERSATION, {
17920
- key: recentProactiveConversationKey
17965
+ key: recentProactiveConversationConfig.key,
17966
+ messageParams: recentProactiveConversationConfig.params
17921
17967
  });
17922
17968
  log("Proactive message clicked", {
17923
17969
  handle: adaSettings.handle,
17924
17970
  embedSettings: adaSettings
17925
17971
  });
17926
17972
  this.setState({
17927
- recentProactiveConversationKey: null
17973
+ recentProactiveConversationConfig: null
17928
17974
  });
17929
17975
  }
17930
17976
  }
@@ -18147,7 +18193,8 @@ class Container extends d {
18147
18193
  Object.entries(proactiveConversations).forEach(_ref => {
18148
18194
  let [key, conversation] = _ref;
18149
18195
  const chatConfig = conversation.modality_config.chat;
18150
- if (chatConfig.active && evaluateUrlTriggerConditions(chatConfig.url_trigger_conditions, currentUrl)) {
18196
+ const isTemplate = conversation.is_template;
18197
+ if (chatConfig.active && !isTemplate && evaluateUrlTriggerConditions(chatConfig.url_trigger_conditions, currentUrl)) {
18151
18198
  this.handleProactiveTrigger(Container_objectSpread({
18152
18199
  key
18153
18200
  }, conversation));
@@ -18435,12 +18482,14 @@ class Container extends d {
18435
18482
  throw new AdaEmbedError("`client` is not defined");
18436
18483
  }
18437
18484
  const {
18438
- messageKey
18485
+ messageKey,
18486
+ params
18439
18487
  } = payload;
18440
18488
  if ((_client$proactive_con = client.proactive_conversations) !== null && _client$proactive_con !== void 0 && _client$proactive_con[messageKey]) {
18441
18489
  const proactiveConversation = client.proactive_conversations[messageKey];
18442
18490
  this.handleProactiveTrigger(Container_objectSpread(Container_objectSpread({}, proactiveConversation), {}, {
18443
- key: messageKey
18491
+ key: messageKey,
18492
+ params
18444
18493
  }));
18445
18494
  } else {
18446
18495
  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, messageKey, adaSettings, messageService, setRecentProactiveConversationKey, clearProactiveConversation, }: {
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
- setRecentProactiveConversationKey: (key: string) => void;
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.4",
3
+ "version": "1.8.6",
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.0",
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",