@microsoft/omnichannel-chat-widget 1.2.2 → 1.2.3-main.2ce131d

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 (23) hide show
  1. package/lib/cjs/common/Constants.js +5 -1
  2. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +2 -1
  3. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +12 -7
  4. package/lib/cjs/components/livechatwidget/common/startChat.js +6 -5
  5. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +16 -15
  6. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +5 -0
  7. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.js +65 -0
  8. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +342 -0
  9. package/lib/cjs/plugins/createChatTranscript.js +28 -4
  10. package/lib/esm/common/Constants.js +5 -1
  11. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +2 -1
  12. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +12 -7
  13. package/lib/esm/components/livechatwidget/common/startChat.js +6 -5
  14. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +16 -15
  15. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/attachmentMiddleware.js +5 -0
  16. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.js +58 -0
  17. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.js +338 -0
  18. package/lib/esm/plugins/createChatTranscript.js +28 -4
  19. package/lib/types/common/Constants.d.ts +4 -0
  20. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +1 -1
  21. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.d.ts +5 -0
  22. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageSequenceIdOverrideMiddleware.spec.d.ts +1 -0
  23. package/package.json +2 -2
@@ -0,0 +1,338 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { Constants } from "../../../../../common/Constants";
3
+ import { WebChatActionType } from "../../enums/WebChatActionType";
4
+ import createMessageSequenceIdOverrideMiddleware from "./messageSequenceIdOverrideMiddleware";
5
+ describe("messageSequenceIdOverrideMiddleware", () => {
6
+ it("sequenceId is overrided", () => {
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ const next = args => args;
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ const dispatch = () => {
11
+ return 1;
12
+ };
13
+ const action = {
14
+ type: WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
15
+ payload: {
16
+ text: "test-text",
17
+ activity: {
18
+ channelId: "ACS_CHANNEL",
19
+ from: {
20
+ role: "user"
21
+ },
22
+ channelData: {
23
+ metadata: {
24
+ "OriginalMessageId": "1683742135918"
25
+ },
26
+ "webchat:sequence-id": 12345
27
+ }
28
+ }
29
+ }
30
+ };
31
+ const middleware = createMessageSequenceIdOverrideMiddleware(dispatch)(next)(action);
32
+ let resultValue;
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
34
+ const channelData = middleware.payload.activity.channelData;
35
+ Object.keys(channelData).forEach(function (key) {
36
+ if (key === Constants.WebchatSequenceIdAttribute) {
37
+ resultValue = channelData[key];
38
+ }
39
+ });
40
+ expect(resultValue).toEqual(1683742135918);
41
+ });
42
+ it("sequenceId is not overrided due to empty string for originalID", () => {
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+ const next = args => args;
45
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
+ const dispatch = () => {
47
+ return 1;
48
+ };
49
+ const action = {
50
+ type: WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
51
+ payload: {
52
+ text: "test-text",
53
+ activity: {
54
+ channelId: "ACS_CHANNEL",
55
+ from: {
56
+ role: "user"
57
+ },
58
+ channelData: {
59
+ metadata: {
60
+ "OriginalMessageId": ""
61
+ },
62
+ "webchat:sequence-id": 12345
63
+ }
64
+ }
65
+ }
66
+ };
67
+ const middleware = createMessageSequenceIdOverrideMiddleware(dispatch)(next)(action);
68
+ let resultValue;
69
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
70
+ const channelData = middleware.payload.activity.channelData;
71
+ Object.keys(channelData).forEach(function (key) {
72
+ if (key === Constants.WebchatSequenceIdAttribute) {
73
+ resultValue = channelData[key];
74
+ }
75
+ });
76
+ expect(resultValue).toEqual(12345);
77
+ });
78
+ it("sequenceId is not overrided, due to OriginalMessageId being not a string of numbers ", () => {
79
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
+ const next = args => args;
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+ const dispatch = () => {
83
+ return 1;
84
+ };
85
+ const action = {
86
+ type: WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
87
+ payload: {
88
+ text: "test-text",
89
+ activity: {
90
+ channelId: "ACS_CHANNEL",
91
+ from: {
92
+ role: "user"
93
+ },
94
+ channelData: {
95
+ metadata: {
96
+ "OriginalMessageId": "abcdf"
97
+ },
98
+ "webchat:sequence-id": 12345
99
+ }
100
+ }
101
+ }
102
+ };
103
+ const middleware = createMessageSequenceIdOverrideMiddleware(dispatch)(next)(action);
104
+ let resultValue;
105
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
106
+ const channelData = middleware.payload.activity.channelData;
107
+ Object.keys(channelData).forEach(function (key) {
108
+ if (key === Constants.WebchatSequenceIdAttribute) {
109
+ resultValue = channelData[key];
110
+ }
111
+ });
112
+ expect(resultValue).toEqual(12345);
113
+ });
114
+ it("no changes since webchat id is not present", () => {
115
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
116
+ const next = args => args;
117
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
+ const dispatch = () => {
119
+ return 1;
120
+ };
121
+ const payloadExpected = {
122
+ payload: {
123
+ text: "test-text",
124
+ activity: {
125
+ channelId: "ACS_CHANNEL",
126
+ from: {
127
+ role: "user"
128
+ },
129
+ channelData: {
130
+ metadata: {
131
+ "OriginalMessageId": "123456789"
132
+ }
133
+ }
134
+ }
135
+ }
136
+ };
137
+ const action = {
138
+ type: WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
139
+ payload: {
140
+ text: "test-text",
141
+ activity: {
142
+ channelId: "ACS_CHANNEL",
143
+ from: {
144
+ role: "user"
145
+ },
146
+ channelData: {
147
+ metadata: {
148
+ "OriginalMessageId": "123456789"
149
+ }
150
+ }
151
+ }
152
+ }
153
+ };
154
+ const middleware = createMessageSequenceIdOverrideMiddleware(dispatch)(next)(action);
155
+ expect(middleware.payload).toEqual(payloadExpected.payload);
156
+ });
157
+ it("no changes since OriginalMessageId is not present", () => {
158
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
159
+ const next = args => args;
160
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
161
+ const dispatch = () => {
162
+ return 1;
163
+ };
164
+ const payloadExpected = {
165
+ payload: {
166
+ text: "test-text",
167
+ activity: {
168
+ channelId: "ACS_CHANNEL",
169
+ from: {
170
+ role: "user"
171
+ },
172
+ channelData: {
173
+ metadata: {},
174
+ "webchat:sequence-id": 12345
175
+ }
176
+ }
177
+ }
178
+ };
179
+ const action = {
180
+ type: WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
181
+ payload: {
182
+ text: "test-text",
183
+ activity: {
184
+ channelId: "ACS_CHANNEL",
185
+ from: {
186
+ role: "user"
187
+ },
188
+ channelData: {
189
+ metadata: {},
190
+ "webchat:sequence-id": 12345
191
+ }
192
+ }
193
+ }
194
+ };
195
+ const middleware = createMessageSequenceIdOverrideMiddleware(dispatch)(next)(action);
196
+ expect(middleware.payload).toEqual(payloadExpected.payload);
197
+ });
198
+ it("no override, since the type of message is not incoming activity", () => {
199
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
200
+ const next = args => args;
201
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
202
+ const dispatch = () => {
203
+ return 1;
204
+ };
205
+ const action = {
206
+ type: "something else",
207
+ payload: {
208
+ text: "test-text",
209
+ activity: {
210
+ channelId: "ACS_CHANNEL",
211
+ from: {
212
+ role: "user"
213
+ },
214
+ channelData: {
215
+ metadata: {
216
+ "OriginalMessageId": "1683742135918"
217
+ },
218
+ "webchat:sequence-id": 12345
219
+ }
220
+ }
221
+ }
222
+ };
223
+ const middleware = createMessageSequenceIdOverrideMiddleware(dispatch)(next)(action);
224
+ let resultValue;
225
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
226
+ const channelData = middleware.payload.activity.channelData;
227
+ Object.keys(channelData).forEach(function (key) {
228
+ if (key === Constants.WebchatSequenceIdAttribute) {
229
+ resultValue = channelData[key];
230
+ }
231
+ });
232
+ expect(resultValue).toEqual(12345);
233
+ });
234
+ it("no override, since the channel is not ACS", () => {
235
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
236
+ const next = args => args;
237
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
238
+ const dispatch = () => {
239
+ return 1;
240
+ };
241
+ const action = {
242
+ type: WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
243
+ payload: {
244
+ text: "test-text",
245
+ activity: {
246
+ channelId: "something_else",
247
+ from: {
248
+ role: "user"
249
+ },
250
+ channelData: {
251
+ metadata: {
252
+ "OriginalMessageId": "1683742135918"
253
+ },
254
+ "webchat:sequence-id": 12345
255
+ }
256
+ }
257
+ }
258
+ };
259
+ const middleware = createMessageSequenceIdOverrideMiddleware(dispatch)(next)(action);
260
+ let resultValue;
261
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
262
+ const channelData = middleware.payload.activity.channelData;
263
+ Object.keys(channelData).forEach(function (key) {
264
+ if (key === Constants.WebchatSequenceIdAttribute) {
265
+ resultValue = channelData[key];
266
+ }
267
+ });
268
+ expect(resultValue).toEqual(12345);
269
+ });
270
+ it("no override, since the channel channelData is not present", () => {
271
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
272
+ const next = args => args;
273
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
274
+ const dispatch = () => {
275
+ return 1;
276
+ };
277
+ const action = {
278
+ type: WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
279
+ payload: {
280
+ text: "test-text channel data is not present",
281
+ activity: {
282
+ channelId: "ACS_CHANNEL",
283
+ from: {
284
+ role: "user"
285
+ }
286
+ }
287
+ }
288
+ };
289
+ const middleware = createMessageSequenceIdOverrideMiddleware(dispatch)(next)(action);
290
+ expect(middleware.payload).toEqual(action.payload);
291
+ });
292
+ it("no override, since channelData is empty object", () => {
293
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
294
+ const next = args => args;
295
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
296
+ const dispatch = () => {
297
+ return 1;
298
+ };
299
+ const action = {
300
+ type: WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
301
+ payload: {
302
+ text: "test-text channel data empty",
303
+ activity: {
304
+ channelId: "ACS_CHANNEL",
305
+ from: {
306
+ role: "user"
307
+ },
308
+ channelData: {}
309
+ }
310
+ }
311
+ };
312
+ const middleware = createMessageSequenceIdOverrideMiddleware(dispatch)(next)(action);
313
+ expect(middleware.payload).toEqual(action.payload);
314
+ });
315
+ it("no override, since channelData null", () => {
316
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
317
+ const next = args => args;
318
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
319
+ const dispatch = () => {
320
+ return 1;
321
+ };
322
+ const action = {
323
+ type: WebChatActionType.DIRECT_LINE_INCOMING_ACTIVITY,
324
+ payload: {
325
+ text: "test-channel Data null",
326
+ activity: {
327
+ channelId: "ACS_CHANNEL",
328
+ from: {
329
+ role: "user"
330
+ },
331
+ channelData: null
332
+ }
333
+ }
334
+ };
335
+ const middleware = createMessageSequenceIdOverrideMiddleware(dispatch)(next)(action);
336
+ expect(middleware.payload).toEqual(action.payload);
337
+ });
338
+ });
@@ -120,7 +120,13 @@ class TranscriptHTMLBuilder {
120
120
  <script>
121
121
  class Translator {
122
122
  static convertTranscriptMessageToActivity(message) {
123
- const {created, isControlMessage, content, tags, from, attachments, amsMetadata, amsReferences} = message;
123
+ const {created, OriginalMessageId, id, isControlMessage, content, tags, from, attachments, amsMetadata, amsReferences} = message;
124
+
125
+ //it's required to convert the id to a number, otherwise the webchat will not render the messages in the correct order
126
+ // if the OrginalMessageId is not present, we can use the id as the sequence id, which is always present.
127
+
128
+ const webchatSequenceId = Translator.convertStringValueToInt(OriginalMessageId) || Translator.convertStringValueToInt(id);
129
+
124
130
  const activity = {
125
131
  from: {
126
132
  role: 'bot'
@@ -175,7 +181,10 @@ class TranscriptHTMLBuilder {
175
181
  return {
176
182
  ...activity,
177
183
  text,
178
- timestamp: created
184
+ timestamp: created,
185
+ channelData: {
186
+ "webchat:sequence-id": webchatSequenceId
187
+ }
179
188
  }
180
189
  }
181
190
 
@@ -188,7 +197,10 @@ class TranscriptHTMLBuilder {
188
197
  return {
189
198
  ...activity,
190
199
  ...partialActivity,
191
- timestamp: created
200
+ timestamp: created,
201
+ channelData: {
202
+ "webchat:sequence-id": webchatSequenceId
203
+ }
192
204
  };
193
205
  } catch {
194
206
 
@@ -199,9 +211,21 @@ class TranscriptHTMLBuilder {
199
211
  return {
200
212
  ...activity,
201
213
  text: content,
202
- timestamp: created
214
+ timestamp: created,
215
+ channelData: {
216
+ "webchat:sequence-id": webchatSequenceId
217
+ }
203
218
  };
204
219
  }
220
+
221
+ static convertStringValueToInt(value) {
222
+ if (typeof value !== "string" || value === "") {
223
+ return undefined;
224
+ }
225
+
226
+ const result = parseInt(value);
227
+ return isNaN(result) ? undefined : result;
228
+ }
205
229
  }
206
230
  <\/script>
207
231
  <script>
@@ -41,6 +41,7 @@ export declare class Constants {
41
41
  static readonly acsChannel = "ACS_CHANNEL";
42
42
  static readonly publicMessageTag = "public";
43
43
  static readonly supportedAdaptiveCardContentTypes: Array<string>;
44
+ static readonly adaptiveCardContentTypePrefix = "application/vnd.microsoft.card";
44
45
  static readonly maxUploadFileSize = "500000";
45
46
  static readonly imageRegex: RegExp;
46
47
  static readonly audioMediaRegex: RegExp;
@@ -86,6 +87,9 @@ export declare class Constants {
86
87
  static readonly LWICheckOnVisibilityTimeout: number;
87
88
  static readonly InitContextParamsRequest = "initContextParamsRequest";
88
89
  static readonly InitContextParamsResponse = "initContextParamsResponse";
90
+ static readonly OCOriginalMessageId = "OriginalMessageId";
91
+ static readonly WebchatSequenceIdAttribute = "webchat:sequence-id";
92
+ static readonly MessageSequenceIdOverride = "MessageSequenceIdOverride";
89
93
  }
90
94
  export declare const Regex: {
91
95
  new (): {};
@@ -3,7 +3,7 @@ import ChatConfig from "@microsoft/omnichannel-chat-sdk/lib/core/ChatConfig";
3
3
  import { Dispatch } from "react";
4
4
  import { ILiveChatWidgetAction } from "../../../contexts/common/ILiveChatWidgetAction";
5
5
  import { ILiveChatWidgetContext } from "../../../contexts/common/ILiveChatWidgetContext";
6
- declare const handleChatReconnect: (chatSDK: any, props: any, dispatch: Dispatch<ILiveChatWidgetAction>, setAdapter: any, initStartChat: any, state: ILiveChatWidgetContext) => Promise<void>;
6
+ declare const handleChatReconnect: (chatSDK: any, props: any, dispatch: Dispatch<ILiveChatWidgetAction>, setAdapter: any, initStartChat: any, state: ILiveChatWidgetContext) => Promise<boolean>;
7
7
  declare const getChatReconnectContext: (chatSDK: any, chatConfig: ChatConfig, props: any, isAuthenticatedChat: boolean) => Promise<any>;
8
8
  declare const isReconnectEnabled: (chatConfig?: ChatConfig | undefined) => boolean;
9
9
  declare const isPersistentEnabled: (chatConfig?: ChatConfig | undefined) => boolean;
@@ -0,0 +1,5 @@
1
+ import { IWebChatAction } from "../../../interfaces/IWebChatAction";
2
+ declare const createMessageSequenceIdOverrideMiddleware: ({ dispatch }: {
3
+ dispatch: any;
4
+ }) => (next: any) => (action: IWebChatAction) => any;
5
+ export default createMessageSequenceIdOverrideMiddleware;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/omnichannel-chat-widget",
3
- "version": "1.2.2",
3
+ "version": "1.2.3-main.2ce131d",
4
4
  "description": "Microsoft Omnichannel Chat Widget",
5
5
  "main": "lib/cjs/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -74,7 +74,7 @@
74
74
  "webpack-cli": "^4.9.2"
75
75
  },
76
76
  "dependencies": {
77
- "@microsoft/omnichannel-chat-components": "^1.0.5",
77
+ "@microsoft/omnichannel-chat-components": "^1.0.6",
78
78
  "@microsoft/omnichannel-chat-sdk": "1.4.6",
79
79
  "abort-controller-es5": "^2.0.1",
80
80
  "dompurify": "^2.3.4",