@microsoft/omnichannel-chat-sdk 2.0.2-main.07ad838 → 2.0.2-main.355218f
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.
- package/README.md +21 -0
- package/lib/OmnichannelChatSDK.d.ts +11 -0
- package/lib/OmnichannelChatSDK.js +42 -0
- package/lib/OmnichannelChatSDK.js.map +1 -1
- package/lib/core/messaging/ACSClient.d.ts +3 -1
- package/lib/core/messaging/ACSClient.js +49 -24
- package/lib/core/messaging/ACSClient.js.map +1 -1
- package/lib/telemetry/TelemetryEvent.d.ts +1 -0
- package/lib/telemetry/TelemetryEvent.js +1 -0
- package/lib/telemetry/TelemetryEvent.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,6 +35,7 @@ Please make sure you have a chat widget configured before using this package or
|
|
|
35
35
|
- [Send Messages](#send-messages)
|
|
36
36
|
- [On New Message](#on-new-message)
|
|
37
37
|
- [On Streaming Message](#on-streaming-message)
|
|
38
|
+
- [On Chat Token Renewed](#on-chat-token-renewed)
|
|
38
39
|
- [On Typing Event](#on-typing-event)
|
|
39
40
|
- [On Agent End Session](#on-agent-end-session)
|
|
40
41
|
- [Send Typing Event](#send-typing-event)
|
|
@@ -516,6 +517,26 @@ await chatSDK.onStreamingMessage((message) => {
|
|
|
516
517
|
|
|
517
518
|
Calling this method before `startChat()` throws `UninitializedConversation`. If the conversation does not use ACS, this method throws `UnsupportedLiveChatVersion`.
|
|
518
519
|
|
|
520
|
+
### On Chat Token Renewed
|
|
521
|
+
|
|
522
|
+
Subscribes to notifications after the SDK renews the chat token and updates the current live chat context.
|
|
523
|
+
If your application caches this context for page refresh or reconnect, save the updated context in the callback
|
|
524
|
+
so subsequent restores use the renewed credentials.
|
|
525
|
+
|
|
526
|
+
Register before `startChat()` to capture renewals during startup, including when restoring a saved chat.
|
|
527
|
+
|
|
528
|
+
```ts
|
|
529
|
+
const unsubscribe = chatSDK.onChatTokenRenewed(async () => {
|
|
530
|
+
const liveChatContext = await chatSDK.getCurrentLiveChatContext();
|
|
531
|
+
cache.saveChatContext(liveChatContext); // Custom logic to save chat context to cache
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
await chatSDK.startChat();
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
The listener remains registered across chats on the same SDK instance; call `unsubscribe()` during cleanup.
|
|
538
|
+
Token renewal works without a subscription.
|
|
539
|
+
|
|
519
540
|
### On Typing Event
|
|
520
541
|
|
|
521
542
|
It subscribes to an agent typing event.
|
|
@@ -58,6 +58,7 @@ declare class OmnichannelChatSDK {
|
|
|
58
58
|
private dynamicsLocationCode;
|
|
59
59
|
private chatToken;
|
|
60
60
|
private chatTokenUnauthorizedRecovery;
|
|
61
|
+
private chatTokenRenewedListeners;
|
|
61
62
|
private liveChatConfig;
|
|
62
63
|
private widgetSnippetBaseUrl;
|
|
63
64
|
private liveChatVersion;
|
|
@@ -157,6 +158,15 @@ declare class OmnichannelChatSDK {
|
|
|
157
158
|
private waitForMessageTags;
|
|
158
159
|
private waitForSurveyStart;
|
|
159
160
|
private waitForConversationalSurveyEnd;
|
|
161
|
+
/**
|
|
162
|
+
* Subscribes to usable chat token renewals after the current SDK context has been updated.
|
|
163
|
+
* No token or other payload is passed. Read getCurrentLiveChatContext() to persist the updated context.
|
|
164
|
+
* Returns an idempotent unsubscribe function. Listener failures never affect renewal.
|
|
165
|
+
* Subscriptions belong to this SDK instance and survive endChat()/startChat().
|
|
166
|
+
* Subscribe before startChat() to observe restoration renewals; past notifications are not replayed.
|
|
167
|
+
* Unsubscribe on host teardown or before replacing a per-chat subscription.
|
|
168
|
+
*/
|
|
169
|
+
onChatTokenRenewed(listener: () => void): () => void;
|
|
160
170
|
getCurrentLiveChatContext(): Promise<GetCurrentLiveChatContextResponse>;
|
|
161
171
|
getConversationDetails(optionalParams?: GetConversationDetailsOptionalParams): Promise<LiveWorkItemDetails>;
|
|
162
172
|
/**
|
|
@@ -173,6 +183,7 @@ declare class OmnichannelChatSDK {
|
|
|
173
183
|
* supported by the installed OCSDK. The refresher never throws and falls back to the current token on failure.
|
|
174
184
|
*/
|
|
175
185
|
private createChatTokenRefresher;
|
|
186
|
+
private notifyChatTokenRenewed;
|
|
176
187
|
/**
|
|
177
188
|
* Gives the renewed chat token to the attachment client, which keeps the token it was initialized with and uses
|
|
178
189
|
* it for every upload and download. Runs in the background and never throws: on failure, attachments keep using
|
|
@@ -128,6 +128,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
128
128
|
this.coreServicesOrgUrl = null;
|
|
129
129
|
this.dynamicsLocationCode = null;
|
|
130
130
|
this.chatTokenUnauthorizedRecovery = null;
|
|
131
|
+
this.chatTokenRenewedListeners = new Set();
|
|
131
132
|
this.widgetSnippetBaseUrl = '';
|
|
132
133
|
this.dataMaskingRules = { rules: [] };
|
|
133
134
|
this.authSettings = null;
|
|
@@ -1567,6 +1568,20 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1567
1568
|
});
|
|
1568
1569
|
});
|
|
1569
1570
|
};
|
|
1571
|
+
/**
|
|
1572
|
+
* Subscribes to usable chat token renewals after the current SDK context has been updated.
|
|
1573
|
+
* No token or other payload is passed. Read getCurrentLiveChatContext() to persist the updated context.
|
|
1574
|
+
* Returns an idempotent unsubscribe function. Listener failures never affect renewal.
|
|
1575
|
+
* Subscriptions belong to this SDK instance and survive endChat()/startChat().
|
|
1576
|
+
* Subscribe before startChat() to observe restoration renewals; past notifications are not replayed.
|
|
1577
|
+
* Unsubscribe on host teardown or before replacing a per-chat subscription.
|
|
1578
|
+
*/
|
|
1579
|
+
OmnichannelChatSDK.prototype.onChatTokenRenewed = function (listener) {
|
|
1580
|
+
var _this = this;
|
|
1581
|
+
var subscription = function () { return listener(); };
|
|
1582
|
+
this.chatTokenRenewedListeners.add(subscription);
|
|
1583
|
+
return function () { _this.chatTokenRenewedListeners.delete(subscription); };
|
|
1584
|
+
};
|
|
1570
1585
|
OmnichannelChatSDK.prototype.getCurrentLiveChatContext = function () {
|
|
1571
1586
|
return __awaiter(this, void 0, void 0, function () {
|
|
1572
1587
|
var chatToken, requestId, chatSession;
|
|
@@ -1865,6 +1880,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1865
1880
|
var _a;
|
|
1866
1881
|
_this.chatToken = __assign(__assign({}, _this.chatToken), { token: renewed.Token, expiresIn: renewed.ExpiresIn !== undefined && renewed.ExpiresIn !== null ? String(renewed.ExpiresIn) : _this.chatToken.expiresIn, voiceVideoCallToken: (_a = renewed.VoiceVideoCallToken) !== null && _a !== void 0 ? _a : _this.chatToken.voiceVideoCallToken });
|
|
1867
1882
|
_this.refreshAttachmentClientToken(chatId_1);
|
|
1883
|
+
_this.notifyChatTokenRenewed(requestId_1, chatId_1);
|
|
1868
1884
|
},
|
|
1869
1885
|
onStart: function () { return _this.scenarioMarker.startScenario(TelemetryEvent_1.default.RenewChatToken, telemetryData_1); },
|
|
1870
1886
|
onSuccess: function () { return _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.RenewChatToken, telemetryData_1); },
|
|
@@ -1881,6 +1897,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
|
1881
1897
|
return undefined;
|
|
1882
1898
|
}
|
|
1883
1899
|
};
|
|
1900
|
+
OmnichannelChatSDK.prototype.notifyChatTokenRenewed = function (requestId, chatId) {
|
|
1901
|
+
var _this = this;
|
|
1902
|
+
var reportFailure = function (response) {
|
|
1903
|
+
try {
|
|
1904
|
+
var telemetryData = { RequestId: requestId, ChatId: chatId };
|
|
1905
|
+
_this.scenarioMarker.startScenario(TelemetryEvent_1.default.ChatTokenRenewedListener, telemetryData);
|
|
1906
|
+
_this.scenarioMarker.failScenario(TelemetryEvent_1.default.ChatTokenRenewedListener, __assign(__assign({}, telemetryData), { ExceptionDetails: JSON.stringify({ response: response }) }));
|
|
1907
|
+
}
|
|
1908
|
+
catch (_a) {
|
|
1909
|
+
// Subscriber telemetry must not affect renewal or become an unhandled rejection.
|
|
1910
|
+
}
|
|
1911
|
+
};
|
|
1912
|
+
Array.from(this.chatTokenRenewedListeners).forEach(function (listener) {
|
|
1913
|
+
var _a;
|
|
1914
|
+
if (_this.isEndingChat || _this.requestId !== requestId || ((_a = _this.chatToken) === null || _a === void 0 ? void 0 : _a.chatId) !== chatId
|
|
1915
|
+
|| !_this.chatTokenRenewedListeners.has(listener)) {
|
|
1916
|
+
return;
|
|
1917
|
+
}
|
|
1918
|
+
try {
|
|
1919
|
+
Promise.resolve(listener()).catch(function () { return reportFailure("ListenerRejected"); });
|
|
1920
|
+
}
|
|
1921
|
+
catch (_b) {
|
|
1922
|
+
reportFailure("ListenerThrew");
|
|
1923
|
+
}
|
|
1924
|
+
});
|
|
1925
|
+
};
|
|
1884
1926
|
/**
|
|
1885
1927
|
* Gives the renewed chat token to the attachment client, which keeps the token it was initialized with and uses
|
|
1886
1928
|
* it for every upload and download. Runs in the background and never throws: on failure, attachments keep using
|