@microsoft/omnichannel-chat-sdk 1.11.9-main.e5288e0 → 2.0.0-main.983bdbd

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 (55) hide show
  1. package/README.md +111 -11
  2. package/lib/OmnichannelChatSDK.d.ts +38 -0
  3. package/lib/OmnichannelChatSDK.js +273 -39
  4. package/lib/OmnichannelChatSDK.js.map +1 -1
  5. package/lib/config/settings.d.ts +2 -2
  6. package/lib/config/settings.js +2 -2
  7. package/lib/config/settings.js.map +1 -1
  8. package/lib/core/ChatSDKError.d.ts +11 -1
  9. package/lib/core/ChatSDKError.js +10 -0
  10. package/lib/core/ChatSDKError.js.map +1 -1
  11. package/lib/core/ChatSDKExceptionDetails.d.ts +6 -0
  12. package/lib/core/StartChatOptionalParams.d.ts +10 -0
  13. package/lib/core/messaging/ACSClient.d.ts +7 -0
  14. package/lib/core/messaging/ACSClient.js +216 -12
  15. package/lib/core/messaging/ACSClient.js.map +1 -1
  16. package/lib/core/messaging/OmnichannelStreamingMessage.d.ts +13 -0
  17. package/lib/core/messaging/OmnichannelStreamingMessage.js +3 -0
  18. package/lib/core/messaging/OmnichannelStreamingMessage.js.map +1 -0
  19. package/lib/core/messaging/OnStreamingMessageOptionalParams.d.ts +8 -0
  20. package/lib/core/messaging/OnStreamingMessageOptionalParams.js +3 -0
  21. package/lib/core/messaging/OnStreamingMessageOptionalParams.js.map +1 -0
  22. package/lib/core/messaging/PolicyViolation.d.ts +8 -0
  23. package/lib/core/messaging/PolicyViolation.js +3 -0
  24. package/lib/core/messaging/PolicyViolation.js.map +1 -0
  25. package/lib/core/messaging/StreamingMetadata.d.ts +11 -0
  26. package/lib/core/messaging/StreamingMetadata.js +3 -0
  27. package/lib/core/messaging/StreamingMetadata.js.map +1 -0
  28. package/lib/index.d.ts +5 -1
  29. package/lib/index.js.map +1 -1
  30. package/lib/telemetry/MessageSource.d.ts +1 -0
  31. package/lib/telemetry/MessageSource.js +1 -0
  32. package/lib/telemetry/MessageSource.js.map +1 -1
  33. package/lib/telemetry/TelemetryEvent.d.ts +23 -1
  34. package/lib/telemetry/TelemetryEvent.js +23 -0
  35. package/lib/telemetry/TelemetryEvent.js.map +1 -1
  36. package/lib/tsconfig.tsbuildinfo +1 -1
  37. package/lib/utils/createOmnichannelMessage.js +27 -1
  38. package/lib/utils/createOmnichannelMessage.js.map +1 -1
  39. package/lib/utils/createOmnichannelStreamingMessage.d.ts +14 -0
  40. package/lib/utils/createOmnichannelStreamingMessage.js +106 -0
  41. package/lib/utils/createOmnichannelStreamingMessage.js.map +1 -0
  42. package/lib/utils/errorClassifier.d.ts +25 -0
  43. package/lib/utils/errorClassifier.js +75 -0
  44. package/lib/utils/errorClassifier.js.map +1 -0
  45. package/lib/utils/exceptionThrowers.d.ts +38 -4
  46. package/lib/utils/exceptionThrowers.js +25 -8
  47. package/lib/utils/exceptionThrowers.js.map +1 -1
  48. package/lib/utils/printers/MessagePrinterFactory.d.ts +3 -2
  49. package/lib/utils/printers/MessagePrinterFactory.js +6 -0
  50. package/lib/utils/printers/MessagePrinterFactory.js.map +1 -1
  51. package/lib/utils/printers/StreamingMessagePrinter.d.ts +5 -0
  52. package/lib/utils/printers/StreamingMessagePrinter.js +33 -0
  53. package/lib/utils/printers/StreamingMessagePrinter.js.map +1 -0
  54. package/lib/utils/printers/types/MessageType.d.ts +2 -1
  55. package/package.json +14 -8
package/README.md CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/%40microsoft%2Fomnichannel-chat-sdk.svg)](https://badge.fury.io/js/%40microsoft%2Fomnichannel-chat-sdk)
4
4
  [![install size](https://packagephobia.com/badge?p=@microsoft/omnichannel-chat-sdk)](https://packagephobia.com/result?p=@microsoft/omnichannel-chat-sdk)
5
- ![Release CI](https://github.com/microsoft/omnichannel-chat-sdk/workflows/Release%20CI/badge.svg)
5
+ [![npm Release](https://github.com/microsoft/omnichannel-chat-sdk/actions/workflows/npm-release.yml/badge.svg)](https://github.com/microsoft/omnichannel-chat-sdk/actions/workflows/npm-release.yml)
6
6
  ![npm](https://img.shields.io/npm/dm/@microsoft/omnichannel-chat-sdk)
7
7
 
8
- > ❗ We recommend using official release versions in production as listed [here](#releases). Support will be provided only on official versions.
9
-
10
- > 📢 Try out our new React component library [omnichannel-chat-widget](https://github.com/microsoft/omnichannel-chat-widget) with Chat SDK
8
+ > [!IMPORTANT]
9
+ > * We recommend using official release versions in production as listed [here](#releases). Support will be provided only on official versions.
10
+ > * Microsoft provides this SDK to ensure a scaleable and secure use of our platform. Do not directly access the APIs used in this repository — you may experience breaking changes, and we will not be able to provide support for any issues.
11
11
 
12
12
  Headless Chat SDK to build your own chat widget against Dynamics 365 Omnichannel Services.
13
13
 
@@ -22,6 +22,7 @@ Please make sure you have a chat widget configured before using this package or
22
22
  - [SDK Methods](#sdk-methods)
23
23
  - [Initialization](#initialization)
24
24
  - [Start Chat](#start-chat)
25
+ - [Authenticate Chat](#authenticate-chat)
25
26
  - [End Chat](#end-chat)
26
27
  - [Get Pre-Chat Survey](#get-pre-chat-survey)
27
28
  - [Get Live Chat Config](#get-live-chat-config)
@@ -34,6 +35,7 @@ Please make sure you have a chat widget configured before using this package or
34
35
  - [Get Messages](#get-messages)
35
36
  - [Send Messages](#send-messages)
36
37
  - [On New Message](#on-new-message)
38
+ - [On Streaming Message](#on-streaming-message)
37
39
  - [On Typing Event](#on-typing-event)
38
40
  - [On Agent End Session](#on-agent-end-session)
39
41
  - [Send Typing Event](#send-typing-event)
@@ -45,6 +47,8 @@ Please make sure you have a chat widget configured before using this package or
45
47
  - [Get Voice & Video Calling](#get-voice--video-calling)
46
48
  - [Get Post Chat Survey Context](#get-post-chat-survey-context)
47
49
  - [Get Persistent Chat History](#get-persistent-chat-history)
50
+ - [Send Read Receipt](#send-read-receipt)
51
+ - [Get Unread Message Count](#get-unread-message-count)
48
52
  - [Common Scenarios](#common-scenarios)
49
53
  - [Using BotFramework-WebChat](#using-botframework-webchat)
50
54
  - [Escalation to Voice & Video](#escalation-to-voice--video)
@@ -56,7 +60,7 @@ Please make sure you have a chat widget configured before using this package or
56
60
  - [Persistent Chat History](#persistent-chat-history)
57
61
  - [Chat Reconnect with Authenticated User](#chat-reconnect-with-authenticated-user)
58
62
  - [Chat Reconnect with Unauthenticated User](#chat-reconnect-with-unauthenticated-user)
59
- - [Best Practices for Chat Session Management: Handling Disconnections and Network Instabilit(#best-practices-for-chat-session-management:-handling-disconnections-and-network-instability)
63
+ - [Best Practices for Chat Session Management: Handling Disconnections and Network Instability](#best-practices-for-chat-session-management-handling-disconnections-and-network-instability)
60
64
  - [Operating Hours](#operating-hours)
61
65
  - [Single Sign-on for Bots](/docs/scenarios/SINGLE_SIGN_ON_FOR_BOTS.md)
62
66
  - [Sample Apps](https://github.com/microsoft/omnichannel-chat-sdk-samples)
@@ -106,22 +110,39 @@ Omnichannel offers a live chat widget (LCW) by default. You can use the Chat SDK
106
110
 
107
111
  New releases are published on a regular basis to ensure the product quality.
108
112
 
109
- for a detailed tracking of the releases, please refer to the [Changelog document](https://github.com/microsoft/omnichannel-chat-sdk/blob/main/CHANGELOG.md)
110
-
111
- _**Important Note:**_ Versions below 1.11.0 will not be supported after November 1st, 2025. Please update to recent versions to ensure you have the latest features and bug fixes.
113
+ For a detailed tracking of the releases, please refer to the [Changelog document](https://github.com/microsoft/omnichannel-chat-sdk/blob/main/CHANGELOG.md)
112
114
 
115
+ _**Important Note:**_ Versions below 1.11.0 are no longer supported after November 1st, 2025. Please update to recent versions to ensure you have the latest features and bug fixes.
113
116
 
114
117
  | Version | Docs | Release Date | End of Support | Deprecated |
115
118
  | -- | -- | -- | -- | -- |
119
+ | 2.0.0 | [Migration Guide](docs/MIGRATION_2.0.md) / [Release Notes](https://github.com/microsoft/omnichannel-chat-sdk/releases/tag/v2.0.0) | Aug 13th 2026 | Aug 13th 2027 | |
116
120
  | 1.11.4 | [Release Notes](https://github.com/microsoft/omnichannel-chat-sdk/releases/tag/v1.11.4) | Jul 17th 2025 | Jul 17th 2026 | |
117
121
  | 1.11.3 | [Release Notes](https://github.com/microsoft/omnichannel-chat-sdk/releases/tag/v1.11.3) | Jul 14th 2025 | Jul 14th 2026 | |
118
122
  | 1.11.2 | [Release Notes](https://github.com/microsoft/omnichannel-chat-sdk/releases/tag/v1.11.2) | Jun 24th 2025 | Jun 24th 2026 | |
119
123
  | 1.11.1 | [Release Notes](https://github.com/microsoft/omnichannel-chat-sdk/releases/tag/v1.11.1) | Jun 5th 2025 | Jun 5th 2026 | |
120
124
  | 1.11.0 | [Release Notes](https://github.com/microsoft/omnichannel-chat-sdk/releases/tag/v1.11.0) | May 27th 2025 | May 27th 2026 | |
121
125
 
126
+ ### Upgrade to 2.0.0
127
+
128
+ Version `2.0.0` requires Node.js `>=22.12.0`. This requirement also applies to the official OC SDK and AMS client dependencies.
129
+
130
+ ```bash
131
+ npm install @microsoft/omnichannel-chat-sdk@2.0.0 --save-exact
132
+ ```
133
+
134
+ The npm `latest` dist-tag can point to a `main` prerelease. Use the exact version for production.
135
+
136
+ Regenerate the application lockfile after the update. Then run the application build and tests on Node.js 22.
137
+
138
+ Version `2.0.0` adds progressive bot-message streaming, mid-conversation authentication, read receipts, and unread-message counts. Existing `onNewMessage` handlers continue to receive final streaming messages.
139
+
140
+ See the [2.0 migration guide](docs/MIGRATION_2.0.md) for the complete upgrade and validation procedure.
122
141
 
123
142
  ## Installation
124
143
 
144
+ Node.js `>=22.12.0` is required.
145
+
125
146
  ```console
126
147
  npm install @microsoft/omnichannel-chat-sdk --save
127
148
  ```
@@ -310,6 +331,32 @@ const optionalParams = {
310
331
  await chatSDK.startChat(optionalParams);
311
332
  ```
312
333
 
334
+ ### Authenticate Chat
335
+
336
+ It authenticates an active unauthenticated conversation. Enable optional authenticated sign-in for the workstream before you use this method.
337
+
338
+ Call `initialize()` and `startChat()` before `authenticateChat()`. The first argument can be a token or an asynchronous token provider.
339
+
340
+ ```ts
341
+ await chatSDK.initialize();
342
+ await chatSDK.startChat();
343
+
344
+ await chatSDK.authenticateChat(async () => {
345
+ const response = await fetch("https://contoso.example/token");
346
+ if (!response.ok) {
347
+ throw new Error("Token request failed");
348
+ }
349
+
350
+ return response.text();
351
+ }, {
352
+ refreshChatToken: true
353
+ });
354
+ ```
355
+
356
+ Set `refreshChatToken` to `true` when subsequent SDK calls must use a refreshed authenticated chat token.
357
+
358
+ The method throws `InvalidConversation` when no conversation is active. It throws `MidConversationAuthFailure` when token resolution or authentication fails.
359
+
313
360
  ### End Chat
314
361
 
315
362
  It ends the current Omnichannel conversation.
@@ -454,6 +501,38 @@ chatSDK.onNewMessage((message) => {
454
501
  }, optionalParams);
455
502
  ```
456
503
 
504
+ ### On Streaming Message
505
+
506
+ It subscribes to progressive ACS bot-message updates. This API is available only for Live Chat version 2.
507
+
508
+ Enable streaming when you start the conversation. Then register the handler after `startChat()` completes.
509
+
510
+ ```ts
511
+ await chatSDK.initialize();
512
+ await chatSDK.startChat({
513
+ supportsLcwStreaming: true
514
+ });
515
+
516
+ await chatSDK.onStreamingMessage((message) => {
517
+ const { streamingMessageType, streamEndReason } = message.streamingMetadata;
518
+
519
+ // Each event contains the full assembled content, not only the new text.
520
+ renderStreamingMessage(message.id, message.content);
521
+
522
+ if (message.policyViolation) {
523
+ handlePolicyViolation(message.policyViolation.result);
524
+ }
525
+
526
+ if (streamingMessageType === "final") {
527
+ completeStreamingMessage(message.id, streamEndReason);
528
+ }
529
+ });
530
+ ```
531
+
532
+ `streamingMessageType` can be `start`, `informative`, `streaming`, or `final`. A final message also reaches existing `onNewMessage` handlers.
533
+
534
+ Calling this method before `startChat()` throws `UninitializedConversation`. Calling it for another Live Chat version throws `UnsupportedLiveChatVersion`.
535
+
457
536
  ### On Typing Event
458
537
 
459
538
  It subscribes to an agent typing event.
@@ -607,6 +686,27 @@ It gets information on whether a queue is available, and whether there are agent
607
686
  const agentAvailability = await chatSDK.getAgentAvailability();
608
687
  ```
609
688
 
689
+ ### Send Read Receipt
690
+
691
+ Logs a particular message (and all previous messages) as read by the user. Read indicators will appear for Contact Center Representatives and Admins in the Admin Center.
692
+
693
+ Authenticated chat sends the receipt through Messaging Runtime. Unauthenticated chat sends it through ACS and requires Live Chat version 2.
694
+
695
+ ```ts
696
+ await chatSDK.sendReadReceipt(messageId: string);
697
+ ```
698
+
699
+ ### Get Unread Message Count
700
+
701
+ Returns unread-message data for an authenticated user. An active chat session is not required. This call is **authenticated-only** — the user must be authenticated, otherwise an `UndefinedAuthToken` error is thrown.
702
+
703
+ ```ts
704
+ const response = await chatSDK.getUnreadMessageCount();
705
+
706
+ // response.unreadMessageCount: number — Number of unread messages in the conversation
707
+ // response.mostRecentUnreadMessage: object | null — The most recent unread message, or null if there are none
708
+ ```
709
+
610
710
  ## Common Scenarios
611
711
 
612
712
  ### Pre-Chat Survey
@@ -1302,11 +1402,11 @@ const chatSDK = new OmnichannelChatSDK.OmnichannelChatSDK(omnichannelConfig, cha
1302
1402
  await chatSDK.initialize();
1303
1403
  ```
1304
1404
 
1305
- # Releasing
1405
+ ## Releasing
1306
1406
 
1307
- See [docs/RELEASING.md](docs/RELEASING.md) for how to publish new versions to npm.
1407
+ See [docs/RELEASING.md](docs/RELEASING.md) for development builds, official npm and GitHub releases, release notes, and hotfixes.
1308
1408
 
1309
- # Contributing
1409
+ ## Contributing
1310
1410
 
1311
1411
  This project welcomes contributions and suggestions. Most contributions require you to agree to a
1312
1412
  Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
@@ -30,7 +30,9 @@ import InitializeOptionalParams from "./core/InitializeOptionalParams";
30
30
  import LiveWorkItemDetails from "./core/LiveWorkItemDetails";
31
31
  import OmnichannelConfig from "./core/OmnichannelConfig";
32
32
  import OmnichannelMessage from "./core/messaging/OmnichannelMessage";
33
+ import OmnichannelStreamingMessage from "./core/messaging/OmnichannelStreamingMessage";
33
34
  import OnNewMessageOptionalParams from "./core/messaging/OnNewMessageOptionalParams";
35
+ import OnStreamingMessageOptionalParams from "./core/messaging/OnStreamingMessageOptionalParams";
34
36
  import PostChatContext from "./core/PostChatContext";
35
37
  import StartChatOptionalParams from "./core/StartChatOptionalParams";
36
38
  declare class OmnichannelChatSDK {
@@ -171,7 +173,36 @@ declare class OmnichannelChatSDK {
171
173
  sendMessage(message: ChatSDKMessage): Promise<OmnichannelMessage | void>;
172
174
  onNewMessage(onNewMessageCallback: CallableFunction, optionalParams?: OnNewMessageOptionalParams): Promise<void>;
173
175
  sendTypingEvent(): Promise<void>;
176
+ /**
177
+ * Fetches unread message count for the authenticated user.
178
+ * Auth-only — does not require an active chat session.
179
+ */
180
+ getUnreadMessageCount(): Promise<object>;
181
+ /**
182
+ * Sends a read receipt for a specific message.
183
+ * Authenticated: calls MRT (updates NRD + forwards to ACS).
184
+ * Unauthenticated: calls ACS directly.
185
+ */
186
+ sendReadReceipt(messageId: string): Promise<void>;
174
187
  onTypingEvent(onTypingEventCallback: CallableFunction): Promise<void>;
188
+ /**
189
+ * Subscribes to ACS-driven streaming message chunks for progressive bot message rendering.
190
+ * Each chunk contains the full assembled text so far (not just the delta).
191
+ * Existing onNewMessage consumers continue receiving final messages without changes.
192
+ *
193
+ * Available only in LiveChatVersion.V2. Must call startChat() before registering.
194
+ *
195
+ * @param onStreamingMessageCallback - Called for each streaming chunk
196
+ * @param optionalParams - Reserved for future configuration
197
+ * @example
198
+ * chatSDK.onStreamingMessage((message) => {
199
+ * switch (message.streamingMetadata.streamingMessageType) {
200
+ * case "streaming": // Update bubble with message.content
201
+ * case "final": // Stream complete
202
+ * }
203
+ * });
204
+ */
205
+ onStreamingMessage(onStreamingMessageCallback: (message: OmnichannelStreamingMessage) => void, optionalParams?: OnStreamingMessageOptionalParams): Promise<void>;
175
206
  onAgentEndSession(onAgentEndSessionCallback: (message: IRawThread | ParticipantsRemovedEvent) => void): Promise<void>;
176
207
  uploadFileAttachment(fileInfo: IFileInfo | File): Promise<UploadFileAttachmentResponse>;
177
208
  downloadFileAttachment(fileMetadata: FileMetadata | IFileMetadata): Promise<Blob>;
@@ -198,6 +229,13 @@ declare class OmnichannelChatSDK {
198
229
  private setCallingOptionConfiguration;
199
230
  private setLiveChatVersionConfiguration;
200
231
  private setWidgetSnippetBaseUrl;
232
+ /**
233
+ * Creates diagnostic data for getChatConfig errors using the error classifier
234
+ * @param e The error object
235
+ * @param clientElapsedMs Optional elapsed time in milliseconds from client's perspective
236
+ * @returns Diagnostic data with clientElapsedMs, online status, and cancellation reason
237
+ */
238
+ private createGetChatConfigDiagnosticData;
201
239
  private getChatConfig;
202
240
  private buildConfigurations;
203
241
  private resolveIC3ClientUrl;