@microsoft/omnichannel-chat-widget 1.2.3-main.000f886 → 1.2.3-main.d27a359

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.
Files changed (33) hide show
  1. package/lib/cjs/common/Constants.js +5 -1
  2. package/lib/cjs/common/telemetry/TelemetryConstants.js +1 -0
  3. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +4 -1
  4. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +2 -1
  5. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +12 -7
  6. package/lib/cjs/components/livechatwidget/common/startChat.js +6 -5
  7. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +16 -15
  8. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +6 -3
  9. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +190 -0
  10. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +5 -0
  11. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.js +65 -0
  12. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +342 -0
  13. package/lib/cjs/plugins/createChatTranscript.js +28 -4
  14. package/lib/esm/common/Constants.js +5 -1
  15. package/lib/esm/common/telemetry/TelemetryConstants.js +1 -0
  16. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/BotAuthActivitySubscriber.js +4 -1
  17. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +2 -1
  18. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +12 -7
  19. package/lib/esm/components/livechatwidget/common/startChat.js +6 -5
  20. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +16 -15
  21. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +6 -3
  22. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.js +188 -0
  23. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +5 -0
  24. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.js +58 -0
  25. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +338 -0
  26. package/lib/esm/plugins/createChatTranscript.js +28 -4
  27. package/lib/types/common/Constants.d.ts +4 -0
  28. package/lib/types/common/telemetry/TelemetryConstants.d.ts +1 -0
  29. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +1 -1
  30. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.spec.d.ts +1 -0
  31. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.d.ts +5 -0
  32. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.d.ts +1 -0
  33. package/package.json +2 -2
@@ -0,0 +1,342 @@
1
+ "use strict";
2
+
3
+ var _Constants = require("../../../../../common/Constants");
4
+ var _WebChatActionType = require("../../enums/WebChatActionType");
5
+ var _messageSequenceIdOverrideMiddleware = _interopRequireDefault(require("./messageSequenceIdOverrideMiddleware"));
6
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
+ /* eslint-disable @typescript-eslint/no-explicit-any */
8
+
9
+ describe("messageSequenceIdOverrideMiddleware", () => {
10
+ it("sequenceId is overrided", () => {
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ const next = args => args;
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ const dispatch = () => {
15
+ return 1;
16
+ };
17
+ const action = {
18
+ type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
19
+ payload: {
20
+ text: "test-text",
21
+ activity: {
22
+ channelId: "ACS_CHANNEL",
23
+ from: {
24
+ role: "user"
25
+ },
26
+ channelData: {
27
+ metadata: {
28
+ "OriginalMessageId": "1683742135918"
29
+ },
30
+ "webchat:sequence-id": 12345
31
+ }
32
+ }
33
+ }
34
+ };
35
+ const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
36
+ let resultValue;
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
38
+ const channelData = middleware.payload.activity.channelData;
39
+ Object.keys(channelData).forEach(function (key) {
40
+ if (key === _Constants.Constants.WebchatSequenceIdAttribute) {
41
+ resultValue = channelData[key];
42
+ }
43
+ });
44
+ expect(resultValue).toEqual(1683742135918);
45
+ });
46
+ it("sequenceId is not overrided due to empty string for originalID", () => {
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ const next = args => args;
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ const dispatch = () => {
51
+ return 1;
52
+ };
53
+ const action = {
54
+ type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
55
+ payload: {
56
+ text: "test-text",
57
+ activity: {
58
+ channelId: "ACS_CHANNEL",
59
+ from: {
60
+ role: "user"
61
+ },
62
+ channelData: {
63
+ metadata: {
64
+ "OriginalMessageId": ""
65
+ },
66
+ "webchat:sequence-id": 12345
67
+ }
68
+ }
69
+ }
70
+ };
71
+ const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
72
+ let resultValue;
73
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
74
+ const channelData = middleware.payload.activity.channelData;
75
+ Object.keys(channelData).forEach(function (key) {
76
+ if (key === _Constants.Constants.WebchatSequenceIdAttribute) {
77
+ resultValue = channelData[key];
78
+ }
79
+ });
80
+ expect(resultValue).toEqual(12345);
81
+ });
82
+ it("sequenceId is not overrided, due to OriginalMessageId being not a string of numbers ", () => {
83
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
+ const next = args => args;
85
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
86
+ const dispatch = () => {
87
+ return 1;
88
+ };
89
+ const action = {
90
+ type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
91
+ payload: {
92
+ text: "test-text",
93
+ activity: {
94
+ channelId: "ACS_CHANNEL",
95
+ from: {
96
+ role: "user"
97
+ },
98
+ channelData: {
99
+ metadata: {
100
+ "OriginalMessageId": "abcdf"
101
+ },
102
+ "webchat:sequence-id": 12345
103
+ }
104
+ }
105
+ }
106
+ };
107
+ const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
108
+ let resultValue;
109
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
110
+ const channelData = middleware.payload.activity.channelData;
111
+ Object.keys(channelData).forEach(function (key) {
112
+ if (key === _Constants.Constants.WebchatSequenceIdAttribute) {
113
+ resultValue = channelData[key];
114
+ }
115
+ });
116
+ expect(resultValue).toEqual(12345);
117
+ });
118
+ it("no changes since webchat id is not present", () => {
119
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
+ const next = args => args;
121
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
122
+ const dispatch = () => {
123
+ return 1;
124
+ };
125
+ const payloadExpected = {
126
+ payload: {
127
+ text: "test-text",
128
+ activity: {
129
+ channelId: "ACS_CHANNEL",
130
+ from: {
131
+ role: "user"
132
+ },
133
+ channelData: {
134
+ metadata: {
135
+ "OriginalMessageId": "123456789"
136
+ }
137
+ }
138
+ }
139
+ }
140
+ };
141
+ const action = {
142
+ type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
143
+ payload: {
144
+ text: "test-text",
145
+ activity: {
146
+ channelId: "ACS_CHANNEL",
147
+ from: {
148
+ role: "user"
149
+ },
150
+ channelData: {
151
+ metadata: {
152
+ "OriginalMessageId": "123456789"
153
+ }
154
+ }
155
+ }
156
+ }
157
+ };
158
+ const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
159
+ expect(middleware.payload).toEqual(payloadExpected.payload);
160
+ });
161
+ it("no changes since OriginalMessageId is not present", () => {
162
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
163
+ const next = args => args;
164
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
165
+ const dispatch = () => {
166
+ return 1;
167
+ };
168
+ const payloadExpected = {
169
+ payload: {
170
+ text: "test-text",
171
+ activity: {
172
+ channelId: "ACS_CHANNEL",
173
+ from: {
174
+ role: "user"
175
+ },
176
+ channelData: {
177
+ metadata: {},
178
+ "webchat:sequence-id": 12345
179
+ }
180
+ }
181
+ }
182
+ };
183
+ const action = {
184
+ type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
185
+ payload: {
186
+ text: "test-text",
187
+ activity: {
188
+ channelId: "ACS_CHANNEL",
189
+ from: {
190
+ role: "user"
191
+ },
192
+ channelData: {
193
+ metadata: {},
194
+ "webchat:sequence-id": 12345
195
+ }
196
+ }
197
+ }
198
+ };
199
+ const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
200
+ expect(middleware.payload).toEqual(payloadExpected.payload);
201
+ });
202
+ it("no override, since the type of message is not incoming activity", () => {
203
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
204
+ const next = args => args;
205
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
206
+ const dispatch = () => {
207
+ return 1;
208
+ };
209
+ const action = {
210
+ type: "something else",
211
+ payload: {
212
+ text: "test-text",
213
+ activity: {
214
+ channelId: "ACS_CHANNEL",
215
+ from: {
216
+ role: "user"
217
+ },
218
+ channelData: {
219
+ metadata: {
220
+ "OriginalMessageId": "1683742135918"
221
+ },
222
+ "webchat:sequence-id": 12345
223
+ }
224
+ }
225
+ }
226
+ };
227
+ const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
228
+ let resultValue;
229
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
230
+ const channelData = middleware.payload.activity.channelData;
231
+ Object.keys(channelData).forEach(function (key) {
232
+ if (key === _Constants.Constants.WebchatSequenceIdAttribute) {
233
+ resultValue = channelData[key];
234
+ }
235
+ });
236
+ expect(resultValue).toEqual(12345);
237
+ });
238
+ it("no override, since the channel is not ACS", () => {
239
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
240
+ const next = args => args;
241
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
242
+ const dispatch = () => {
243
+ return 1;
244
+ };
245
+ const action = {
246
+ type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
247
+ payload: {
248
+ text: "test-text",
249
+ activity: {
250
+ channelId: "something_else",
251
+ from: {
252
+ role: "user"
253
+ },
254
+ channelData: {
255
+ metadata: {
256
+ "OriginalMessageId": "1683742135918"
257
+ },
258
+ "webchat:sequence-id": 12345
259
+ }
260
+ }
261
+ }
262
+ };
263
+ const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
264
+ let resultValue;
265
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
266
+ const channelData = middleware.payload.activity.channelData;
267
+ Object.keys(channelData).forEach(function (key) {
268
+ if (key === _Constants.Constants.WebchatSequenceIdAttribute) {
269
+ resultValue = channelData[key];
270
+ }
271
+ });
272
+ expect(resultValue).toEqual(12345);
273
+ });
274
+ it("no override, since the channel channelData is not present", () => {
275
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
276
+ const next = args => args;
277
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
278
+ const dispatch = () => {
279
+ return 1;
280
+ };
281
+ const action = {
282
+ type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
283
+ payload: {
284
+ text: "test-text channel data is not present",
285
+ activity: {
286
+ channelId: "ACS_CHANNEL",
287
+ from: {
288
+ role: "user"
289
+ }
290
+ }
291
+ }
292
+ };
293
+ const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
294
+ expect(middleware.payload).toEqual(action.payload);
295
+ });
296
+ it("no override, since channelData is empty object", () => {
297
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
298
+ const next = args => args;
299
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
300
+ const dispatch = () => {
301
+ return 1;
302
+ };
303
+ const action = {
304
+ type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
305
+ payload: {
306
+ text: "test-text channel data empty",
307
+ activity: {
308
+ channelId: "ACS_CHANNEL",
309
+ from: {
310
+ role: "user"
311
+ },
312
+ channelData: {}
313
+ }
314
+ }
315
+ };
316
+ const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
317
+ expect(middleware.payload).toEqual(action.payload);
318
+ });
319
+ it("no override, since channelData null", () => {
320
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
321
+ const next = args => args;
322
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
323
+ const dispatch = () => {
324
+ return 1;
325
+ };
326
+ const action = {
327
+ type: _WebChatActionType.WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
328
+ payload: {
329
+ text: "test-channel Data null",
330
+ activity: {
331
+ channelId: "ACS_CHANNEL",
332
+ from: {
333
+ role: "user"
334
+ },
335
+ channelData: null
336
+ }
337
+ }
338
+ };
339
+ const middleware = (0, _messageSequenceIdOverrideMiddleware.default)(dispatch)(next)(action);
340
+ expect(middleware.payload).toEqual(action.payload);
341
+ });
342
+ });
@@ -124,7 +124,13 @@ class TranscriptHTMLBuilder {
124
124
  <script>
125
125
  class Translator {
126
126
  static convertTranscriptMessageToActivity(message) {
127
- const {created, isControlMessage, content, tags, from, attachments, amsMetadata, amsReferences} = message;
127
+ const {created, OriginalMessageId, id, isControlMessage, content, tags, from, attachments, amsMetadata, amsReferences} = message;
128
+
129
+ //it's required to convert the id to a number, otherwise the webchat will not render the messages in the correct order
130
+ // if the OrginalMessageId is not present, we can use the id as the sequence id, which is always present.
131
+
132
+ const webchatSequenceId = Translator.convertStringValueToInt(OriginalMessageId) || Translator.convertStringValueToInt(id);
133
+
128
134
  const activity = {
129
135
  from: {
130
136
  role: 'bot'
@@ -179,7 +185,10 @@ class TranscriptHTMLBuilder {
179
185
  return {
180
186
  ...activity,
181
187
  text,
182
- timestamp: created
188
+ timestamp: created,
189
+ channelData: {
190
+ "webchat:sequence-id": webchatSequenceId
191
+ }
183
192
  }
184
193
  }
185
194
 
@@ -192,7 +201,10 @@ class TranscriptHTMLBuilder {
192
201
  return {
193
202
  ...activity,
194
203
  ...partialActivity,
195
- timestamp: created
204
+ timestamp: created,
205
+ channelData: {
206
+ "webchat:sequence-id": webchatSequenceId
207
+ }
196
208
  };
197
209
  } catch {
198
210
 
@@ -203,9 +215,21 @@ class TranscriptHTMLBuilder {
203
215
  return {
204
216
  ...activity,
205
217
  text: content,
206
- timestamp: created
218
+ timestamp: created,
219
+ channelData: {
220
+ "webchat:sequence-id": webchatSequenceId
221
+ }
207
222
  };
208
223
  }
224
+
225
+ static convertStringValueToInt(value) {
226
+ if (typeof value !== "string" || value === "") {
227
+ return undefined;
228
+ }
229
+
230
+ const result = parseInt(value);
231
+ return isNaN(result) ? undefined : result;
232
+ }
209
233
  }
210
234
  <\/script>
211
235
  <script>
@@ -51,7 +51,8 @@ _defineProperty(Constants, "prefixTimestampTag", "ServerMessageTimestamp_");
51
51
  _defineProperty(Constants, "acsChannel", "ACS_CHANNEL");
52
52
  _defineProperty(Constants, "publicMessageTag", "public");
53
53
  //attachmentMiddleware
54
- _defineProperty(Constants, "supportedAdaptiveCardContentTypes", ["application/vnd.microsoft.card.adaptive", "application/vnd.microsoft.card.audio", "application/vnd.microsoft.card.hero", "application/vnd.microsoft.card.receipt", "application/vnd.microsoft.card.thumbnail", "application/vnd.microsoft.card.signin", "application/vnd.microsoft.card.oauth"]);
54
+ _defineProperty(Constants, "supportedAdaptiveCardContentTypes", ["application/vnd.microsoft.card.adaptive", "application/vnd.microsoft.card.audio", "application/vnd.microsoft.card.hero", "application/vnd.microsoft.card.receipt", "application/vnd.microsoft.card.thumbnail", "application/vnd.microsoft.card.signin", "application/vnd.microsoft.card.oauth", "application/vnd.microsoft.card.video"]);
55
+ _defineProperty(Constants, "adaptiveCardContentTypePrefix", "application/vnd.microsoft.card");
55
56
  _defineProperty(Constants, "maxUploadFileSize", "500000");
56
57
  _defineProperty(Constants, "imageRegex", /(\.)(jpeg|jpg|jiff|png|gif|bmp|webp)$/i);
57
58
  _defineProperty(Constants, "audioMediaRegex", /(\.)(aac|aiff|alac|amr|flac|mp2|mp3|pcm|wav|wma)$/i);
@@ -109,6 +110,9 @@ _defineProperty(Constants, "LWICheckOnVisibilityTimeout", 3 * 60 * 1000);
109
110
  // Popup mode custom context response event message name
110
111
  _defineProperty(Constants, "InitContextParamsRequest", "initContextParamsRequest");
111
112
  _defineProperty(Constants, "InitContextParamsResponse", "initContextParamsResponse");
113
+ _defineProperty(Constants, "OCOriginalMessageId", "OriginalMessageId");
114
+ _defineProperty(Constants, "WebchatSequenceIdAttribute", "webchat:sequence-id");
115
+ _defineProperty(Constants, "MessageSequenceIdOverride", "MessageSequenceIdOverride");
112
116
  export const Regex = (_class = class Regex {}, _defineProperty(_class, "EmailRegex", "(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"), _class);
113
117
  export class HtmlIdNames {}
114
118
  _defineProperty(HtmlIdNames, "MSLiveChatWidget", "MSLiveChatWidget");
@@ -158,6 +158,7 @@ export let TelemetryEvent;
158
158
  TelemetryEvent["SetBotAuthProviderHideCard"] = "SetBotAuthProviderHideCard";
159
159
  TelemetryEvent["SetBotAuthProviderDisplayCard"] = "SetBotAuthProviderDisplayCard";
160
160
  TelemetryEvent["SetBotAuthProviderNotFound"] = "SetBotAuthProviderNotFound";
161
+ TelemetryEvent["BotAuthActivityUndefinedSignInId"] = "BotAuthActivityUndefinedSignInId";
161
162
  TelemetryEvent["ThirdPartyCookiesBlocked"] = "ThirdPartyCookiesBlocked";
162
163
  TelemetryEvent["ProcessingHTMLTextMiddlewareFailed"] = "ProcessingHTMLTextMiddlewareFailed";
163
164
  TelemetryEvent["ProcessingSanitizationMiddlewareFailed"] = "ProcessingSanitizationMiddlewareFailed";
@@ -79,7 +79,10 @@ export class BotAuthActivitySubscriber {
79
79
  const signInUrl = attachment.content.buttons[0].value;
80
80
  const signInId = extractSignInId(signInUrl);
81
81
  if (!signInId) {
82
- return;
82
+ TelemetryHelper.logLoadingEvent(LogLevel.INFO, {
83
+ Event: TelemetryEvent.BotAuthActivityUndefinedSignInId
84
+ });
85
+ return activity;
83
86
  }
84
87
  if (this.signInCardSeen.has(signInId)) {
85
88
  // Prevents duplicate auth
@@ -29,6 +29,7 @@ import htmlTextMiddleware from "../../webchatcontainerstateful/webchatcontroller
29
29
  import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware";
30
30
  import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
31
31
  import DOMPurify from "dompurify";
32
+ import createMessageSequenceIdOverrideMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware";
32
33
 
33
34
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
35
  export const initWebChatComposer = (props, state, dispatch, chatSDK) => {
@@ -68,7 +69,7 @@ export const initWebChatComposer = (props, state, dispatch, chatSDK) => {
68
69
  };
69
70
  webChatStore = createStore({},
70
71
  //initial state
71
- preProcessingMiddleware, attachmentProcessingMiddleware, createAttachmentUploadValidatorMiddleware((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.allowedFileExtensions, (_state$domainStates$l2 = state.domainStates.liveChatConfig) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.maxUploadFileSize, localizedTexts), channelDataMiddleware, createConversationEndMiddleware(conversationEndCallback), createDataMaskingMiddleware((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : _state$domainStates$l3.DataMaskingInfo), createMessageTimeStampMiddleware, gifUploadMiddleware, htmlPlayerMiddleware, htmlTextMiddleware, createMaxMessageSizeValidator(localizedTexts), sanitizationMiddleware,
72
+ preProcessingMiddleware, attachmentProcessingMiddleware, createAttachmentUploadValidatorMiddleware((_state$domainStates$l = state.domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.allowedFileExtensions, (_state$domainStates$l2 = state.domainStates.liveChatConfig) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.maxUploadFileSize, localizedTexts), channelDataMiddleware, createConversationEndMiddleware(conversationEndCallback), createDataMaskingMiddleware((_state$domainStates$l3 = state.domainStates.liveChatConfig) === null || _state$domainStates$l3 === void 0 ? void 0 : _state$domainStates$l3.DataMaskingInfo), createMessageTimeStampMiddleware, createMessageSequenceIdOverrideMiddleware, gifUploadMiddleware, htmlPlayerMiddleware, htmlTextMiddleware, createMaxMessageSizeValidator(localizedTexts), sanitizationMiddleware,
72
73
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
74
  ...(((_props$webChatContain5 = props.webChatContainerProps) === null || _props$webChatContain5 === void 0 ? void 0 : _props$webChatContain5.storeMiddlewares) ?? []));
74
75
  WebChatStoreLoader.store = webChatStore;
@@ -8,10 +8,11 @@ import { ConversationState } from "../../../contexts/common/ConversationState";
8
8
  import { LiveChatWidgetActionType } from "../../../contexts/common/LiveChatWidgetActionType";
9
9
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
10
10
 
11
+ // Return value: should start normal chat flow when reconnect is enabled
11
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
13
  const handleChatReconnect = async (chatSDK, props, dispatch, setAdapter, initStartChat, state) => {
13
14
  var _props$chatConfig, _props$chatConfig$Liv;
14
- if (!isReconnectEnabled(props.chatConfig) || isPersistentEnabled(props.chatConfig)) return;
15
+ if (!isReconnectEnabled(props.chatConfig) || isPersistentEnabled(props.chatConfig)) return false;
15
16
 
16
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
18
  const isAuthenticatedChat = (_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction ? true : false;
@@ -23,14 +24,14 @@ const handleChatReconnect = async (chatSDK, props, dispatch, setAdapter, initSta
23
24
  if (reconnectChatContext !== null && reconnectChatContext !== void 0 && reconnectChatContext.redirectURL) {
24
25
  var _props$reconnectChatP;
25
26
  redirectPage(reconnectChatContext.redirectURL, (_props$reconnectChatP = props.reconnectChatPaneProps) === null || _props$reconnectChatP === void 0 ? void 0 : _props$reconnectChatP.redirectInSameWindow);
26
- return;
27
+ return false;
27
28
  }
28
29
  if (hasReconnectId(reconnectChatContext)) {
29
30
  var _props$reconnectChatP2, _props$reconnectChatP3;
30
31
  //if reconnect id is provided in props, don't show reconnect pane
31
32
  if ((_props$reconnectChatP2 = props.reconnectChatPaneProps) !== null && _props$reconnectChatP2 !== void 0 && _props$reconnectChatP2.reconnectId && !isNullOrEmptyString((_props$reconnectChatP3 = props.reconnectChatPaneProps) === null || _props$reconnectChatP3 === void 0 ? void 0 : _props$reconnectChatP3.reconnectId)) {
32
- await setReconnectIdAndStartChat(isAuthenticatedChat, chatSDK, props, dispatch, setAdapter, reconnectChatContext.reconnectId ?? "", initStartChat);
33
- return;
33
+ await setReconnectIdAndStartChat(isAuthenticatedChat, chatSDK, state, props, dispatch, setAdapter, reconnectChatContext.reconnectId ?? "", initStartChat);
34
+ return false;
34
35
  }
35
36
 
36
37
  //show reconnect pane
@@ -43,8 +44,12 @@ const handleChatReconnect = async (chatSDK, props, dispatch, setAdapter, initSta
43
44
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
44
45
  payload: ConversationState.ReconnectChat
45
46
  });
46
- return;
47
+ return false;
47
48
  }
49
+
50
+ // If we have reached this point, it means there is no valid reconnect id or redirectUrl
51
+ // This is a unauth reconnect refresh scenario - returns true so that we can start normal hydration process
52
+ return true;
48
53
  };
49
54
 
50
55
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -81,7 +86,7 @@ const getChatReconnectContext = async (chatSDK, chatConfig, props, isAuthenticat
81
86
  };
82
87
 
83
88
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
- const setReconnectIdAndStartChat = async (isAuthenticatedChat, chatSDK, props, dispatch, setAdapter, reconnectId, initStartChat) => {
89
+ const setReconnectIdAndStartChat = async (isAuthenticatedChat, chatSDK, state, props, dispatch, setAdapter, reconnectId, initStartChat) => {
85
90
  if (!isAuthenticatedChat) {
86
91
  const startUnauthenticatedReconnectChat = {
87
92
  eventName: BroadcastEvent.StartUnauthenticatedReconnectChat
@@ -99,7 +104,7 @@ const setReconnectIdAndStartChat = async (isAuthenticatedChat, chatSDK, props, d
99
104
  type: LiveChatWidgetActionType.SET_CONVERSATION_STATE,
100
105
  payload: ConversationState.Loading
101
106
  });
102
- await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams);
107
+ await initStartChat(chatSDK, dispatch, setAdapter, state, props, optionalParams);
103
108
  };
104
109
  const redirectPage = (redirectURL, redirectInSameWindow) => {
105
110
  const redirectPageRequest = {
@@ -295,16 +295,17 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
295
295
 
296
296
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
297
297
  const setCustomContextParams = async (state, props) => {
298
- var _props$chatConfig, _props$chatConfig$Liv, _persistedState$domai8;
298
+ var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates, _persistedState$domai8;
299
299
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
300
300
  const isAuthenticatedChat = props !== null && props !== void 0 && (_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction ? true : false;
301
301
  //Should not set custom context for auth chat
302
302
  if (isAuthenticatedChat) {
303
303
  return;
304
304
  }
305
- if (state !== null && state !== void 0 && state.domainStates.customContext) {
305
+ if (state !== null && state !== void 0 && (_state$domainStates = state.domainStates) !== null && _state$domainStates !== void 0 && _state$domainStates.customContext) {
306
+ var _state$domainStates2;
306
307
  optionalParams = Object.assign({}, optionalParams, {
307
- customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : state.domainStates.customContext))
308
+ customContext: JSON.parse(JSON.stringify(state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : _state$domainStates2.customContext))
308
309
  });
309
310
  return;
310
311
  }
@@ -352,8 +353,8 @@ const canStartPopoutChat = async props => {
352
353
 
353
354
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
354
355
  const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
355
- var _state$domainStates, _state$domainStates$l;
356
- const requestIdFromCache = (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$l = _state$domainStates.liveChatContext) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.requestId;
356
+ var _state$domainStates3, _state$domainStates3$;
357
+ const requestIdFromCache = (_state$domainStates3 = state.domainStates) === null || _state$domainStates3 === void 0 ? void 0 : (_state$domainStates3$ = _state$domainStates3.liveChatContext) === null || _state$domainStates3$ === void 0 ? void 0 : _state$domainStates3$.requestId;
357
358
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
358
359
  let conversationDetails = undefined;
359
360
 
@@ -108,6 +108,16 @@ export const LiveChatWidgetStateful = props => {
108
108
 
109
109
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
110
110
  const startChat = async (props, localState) => {
111
+ const isReconnectTriggered = async () => {
112
+ if (isReconnectEnabled(props.chatConfig) === true && !isPersistentEnabled(props.chatConfig)) {
113
+ const noValidReconnectId = await handleChatReconnect(chatSDK, props, dispatch, setAdapter, initStartChat, state);
114
+ // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
115
+ if (!noValidReconnectId && (state.appStates.conversationState === ConversationState.Active || state.appStates.conversationState === ConversationState.ReconnectChat)) {
116
+ return true;
117
+ }
118
+ }
119
+ return false;
120
+ };
111
121
  let isChatValid = false;
112
122
  //Start a chat from cache/reconnectid
113
123
  if (activeCachedChatExist === true) {
@@ -122,29 +132,20 @@ export const LiveChatWidgetStateful = props => {
122
132
  //Check if conversation state is not in wrapup or closed state
123
133
  isChatValid = await checkIfConversationStillValid(chatSDK, dispatch, state);
124
134
  if (isChatValid === true) {
125
- //Check if reconnect enabled
126
- if (isReconnectEnabled(props.chatConfig) === true && !isPersistentEnabled(props.chatConfig)) {
127
- await handleChatReconnect(chatSDK, props, dispatch, setAdapter, initStartChat, state);
128
- // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
129
- if (state.appStates.conversationState === ConversationState.Active || state.appStates.conversationState === ConversationState.ReconnectChat) {
130
- return;
131
- }
135
+ const reconnectTriggered = await isReconnectTriggered();
136
+ if (!reconnectTriggered) {
137
+ await initStartChat(chatSDK, dispatch, setAdapter, state, props, optionalParams);
132
138
  }
133
- await initStartChat(chatSDK, dispatch, setAdapter, state, props, optionalParams);
134
139
  return;
135
140
  }
136
141
  }
137
142
  if (isChatValid === false) {
138
143
  if (localState) {
139
144
  // adding the reconnect logic for the case when customer tries to reconnect from a new browser or InPrivate browser
140
- if (isReconnectEnabled(props.chatConfig) === true && !isPersistentEnabled(props.chatConfig)) {
141
- await handleChatReconnect(chatSDK, props, dispatch, setAdapter, initStartChat, state);
142
- // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
143
- if (state.appStates.conversationState === ConversationState.Active || state.appStates.conversationState === ConversationState.ReconnectChat) {
144
- return;
145
- }
145
+ const reconnectTriggered = await isReconnectTriggered();
146
+ if (!reconnectTriggered) {
147
+ await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, undefined, undefined, localState, props);
146
148
  }
147
- await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, undefined, undefined, localState, props);
148
149
  return;
149
150
  } else {
150
151
  var _state$appStates4;
@@ -44,12 +44,15 @@ const handleSystemMessage = (next, args, card, systemMessageStyleProps) => {
44
44
  return () => false;
45
45
  }
46
46
 
47
- // eslint-disable-next-line react/display-name, @typescript-eslint/no-explicit-any
47
+ // eslint-disable-next-line react/display-name
48
48
  return () => /*#__PURE__*/React.createElement("div", {
49
49
  key: card.activity.id,
50
50
  style: systemMessageStyles,
51
- "aria-hidden": "true"
52
- }, card.activity.text);
51
+ "aria-hidden": "true",
52
+ dangerouslySetInnerHTML: {
53
+ __html: escapeHtml(card.activity.text)
54
+ }
55
+ });
53
56
  };
54
57
 
55
58
  // eslint-disable-next-line @typescript-eslint/no-explicit-any