@microsoft/omnichannel-chat-sdk 1.9.7-main.9019907 → 1.9.7
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/lib/OmnichannelChatSDK.d.ts +128 -128
- package/lib/OmnichannelChatSDK.js +2610 -2609
- package/lib/OmnichannelChatSDK.js.map +1 -1
- package/lib/api/createVoiceVideoCalling.d.ts +53 -53
- package/lib/api/createVoiceVideoCalling.js +462 -462
- package/lib/config/ocSDKConfiguration.d.ts +7 -7
- package/lib/config/ocSDKConfiguration.js +9 -9
- package/lib/config/settings.d.ts +7 -6
- package/lib/config/settings.js +15 -13
- package/lib/config/settings.js.map +1 -1
- package/lib/core/AuthSettings.d.ts +5 -5
- package/lib/core/AuthSettings.js +2 -2
- package/lib/core/AxiosErrorCodes.d.ts +4 -4
- package/lib/core/AxiosErrorCodes.js +7 -7
- package/lib/core/CallingOptionsOptionSetNumber.d.ts +6 -6
- package/lib/core/CallingOptionsOptionSetNumber.js +9 -9
- package/lib/core/ChatConfig.d.ts +10 -10
- package/lib/core/ChatConfig.js +2 -2
- package/lib/core/ChatReconnectContext.d.ts +4 -4
- package/lib/core/ChatReconnectContext.js +2 -2
- package/lib/core/ChatReconnectOptionalParams.d.ts +3 -3
- package/lib/core/ChatReconnectOptionalParams.js +2 -2
- package/lib/core/ChatSDKConfig.d.ts +38 -38
- package/lib/core/ChatSDKConfig.js +2 -2
- package/lib/core/ChatSDKError.d.ts +64 -64
- package/lib/core/ChatSDKError.js +73 -73
- package/lib/core/ChatSDKExceptionDetails.d.ts +13 -13
- package/lib/core/ChatSDKExceptionDetails.js +2 -2
- package/lib/core/ChatTranscriptBody.d.ts +5 -5
- package/lib/core/ChatTranscriptBody.js +2 -2
- package/lib/core/ConversationMode.d.ts +5 -5
- package/lib/core/ConversationMode.js +8 -8
- package/lib/core/EmailLiveChatTranscriptOptionalParams.d.ts +4 -4
- package/lib/core/EmailLiveChatTranscriptOptionalParams.js +2 -2
- package/lib/core/GetAgentAvailabilityOptionalParams.d.ts +13 -13
- package/lib/core/GetAgentAvailabilityOptionalParams.js +2 -2
- package/lib/core/GetChatTokenOptionalParams.d.ts +3 -3
- package/lib/core/GetChatTokenOptionalParams.js +2 -2
- package/lib/core/GetConversationDetailsOptionalParams.d.ts +4 -4
- package/lib/core/GetConversationDetailsOptionalParams.js +2 -2
- package/lib/core/GetLiveChatConfigOptionalParams.d.ts +5 -5
- package/lib/core/GetLiveChatConfigOptionalParams.js +2 -2
- package/lib/core/GetLiveChatTranscriptOptionalParams.d.ts +4 -4
- package/lib/core/GetLiveChatTranscriptOptionalParams.js +2 -2
- package/lib/core/InitializeOptionalParams.d.ts +6 -6
- package/lib/core/InitializeOptionalParams.js +2 -2
- package/lib/core/LiveChatContext.d.ts +14 -14
- package/lib/core/LiveChatContext.js +2 -2
- package/lib/core/LiveChatVersion.d.ts +5 -5
- package/lib/core/LiveChatVersion.js +8 -8
- package/lib/core/LiveWorkItemDetails.d.ts +8 -8
- package/lib/core/LiveWorkItemDetails.js +2 -2
- package/lib/core/LiveWorkItemState.d.ts +8 -8
- package/lib/core/LiveWorkItemState.js +11 -11
- package/lib/core/OmnichannelConfig.d.ts +5 -5
- package/lib/core/OmnichannelConfig.js +2 -2
- package/lib/core/OmnichannelErrorCodes.d.ts +4 -4
- package/lib/core/OmnichannelErrorCodes.js +7 -7
- package/lib/core/PostChatContext.d.ts +8 -8
- package/lib/core/PostChatContext.js +2 -2
- package/lib/core/SetAuthTokenProviderOptionalParams.d.ts +3 -3
- package/lib/core/SetAuthTokenProviderOptionalParams.js +2 -2
- package/lib/core/StartChatOptionalParams.d.ts +18 -18
- package/lib/core/StartChatOptionalParams.js +2 -2
- package/lib/core/messaging/ACSChatMessageType.d.ts +7 -7
- package/lib/core/messaging/ACSChatMessageType.js +10 -10
- package/lib/core/messaging/ACSClient.d.ts +45 -45
- package/lib/core/messaging/ACSClient.js +612 -612
- package/lib/core/messaging/ACSClientConfig.d.ts +5 -5
- package/lib/core/messaging/ACSClientConfig.js +2 -2
- package/lib/core/messaging/ACSParticipantDisplayName.d.ts +6 -6
- package/lib/core/messaging/ACSParticipantDisplayName.js +9 -9
- package/lib/core/messaging/ACSSessionInfo.d.ts +5 -5
- package/lib/core/messaging/ACSSessionInfo.js +2 -2
- package/lib/core/messaging/ChatAdapterConfig.d.ts +8 -8
- package/lib/core/messaging/ChatAdapterConfig.js +2 -2
- package/lib/core/messaging/ChatAdapterOptionalParams.d.ts +24 -24
- package/lib/core/messaging/ChatAdapterOptionalParams.js +2 -2
- package/lib/core/messaging/ChatAdapterProtocols.d.ts +6 -6
- package/lib/core/messaging/ChatAdapterProtocols.js +10 -10
- package/lib/core/messaging/ChatSDKMessage.d.ts +6 -6
- package/lib/core/messaging/ChatSDKMessage.js +2 -2
- package/lib/core/messaging/IC3Config.d.ts +4 -4
- package/lib/core/messaging/IC3Config.js +2 -2
- package/lib/core/messaging/MessageTags.d.ts +3 -3
- package/lib/core/messaging/MessageTags.js +6 -6
- package/lib/core/messaging/OmnichannelMessage.d.ts +64 -64
- package/lib/core/messaging/OmnichannelMessage.js +51 -51
- package/lib/core/messaging/OnNewMessageOptionalParams.d.ts +3 -3
- package/lib/core/messaging/OnNewMessageOptionalParams.js +2 -2
- package/lib/external/ACSAdapter/AMSFileManager.d.ts +76 -76
- package/lib/external/ACSAdapter/AMSFileManager.js +394 -394
- package/lib/external/ACSAdapter/AMSFileScanner.d.ts +36 -36
- package/lib/external/ACSAdapter/AMSFileScanner.js +275 -275
- package/lib/external/ACSAdapter/activityUtils.d.ts +9 -9
- package/lib/external/ACSAdapter/activityUtils.js +79 -79
- package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.d.ts +5 -5
- package/lib/external/ACSAdapter/createChannelDataEgressMiddleware.js +33 -33
- package/lib/external/ACSAdapter/createFileScanIngressMiddleware.d.ts +2 -2
- package/lib/external/ACSAdapter/createFileScanIngressMiddleware.js +95 -95
- package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.d.ts +2 -2
- package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.js +30 -30
- package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.d.ts +2 -2
- package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.js +24 -24
- package/lib/external/CallingSDK/ICallingSDKLogData.d.ts +7 -7
- package/lib/external/CallingSDK/ICallingSDKLogData.js +2 -2
- package/lib/external/IC3Adapter/IChatToken.d.ts +11 -11
- package/lib/external/IC3Adapter/IChatToken.js +3 -3
- package/lib/external/IC3Adapter/IIC3AdapterOptions.d.ts +22 -22
- package/lib/external/IC3Adapter/IIC3AdapterOptions.js +2 -2
- package/lib/external/IC3Adapter/INotification.d.ts +6 -6
- package/lib/external/IC3Adapter/INotification.js +2 -2
- package/lib/external/IC3Adapter/Notification.d.ts +7 -7
- package/lib/external/IC3Adapter/Notification.js +14 -14
- package/lib/external/IC3Client/IIC3SDKLogData.d.ts +9 -9
- package/lib/external/IC3Client/IIC3SDKLogData.js +2 -2
- package/lib/external/OCSDK/IOCSDKLogData.d.ts +14 -14
- package/lib/external/OCSDK/IOCSDKLogData.js +2 -2
- package/lib/index.d.ts +25 -25
- package/lib/index.js +34 -34
- package/lib/telemetry/AriaTelemetry.d.ts +40 -40
- package/lib/telemetry/AriaTelemetry.js +539 -539
- package/lib/telemetry/EUDomainNames.d.ts +2 -2
- package/lib/telemetry/EUDomainNames.js +16 -16
- package/lib/telemetry/EventMarker.d.ts +3 -3
- package/lib/telemetry/EventMarker.js +12 -12
- package/lib/telemetry/GCCDomainPatterns.d.ts +2 -2
- package/lib/telemetry/GCCDomainPatterns.js +7 -7
- package/lib/telemetry/LogLevel.d.ts +8 -8
- package/lib/telemetry/LogLevel.js +11 -11
- package/lib/telemetry/ScenarioMarker.d.ts +21 -21
- package/lib/telemetry/ScenarioMarker.js +82 -82
- package/lib/telemetry/ScenarioType.d.ts +11 -11
- package/lib/telemetry/ScenarioType.js +14 -14
- package/lib/telemetry/StopWatch.d.ts +6 -6
- package/lib/telemetry/StopWatch.js +14 -14
- package/lib/telemetry/TelemetryEvent.d.ts +46 -46
- package/lib/telemetry/TelemetryEvent.js +49 -49
- package/lib/telemetry/retrieveCollectorUri.d.ts +2 -2
- package/lib/telemetry/retrieveCollectorUri.js +25 -25
- package/lib/tsconfig.tsbuildinfo +1917 -1968
- package/lib/utils/AMSClientLoadStates.d.ts +6 -6
- package/lib/utils/AMSClientLoadStates.js +11 -11
- package/lib/utils/CoreServicesUtils.d.ts +7 -7
- package/lib/utils/CoreServicesUtils.js +39 -39
- package/lib/utils/WebUtils.d.ts +10 -10
- package/lib/utils/WebUtils.js +128 -128
- package/lib/utils/chatAdapterCreators.d.ts +20 -20
- package/lib/utils/chatAdapterCreators.js +208 -208
- package/lib/utils/createOcSDKConfiguration.d.ts +4 -4
- package/lib/utils/createOcSDKConfiguration.js +22 -22
- package/lib/utils/createOmnichannelMessage.d.ts +11 -11
- package/lib/utils/createOmnichannelMessage.js +77 -77
- package/lib/utils/createTelemetry.d.ts +3 -3
- package/lib/utils/createTelemetry.js +9 -9
- package/lib/utils/exceptionSuppressors.d.ts +29 -29
- package/lib/utils/exceptionSuppressors.js +49 -49
- package/lib/utils/exceptionThrowers.d.ts +119 -119
- package/lib/utils/exceptionThrowers.js +137 -137
- package/lib/utils/internalUtils.d.ts +4 -4
- package/lib/utils/internalUtils.js +16 -16
- package/lib/utils/libraries.d.ts +12 -12
- package/lib/utils/libraries.js +34 -34
- package/lib/utils/locale.d.ts +4 -4
- package/lib/utils/locale.js +60 -60
- package/lib/utils/location.d.ts +7 -7
- package/lib/utils/location.js +95 -95
- package/lib/utils/loggerUtils.d.ts +15 -15
- package/lib/utils/loggerUtils.js +55 -55
- package/lib/utils/loggers.d.ts +111 -111
- package/lib/utils/loggers.js +501 -501
- package/lib/utils/parsers.d.ts +6 -6
- package/lib/utils/parsers.js +10 -10
- package/lib/utils/platform.d.ts +9 -9
- package/lib/utils/platform.js +11 -11
- package/lib/utils/setOcUserAgent.d.ts +2 -2
- package/lib/utils/setOcUserAgent.js +21 -21
- package/lib/utils/sleep.d.ts +2 -2
- package/lib/utils/sleep.js +4 -4
- package/lib/utils/urlResolvers.d.ts +10 -10
- package/lib/utils/urlResolvers.js +64 -64
- package/lib/utils/utilities.d.ts +5 -5
- package/lib/utils/utilities.js +36 -36
- package/lib/validators/OmnichannelConfigValidator.d.ts +3 -3
- package/lib/validators/OmnichannelConfigValidator.js +28 -28
- package/lib/validators/SDKConfigValidators.d.ts +5 -5
- package/lib/validators/SDKConfigValidators.js +48 -48
- package/package.json +1 -1
- package/lib/utils/fillMobilePlatformData.d.ts +0 -2
- package/lib/utils/fillMobilePlatformData.js +0 -44
- package/lib/utils/fillMobilePlatformData.js.map +0 -1
- package/lib/utils/fillPlatformData.browser.d.ts +0 -2
- package/lib/utils/fillPlatformData.browser.js +0 -8
- package/lib/utils/fillPlatformData.browser.js.map +0 -1
- package/lib/utils/fillPlatformData.d.ts +0 -2
- package/lib/utils/fillPlatformData.js +0 -8
- package/lib/utils/fillPlatformData.js.map +0 -1
- package/lib/utils/fillWebPlatformData.d.ts +0 -2
- package/lib/utils/fillWebPlatformData.js +0 -21
- package/lib/utils/fillWebPlatformData.js.map +0 -1
@@ -1,613 +1,613 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
3
|
-
__assign = Object.assign || function(t) {
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
-
s = arguments[i];
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
-
t[p] = s[p];
|
8
|
-
}
|
9
|
-
return t;
|
10
|
-
};
|
11
|
-
return __assign.apply(this, arguments);
|
12
|
-
};
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
20
|
-
});
|
21
|
-
};
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
26
|
-
function step(op) {
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
28
|
-
while (_) try {
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
31
|
-
switch (op[0]) {
|
32
|
-
case 0: case 1: t = op; break;
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
36
|
-
default:
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
41
|
-
if (t[2]) _.ops.pop();
|
42
|
-
_.trys.pop(); continue;
|
43
|
-
}
|
44
|
-
op = body.call(thisArg, _);
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
47
|
-
}
|
48
|
-
};
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
50
|
-
exports.ACSConversation = void 0;
|
51
|
-
var ACSChatMessageType_1 = require("./ACSChatMessageType");
|
52
|
-
var ACSParticipantDisplayName_1 = require("./ACSParticipantDisplayName");
|
53
|
-
var communication_chat_1 = require("@azure/communication-chat");
|
54
|
-
var communication_common_1 = require("@azure/communication-common");
|
55
|
-
var createOmnichannelMessage_1 = require("../../utils/createOmnichannelMessage");
|
56
|
-
var MessageTags_1 = require("./MessageTags");
|
57
|
-
var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
|
58
|
-
var LiveChatVersion_1 = require("../LiveChatVersion");
|
59
|
-
var ACSClientEvent;
|
60
|
-
(function (ACSClientEvent) {
|
61
|
-
ACSClientEvent["InitializeACSClient"] = "InitializeACSClient";
|
62
|
-
ACSClientEvent["InitializeACSConversation"] = "InitializeACSConversation";
|
63
|
-
ACSClientEvent["GetParticipants"] = "GetParticipants";
|
64
|
-
ACSClientEvent["RegisterOnNewMessage"] = "RegisterOnNewMessage";
|
65
|
-
ACSClientEvent["RegisterOnThreadUpdate"] = "RegisterOnThreadUpdate";
|
66
|
-
ACSClientEvent["OnTypingEvent"] = "OnTypingEvent";
|
67
|
-
ACSClientEvent["GetMessages"] = "GetMessages";
|
68
|
-
ACSClientEvent["SendMessage"] = "SendMessage";
|
69
|
-
ACSClientEvent["SendTyping"] = "SendTyping";
|
70
|
-
ACSClientEvent["Disconnect"] = "Disconnect";
|
71
|
-
})(ACSClientEvent || (ACSClientEvent = {}));
|
72
|
-
var ACSConversation = /** @class */ (function () {
|
73
|
-
function ACSConversation(tokenCredential, chatClient, logger) {
|
74
|
-
if (logger === void 0) { logger = null; }
|
75
|
-
this.logger = null;
|
76
|
-
this.logger = logger;
|
77
|
-
this.tokenCredential = tokenCredential;
|
78
|
-
this.chatClient = chatClient;
|
79
|
-
this.eventListeners = {};
|
80
|
-
}
|
81
|
-
ACSConversation.prototype.initialize = function (sessionInfo) {
|
82
|
-
var _a, _b, _c, _d, _e;
|
83
|
-
return __awaiter(this, void 0, void 0, function () {
|
84
|
-
var _f, error_1, exceptionDetails, error_2, exceptionDetails;
|
85
|
-
return __generator(this, function (_g) {
|
86
|
-
switch (_g.label) {
|
87
|
-
case 0:
|
88
|
-
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.InitializeACSConversation);
|
89
|
-
this.sessionInfo = sessionInfo;
|
90
|
-
_g.label = 1;
|
91
|
-
case 1:
|
92
|
-
_g.trys.push([1, 3, , 4]);
|
93
|
-
_f = this;
|
94
|
-
return [4 /*yield*/, ((_b = this.chatClient) === null || _b === void 0 ? void 0 : _b.getChatThreadClient(sessionInfo.threadId))];
|
95
|
-
case 2:
|
96
|
-
_f.chatThreadClient = _g.sent();
|
97
|
-
return [3 /*break*/, 4];
|
98
|
-
case 3:
|
99
|
-
error_1 = _g.sent();
|
100
|
-
exceptionDetails = {
|
101
|
-
response: 'ChatClientGetChatThreadClientFailure',
|
102
|
-
errorObject: "" + error_1
|
103
|
-
};
|
104
|
-
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.failScenario(ACSClientEvent.InitializeACSConversation, {
|
105
|
-
ExceptionDetails: JSON.stringify(exceptionDetails)
|
106
|
-
});
|
107
|
-
throw new Error("GetChatThreadClientFailed");
|
108
|
-
case 4:
|
109
|
-
_g.trys.push([4, 6, , 7]);
|
110
|
-
return [4 /*yield*/, this.chatClient.startRealtimeNotifications()];
|
111
|
-
case 5:
|
112
|
-
_g.sent();
|
113
|
-
return [3 /*break*/, 7];
|
114
|
-
case 6:
|
115
|
-
error_2 = _g.sent();
|
116
|
-
exceptionDetails = {
|
117
|
-
response: 'StartRealtimeNotificationsFailed',
|
118
|
-
errorObject: "" + error_2
|
119
|
-
};
|
120
|
-
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.failScenario(ACSClientEvent.InitializeACSConversation, {
|
121
|
-
ExceptionDetails: JSON.stringify(exceptionDetails)
|
122
|
-
});
|
123
|
-
throw new Error(exceptionDetails.response);
|
124
|
-
case 7:
|
125
|
-
(_e = this.logger) === null || _e === void 0 ? void 0 : _e.completeScenario(ACSClientEvent.InitializeACSConversation);
|
126
|
-
return [2 /*return*/];
|
127
|
-
}
|
128
|
-
});
|
129
|
-
});
|
130
|
-
};
|
131
|
-
ACSConversation.prototype.getMessages = function () {
|
132
|
-
var _a, _b, _c;
|
133
|
-
return __awaiter(this, void 0, void 0, function () {
|
134
|
-
var messages, pagedAsyncIterableIterator, nextMessage, chatMessage, omnichannelMessage, error_3, exceptionDetails;
|
135
|
-
return __generator(this, function (_d) {
|
136
|
-
switch (_d.label) {
|
137
|
-
case 0:
|
138
|
-
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.GetMessages);
|
139
|
-
messages = [];
|
140
|
-
_d.label = 1;
|
141
|
-
case 1:
|
142
|
-
_d.trys.push([1, 9, , 10]);
|
143
|
-
return [4 /*yield*/, this.chatThreadClient.listMessages()];
|
144
|
-
case 2:
|
145
|
-
pagedAsyncIterableIterator = _d.sent();
|
146
|
-
return [4 /*yield*/, pagedAsyncIterableIterator.next()];
|
147
|
-
case 3:
|
148
|
-
nextMessage = _d.sent();
|
149
|
-
_d.label = 4;
|
150
|
-
case 4:
|
151
|
-
if (!!nextMessage.done) return [3 /*break*/, 8];
|
152
|
-
chatMessage = nextMessage.value;
|
153
|
-
if (!(chatMessage.type !== ACSChatMessageType_1.default.Text)) return [3 /*break*/, 6];
|
154
|
-
return [4 /*yield*/, pagedAsyncIterableIterator.next()];
|
155
|
-
case 5:
|
156
|
-
nextMessage = _d.sent();
|
157
|
-
return [3 /*break*/, 4];
|
158
|
-
case 6:
|
159
|
-
omnichannelMessage = createOmnichannelMessage_1.default(chatMessage, {
|
160
|
-
liveChatVersion: LiveChatVersion_1.default.V2
|
161
|
-
});
|
162
|
-
messages.push(omnichannelMessage);
|
163
|
-
return [4 /*yield*/, pagedAsyncIterableIterator.next()];
|
164
|
-
case 7:
|
165
|
-
nextMessage = _d.sent();
|
166
|
-
return [3 /*break*/, 4];
|
167
|
-
case 8:
|
168
|
-
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.completeScenario(ACSClientEvent.GetMessages);
|
169
|
-
return [3 /*break*/, 10];
|
170
|
-
case 9:
|
171
|
-
error_3 = _d.sent();
|
172
|
-
exceptionDetails = {
|
173
|
-
errorObject: "" + error_3
|
174
|
-
};
|
175
|
-
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.failScenario(ACSClientEvent.GetMessages, {
|
176
|
-
ExceptionDetails: JSON.stringify(exceptionDetails)
|
177
|
-
});
|
178
|
-
throw new Error(ACSClientEvent.GetMessages);
|
179
|
-
case 10: return [2 /*return*/, messages];
|
180
|
-
}
|
181
|
-
});
|
182
|
-
});
|
183
|
-
};
|
184
|
-
ACSConversation.prototype.getParticipants = function () {
|
185
|
-
var _a, _b, _c;
|
186
|
-
return __awaiter(this, void 0, void 0, function () {
|
187
|
-
var participants, pagedAsyncIterableIterator, next, user, error_4, exceptionDetails;
|
188
|
-
return __generator(this, function (_d) {
|
189
|
-
switch (_d.label) {
|
190
|
-
case 0:
|
191
|
-
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.GetParticipants);
|
192
|
-
participants = [];
|
193
|
-
_d.label = 1;
|
194
|
-
case 1:
|
195
|
-
_d.trys.push([1, 7, , 8]);
|
196
|
-
return [4 /*yield*/, this.chatThreadClient.listParticipants()];
|
197
|
-
case 2:
|
198
|
-
pagedAsyncIterableIterator = _d.sent();
|
199
|
-
return [4 /*yield*/, pagedAsyncIterableIterator.next()];
|
200
|
-
case 3:
|
201
|
-
next = _d.sent();
|
202
|
-
_d.label = 4;
|
203
|
-
case 4:
|
204
|
-
if (!!next.done) return [3 /*break*/, 6];
|
205
|
-
user = next.value;
|
206
|
-
participants.push(user);
|
207
|
-
return [4 /*yield*/, pagedAsyncIterableIterator.next()];
|
208
|
-
case 5:
|
209
|
-
next = _d.sent();
|
210
|
-
return [3 /*break*/, 4];
|
211
|
-
case 6:
|
212
|
-
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.completeScenario(ACSClientEvent.GetParticipants);
|
213
|
-
return [3 /*break*/, 8];
|
214
|
-
case 7:
|
215
|
-
error_4 = _d.sent();
|
216
|
-
exceptionDetails = {
|
217
|
-
errorObject: "" + error_4
|
218
|
-
};
|
219
|
-
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.failScenario(ACSClientEvent.GetParticipants, {
|
220
|
-
ExceptionDetails: JSON.stringify(exceptionDetails)
|
221
|
-
});
|
222
|
-
throw new Error(ACSClientEvent.GetParticipants);
|
223
|
-
case 8: return [2 /*return*/, participants];
|
224
|
-
}
|
225
|
-
});
|
226
|
-
});
|
227
|
-
};
|
228
|
-
ACSConversation.prototype.registerOnNewMessage = function (onNewMessageCallback) {
|
229
|
-
var _a, _b, _c, _d, _e, _f;
|
230
|
-
return __awaiter(this, void 0, void 0, function () {
|
231
|
-
var isReceivingNotifications, postedMessageIds, pollForMessages_1, listener, error_5, exceptionDetails;
|
232
|
-
var _this = this;
|
233
|
-
return __generator(this, function (_g) {
|
234
|
-
switch (_g.label) {
|
235
|
-
case 0:
|
236
|
-
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.RegisterOnNewMessage);
|
237
|
-
isReceivingNotifications = false;
|
238
|
-
postedMessageIds = new Set();
|
239
|
-
_g.label = 1;
|
240
|
-
case 1:
|
241
|
-
_g.trys.push([1, 3, , 4]);
|
242
|
-
pollForMessages_1 = function (delay) { return __awaiter(_this, void 0, void 0, function () {
|
243
|
-
var messages, _i, _a, message, id, sender, customerMessageCondition, _b;
|
244
|
-
return __generator(this, function (_c) {
|
245
|
-
switch (_c.label) {
|
246
|
-
case 0:
|
247
|
-
if (isReceivingNotifications) {
|
248
|
-
return [2 /*return*/];
|
249
|
-
}
|
250
|
-
_c.label = 1;
|
251
|
-
case 1:
|
252
|
-
_c.trys.push([1, 3, , 4]);
|
253
|
-
return [4 /*yield*/, this.getMessages()];
|
254
|
-
case 2:
|
255
|
-
messages = _c.sent();
|
256
|
-
for (_i = 0, _a = messages.reverse(); _i < _a.length; _i++) {
|
257
|
-
message = _a[_i];
|
258
|
-
id = message.id, sender = message.sender;
|
259
|
-
customerMessageCondition = sender.displayName === ACSParticipantDisplayName_1.default.Customer;
|
260
|
-
// Filter out customer messages
|
261
|
-
if (customerMessageCondition) {
|
262
|
-
continue;
|
263
|
-
}
|
264
|
-
// Filter out duplicate messages
|
265
|
-
if (!postedMessageIds.has(id)) {
|
266
|
-
onNewMessageCallback(message);
|
267
|
-
postedMessageIds.add(id);
|
268
|
-
}
|
269
|
-
}
|
270
|
-
return [3 /*break*/, 4];
|
271
|
-
case 3:
|
272
|
-
_b = _c.sent();
|
273
|
-
return [3 /*break*/, 4];
|
274
|
-
case 4:
|
275
|
-
setTimeout(function () {
|
276
|
-
pollForMessages_1(delay);
|
277
|
-
}, delay);
|
278
|
-
return [2 /*return*/];
|
279
|
-
}
|
280
|
-
});
|
281
|
-
}); };
|
282
|
-
// Poll messages until WS established connection
|
283
|
-
return [4 /*yield*/, pollForMessages_1((_b = this.sessionInfo) === null || _b === void 0 ? void 0 : _b.pollingInterval)];
|
284
|
-
case 2:
|
285
|
-
// Poll messages until WS established connection
|
286
|
-
_g.sent();
|
287
|
-
listener = function (event) {
|
288
|
-
var _a;
|
289
|
-
isReceivingNotifications = true;
|
290
|
-
var id = event.id, sender = event.sender;
|
291
|
-
var customerMessageCondition = (sender.communicationUserId === ((_a = _this.sessionInfo) === null || _a === void 0 ? void 0 : _a.id));
|
292
|
-
var isChatMessageEditedEvent = Object.keys(event).includes("editedOn");
|
293
|
-
// Filter out customer messages
|
294
|
-
if (customerMessageCondition) {
|
295
|
-
return;
|
296
|
-
}
|
297
|
-
// Filter out duplicate messages
|
298
|
-
if (postedMessageIds.has(id) && !isChatMessageEditedEvent) {
|
299
|
-
return;
|
300
|
-
}
|
301
|
-
onNewMessageCallback(event);
|
302
|
-
postedMessageIds.add(id);
|
303
|
-
};
|
304
|
-
(_c = this.chatClient) === null || _c === void 0 ? void 0 : _c.on("chatMessageReceived", listener);
|
305
|
-
(_d = this.chatClient) === null || _d === void 0 ? void 0 : _d.on("chatMessageEdited", listener);
|
306
|
-
this.trackListener("chatMessageReceived", listener);
|
307
|
-
this.trackListener("chatMessageEdited", listener);
|
308
|
-
(_e = this.logger) === null || _e === void 0 ? void 0 : _e.completeScenario(ACSClientEvent.RegisterOnNewMessage);
|
309
|
-
return [3 /*break*/, 4];
|
310
|
-
case 3:
|
311
|
-
error_5 = _g.sent();
|
312
|
-
exceptionDetails = {
|
313
|
-
errorObject: "" + error_5
|
314
|
-
};
|
315
|
-
(_f = this.logger) === null || _f === void 0 ? void 0 : _f.failScenario(ACSClientEvent.RegisterOnNewMessage, {
|
316
|
-
ExceptionDetails: JSON.stringify(exceptionDetails)
|
317
|
-
});
|
318
|
-
throw new Error(ACSClientEvent.RegisterOnNewMessage);
|
319
|
-
case 4: return [2 /*return*/];
|
320
|
-
}
|
321
|
-
});
|
322
|
-
});
|
323
|
-
};
|
324
|
-
ACSConversation.prototype.registerOnThreadUpdate = function (onThreadUpdateCallback) {
|
325
|
-
var _a, _b, _c, _d;
|
326
|
-
return __awaiter(this, void 0, void 0, function () {
|
327
|
-
var listener;
|
328
|
-
return __generator(this, function (_e) {
|
329
|
-
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.RegisterOnThreadUpdate);
|
330
|
-
try {
|
331
|
-
listener = function (event) {
|
332
|
-
onThreadUpdateCallback(event);
|
333
|
-
};
|
334
|
-
(_b = this.chatClient) === null || _b === void 0 ? void 0 : _b.on("participantsRemoved", listener);
|
335
|
-
this.trackListener("participantsRemoved", listener);
|
336
|
-
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.completeScenario(ACSClientEvent.RegisterOnThreadUpdate);
|
337
|
-
}
|
338
|
-
catch (error) {
|
339
|
-
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.failScenario(ACSClientEvent.RegisterOnThreadUpdate);
|
340
|
-
}
|
341
|
-
return [2 /*return*/];
|
342
|
-
});
|
343
|
-
});
|
344
|
-
};
|
345
|
-
ACSConversation.prototype.onTypingEvent = function (onTypingEventCallback) {
|
346
|
-
var _a, _b, _c, _d;
|
347
|
-
return __awaiter(this, void 0, void 0, function () {
|
348
|
-
var listener;
|
349
|
-
return __generator(this, function (_e) {
|
350
|
-
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.OnTypingEvent);
|
351
|
-
try {
|
352
|
-
listener = function (event) {
|
353
|
-
var sender = event.sender, recipient = event.recipient;
|
354
|
-
// Ignore participant's own typing events
|
355
|
-
if (sender.communicationUserId === recipient.communicationUserId) { // eslint-disable-line @typescript-eslint/no-explicit-any
|
356
|
-
return;
|
357
|
-
}
|
358
|
-
onTypingEventCallback(event);
|
359
|
-
};
|
360
|
-
(_b = this.chatClient) === null || _b === void 0 ? void 0 : _b.on("typingIndicatorReceived", listener);
|
361
|
-
this.trackListener("typingIndicatorReceived", listener);
|
362
|
-
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.completeScenario(ACSClientEvent.OnTypingEvent);
|
363
|
-
}
|
364
|
-
catch (error) {
|
365
|
-
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.failScenario(ACSClientEvent.OnTypingEvent);
|
366
|
-
}
|
367
|
-
return [2 /*return*/];
|
368
|
-
});
|
369
|
-
});
|
370
|
-
};
|
371
|
-
ACSConversation.prototype.sendMessage = function (message) {
|
372
|
-
var _a, _b, _c, _d;
|
373
|
-
return __awaiter(this, void 0, void 0, function () {
|
374
|
-
var sendMessageRequest, sendMessageOptions, error_6, exceptionDetails;
|
375
|
-
return __generator(this, function (_e) {
|
376
|
-
switch (_e.label) {
|
377
|
-
case 0:
|
378
|
-
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.SendMessage);
|
379
|
-
if (!message.metadata) {
|
380
|
-
message.metadata = {};
|
381
|
-
}
|
382
|
-
sendMessageRequest = {
|
383
|
-
content: message.content,
|
384
|
-
};
|
385
|
-
sendMessageOptions = {
|
386
|
-
senderDisplayName: ACSParticipantDisplayName_1.default.Customer,
|
387
|
-
metadata: __assign({ deliveryMode: DeliveryMode_1.default.Bridged, tags: MessageTags_1.defaultMessageTags.join(',') }, message.metadata)
|
388
|
-
};
|
389
|
-
_e.label = 1;
|
390
|
-
case 1:
|
391
|
-
_e.trys.push([1, 3, , 4]);
|
392
|
-
return [4 /*yield*/, ((_b = this.chatThreadClient) === null || _b === void 0 ? void 0 : _b.sendMessage(sendMessageRequest, sendMessageOptions))];
|
393
|
-
case 2:
|
394
|
-
_e.sent();
|
395
|
-
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.completeScenario(ACSClientEvent.SendMessage);
|
396
|
-
return [3 /*break*/, 4];
|
397
|
-
case 3:
|
398
|
-
error_6 = _e.sent();
|
399
|
-
exceptionDetails = {
|
400
|
-
response: 'SendMessageFailed',
|
401
|
-
errorObject: "" + error_6
|
402
|
-
};
|
403
|
-
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.failScenario(ACSClientEvent.SendMessage, {
|
404
|
-
ExceptionDetails: JSON.stringify(exceptionDetails)
|
405
|
-
});
|
406
|
-
throw new Error('SendMessageFailed');
|
407
|
-
case 4: return [2 /*return*/];
|
408
|
-
}
|
409
|
-
});
|
410
|
-
});
|
411
|
-
};
|
412
|
-
ACSConversation.prototype.sendTyping = function () {
|
413
|
-
var _a, _b, _c, _d;
|
414
|
-
return __awaiter(this, void 0, void 0, function () {
|
415
|
-
var error_7, exceptionDetails;
|
416
|
-
return __generator(this, function (_e) {
|
417
|
-
switch (_e.label) {
|
418
|
-
case 0:
|
419
|
-
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.SendTyping);
|
420
|
-
_e.label = 1;
|
421
|
-
case 1:
|
422
|
-
_e.trys.push([1, 3, , 4]);
|
423
|
-
return [4 /*yield*/, ((_b = this.chatThreadClient) === null || _b === void 0 ? void 0 : _b.sendTypingNotification())];
|
424
|
-
case 2:
|
425
|
-
_e.sent();
|
426
|
-
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.completeScenario(ACSClientEvent.SendTyping);
|
427
|
-
return [3 /*break*/, 4];
|
428
|
-
case 3:
|
429
|
-
error_7 = _e.sent();
|
430
|
-
exceptionDetails = {
|
431
|
-
response: 'SendTypingFailed',
|
432
|
-
errorObject: "" + error_7
|
433
|
-
};
|
434
|
-
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.failScenario(ACSClientEvent.SendTyping, {
|
435
|
-
ExceptionDetails: JSON.stringify(exceptionDetails)
|
436
|
-
});
|
437
|
-
throw new Error('SendTypingFailed');
|
438
|
-
case 4: return [2 /*return*/];
|
439
|
-
}
|
440
|
-
});
|
441
|
-
});
|
442
|
-
};
|
443
|
-
ACSConversation.prototype.sendFileMessage = function () {
|
444
|
-
return __awaiter(this, void 0, void 0, function () {
|
445
|
-
return __generator(this, function (_a) {
|
446
|
-
return [2 /*return*/, undefined];
|
447
|
-
});
|
448
|
-
});
|
449
|
-
};
|
450
|
-
ACSConversation.prototype.sendFileData = function () {
|
451
|
-
return __awaiter(this, void 0, void 0, function () {
|
452
|
-
return __generator(this, function (_a) {
|
453
|
-
return [2 /*return*/, undefined];
|
454
|
-
});
|
455
|
-
});
|
456
|
-
};
|
457
|
-
ACSConversation.prototype.uploadFile = function () {
|
458
|
-
return __awaiter(this, void 0, void 0, function () {
|
459
|
-
return __generator(this, function (_a) {
|
460
|
-
return [2 /*return*/, undefined];
|
461
|
-
});
|
462
|
-
});
|
463
|
-
};
|
464
|
-
ACSConversation.prototype.downloadFile = function () {
|
465
|
-
return __awaiter(this, void 0, void 0, function () {
|
466
|
-
return __generator(this, function (_a) {
|
467
|
-
return [2 /*return*/, undefined];
|
468
|
-
});
|
469
|
-
});
|
470
|
-
};
|
471
|
-
ACSConversation.prototype.disconnect = function () {
|
472
|
-
var _a, _b, _c;
|
473
|
-
return __awaiter(this, void 0, void 0, function () {
|
474
|
-
var _loop_1, _i, _d, _e, event_1, listeners;
|
475
|
-
var _this = this;
|
476
|
-
return __generator(this, function (_f) {
|
477
|
-
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.Disconnect);
|
478
|
-
try {
|
479
|
-
_loop_1 = function (event_1, listeners) {
|
480
|
-
listeners.forEach(function (listener) {
|
481
|
-
_this.chatClient.off(event_1, listener); // eslint-disable-line @typescript-eslint/no-explicit-any
|
482
|
-
});
|
483
|
-
};
|
484
|
-
for (_i = 0, _d = Object.entries(this.eventListeners); _i < _d.length; _i++) {
|
485
|
-
_e = _d[_i], event_1 = _e[0], listeners = _e[1];
|
486
|
-
_loop_1(event_1, listeners);
|
487
|
-
}
|
488
|
-
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.completeScenario(ACSClientEvent.Disconnect);
|
489
|
-
}
|
490
|
-
catch (_g) {
|
491
|
-
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.failScenario(ACSClientEvent.Disconnect);
|
492
|
-
}
|
493
|
-
return [2 /*return*/];
|
494
|
-
});
|
495
|
-
});
|
496
|
-
};
|
497
|
-
ACSConversation.prototype.createParticipantsMapping = function () {
|
498
|
-
return __awaiter(this, void 0, void 0, function () {
|
499
|
-
var participants, participantsMapping, _i, participants_1, participant, id;
|
500
|
-
var _a;
|
501
|
-
return __generator(this, function (_b) {
|
502
|
-
switch (_b.label) {
|
503
|
-
case 0: return [4 /*yield*/, this.getParticipants()];
|
504
|
-
case 1:
|
505
|
-
participants = _b.sent();
|
506
|
-
participantsMapping = {};
|
507
|
-
for (_i = 0, participants_1 = participants; _i < participants_1.length; _i++) {
|
508
|
-
participant = participants_1[_i];
|
509
|
-
id = participant.id;
|
510
|
-
if (!Object.keys(participantsMapping).includes(id.communicationUserId)) {
|
511
|
-
Object.assign(participantsMapping, (_a = {}, _a[id.communicationUserId] = participant, _a));
|
512
|
-
}
|
513
|
-
}
|
514
|
-
return [2 /*return*/, participantsMapping];
|
515
|
-
}
|
516
|
-
});
|
517
|
-
});
|
518
|
-
};
|
519
|
-
ACSConversation.prototype.trackListener = function (event, listener) {
|
520
|
-
if (!(event in this.eventListeners)) {
|
521
|
-
this.eventListeners[event] = [];
|
522
|
-
}
|
523
|
-
this.eventListeners[event].push(listener);
|
524
|
-
};
|
525
|
-
return ACSConversation;
|
526
|
-
}());
|
527
|
-
exports.ACSConversation = ACSConversation;
|
528
|
-
var ACSClient = /** @class */ (function () {
|
529
|
-
function ACSClient(logger) {
|
530
|
-
if (logger === void 0) { logger = null; }
|
531
|
-
this.logger = null;
|
532
|
-
this.tokenCredential = null;
|
533
|
-
this.chatClient = null;
|
534
|
-
this.logger = logger;
|
535
|
-
}
|
536
|
-
ACSClient.prototype.initialize = function (acsClientConfig) {
|
537
|
-
var _a, _b, _c, _d;
|
538
|
-
return __awaiter(this, void 0, void 0, function () {
|
539
|
-
var tokenRefresher, exceptionDetails, exceptionDetails;
|
540
|
-
var _this = this;
|
541
|
-
return __generator(this, function (_e) {
|
542
|
-
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.InitializeACSClient);
|
543
|
-
tokenRefresher = function () { return __awaiter(_this, void 0, void 0, function () {
|
544
|
-
var token;
|
545
|
-
return __generator(this, function (_a) {
|
546
|
-
switch (_a.label) {
|
547
|
-
case 0:
|
548
|
-
if (!acsClientConfig.tokenRefresher) return [3 /*break*/, 2];
|
549
|
-
return [4 /*yield*/, acsClientConfig.tokenRefresher()];
|
550
|
-
case 1:
|
551
|
-
token = _a.sent();
|
552
|
-
return [2 /*return*/, token];
|
553
|
-
case 2: return [2 /*return*/, acsClientConfig.token];
|
554
|
-
}
|
555
|
-
});
|
556
|
-
}); };
|
557
|
-
try {
|
558
|
-
this.tokenCredential = new communication_common_1.AzureCommunicationTokenCredential({
|
559
|
-
token: acsClientConfig.token,
|
560
|
-
tokenRefresher: tokenRefresher,
|
561
|
-
refreshProactively: true // Flag to whether refresh token 10 mins it expires
|
562
|
-
});
|
563
|
-
}
|
564
|
-
catch (error) {
|
565
|
-
exceptionDetails = {
|
566
|
-
response: 'CreateTokenCredentialFailure',
|
567
|
-
errorObject: "" + error
|
568
|
-
};
|
569
|
-
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.failScenario(ACSClientEvent.InitializeACSClient, {
|
570
|
-
ExceptionDetails: JSON.stringify(exceptionDetails)
|
571
|
-
});
|
572
|
-
throw new Error('CreateTokenCredentialFailed');
|
573
|
-
}
|
574
|
-
try {
|
575
|
-
this.chatClient = new communication_chat_1.ChatClient(acsClientConfig.environmentUrl, this.tokenCredential);
|
576
|
-
}
|
577
|
-
catch (error) {
|
578
|
-
exceptionDetails = {
|
579
|
-
response: 'CreateChatClientFailure',
|
580
|
-
errorObject: "" + error
|
581
|
-
};
|
582
|
-
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.failScenario(ACSClientEvent.InitializeACSClient, {
|
583
|
-
ExceptionDetails: JSON.stringify(exceptionDetails)
|
584
|
-
});
|
585
|
-
throw new Error('CreateChatClientFailed');
|
586
|
-
}
|
587
|
-
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.completeScenario(ACSClientEvent.InitializeACSClient);
|
588
|
-
return [2 /*return*/];
|
589
|
-
});
|
590
|
-
});
|
591
|
-
};
|
592
|
-
ACSClient.prototype.joinConversation = function (sessionInfo) {
|
593
|
-
return __awaiter(this, void 0, void 0, function () {
|
594
|
-
var conversation;
|
595
|
-
return __generator(this, function (_a) {
|
596
|
-
switch (_a.label) {
|
597
|
-
case 0:
|
598
|
-
conversation = new ACSConversation(this.tokenCredential, this.chatClient, this.logger);
|
599
|
-
return [4 /*yield*/, conversation.initialize(sessionInfo)];
|
600
|
-
case 1:
|
601
|
-
_a.sent();
|
602
|
-
return [2 /*return*/, conversation];
|
603
|
-
}
|
604
|
-
});
|
605
|
-
});
|
606
|
-
};
|
607
|
-
ACSClient.prototype.getChatClient = function () {
|
608
|
-
return this.chatClient;
|
609
|
-
};
|
610
|
-
return ACSClient;
|
611
|
-
}());
|
612
|
-
exports.default = ACSClient;
|
1
|
+
"use strict";
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
3
|
+
__assign = Object.assign || function(t) {
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
+
s = arguments[i];
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
+
t[p] = s[p];
|
8
|
+
}
|
9
|
+
return t;
|
10
|
+
};
|
11
|
+
return __assign.apply(this, arguments);
|
12
|
+
};
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
20
|
+
});
|
21
|
+
};
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
26
|
+
function step(op) {
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
28
|
+
while (_) try {
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
31
|
+
switch (op[0]) {
|
32
|
+
case 0: case 1: t = op; break;
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
36
|
+
default:
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
41
|
+
if (t[2]) _.ops.pop();
|
42
|
+
_.trys.pop(); continue;
|
43
|
+
}
|
44
|
+
op = body.call(thisArg, _);
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
47
|
+
}
|
48
|
+
};
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
50
|
+
exports.ACSConversation = void 0;
|
51
|
+
var ACSChatMessageType_1 = require("./ACSChatMessageType");
|
52
|
+
var ACSParticipantDisplayName_1 = require("./ACSParticipantDisplayName");
|
53
|
+
var communication_chat_1 = require("@azure/communication-chat");
|
54
|
+
var communication_common_1 = require("@azure/communication-common");
|
55
|
+
var createOmnichannelMessage_1 = require("../../utils/createOmnichannelMessage");
|
56
|
+
var MessageTags_1 = require("./MessageTags");
|
57
|
+
var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
|
58
|
+
var LiveChatVersion_1 = require("../LiveChatVersion");
|
59
|
+
var ACSClientEvent;
|
60
|
+
(function (ACSClientEvent) {
|
61
|
+
ACSClientEvent["InitializeACSClient"] = "InitializeACSClient";
|
62
|
+
ACSClientEvent["InitializeACSConversation"] = "InitializeACSConversation";
|
63
|
+
ACSClientEvent["GetParticipants"] = "GetParticipants";
|
64
|
+
ACSClientEvent["RegisterOnNewMessage"] = "RegisterOnNewMessage";
|
65
|
+
ACSClientEvent["RegisterOnThreadUpdate"] = "RegisterOnThreadUpdate";
|
66
|
+
ACSClientEvent["OnTypingEvent"] = "OnTypingEvent";
|
67
|
+
ACSClientEvent["GetMessages"] = "GetMessages";
|
68
|
+
ACSClientEvent["SendMessage"] = "SendMessage";
|
69
|
+
ACSClientEvent["SendTyping"] = "SendTyping";
|
70
|
+
ACSClientEvent["Disconnect"] = "Disconnect";
|
71
|
+
})(ACSClientEvent || (ACSClientEvent = {}));
|
72
|
+
var ACSConversation = /** @class */ (function () {
|
73
|
+
function ACSConversation(tokenCredential, chatClient, logger) {
|
74
|
+
if (logger === void 0) { logger = null; }
|
75
|
+
this.logger = null;
|
76
|
+
this.logger = logger;
|
77
|
+
this.tokenCredential = tokenCredential;
|
78
|
+
this.chatClient = chatClient;
|
79
|
+
this.eventListeners = {};
|
80
|
+
}
|
81
|
+
ACSConversation.prototype.initialize = function (sessionInfo) {
|
82
|
+
var _a, _b, _c, _d, _e;
|
83
|
+
return __awaiter(this, void 0, void 0, function () {
|
84
|
+
var _f, error_1, exceptionDetails, error_2, exceptionDetails;
|
85
|
+
return __generator(this, function (_g) {
|
86
|
+
switch (_g.label) {
|
87
|
+
case 0:
|
88
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.InitializeACSConversation);
|
89
|
+
this.sessionInfo = sessionInfo;
|
90
|
+
_g.label = 1;
|
91
|
+
case 1:
|
92
|
+
_g.trys.push([1, 3, , 4]);
|
93
|
+
_f = this;
|
94
|
+
return [4 /*yield*/, ((_b = this.chatClient) === null || _b === void 0 ? void 0 : _b.getChatThreadClient(sessionInfo.threadId))];
|
95
|
+
case 2:
|
96
|
+
_f.chatThreadClient = _g.sent();
|
97
|
+
return [3 /*break*/, 4];
|
98
|
+
case 3:
|
99
|
+
error_1 = _g.sent();
|
100
|
+
exceptionDetails = {
|
101
|
+
response: 'ChatClientGetChatThreadClientFailure',
|
102
|
+
errorObject: "" + error_1
|
103
|
+
};
|
104
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.failScenario(ACSClientEvent.InitializeACSConversation, {
|
105
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
106
|
+
});
|
107
|
+
throw new Error("GetChatThreadClientFailed");
|
108
|
+
case 4:
|
109
|
+
_g.trys.push([4, 6, , 7]);
|
110
|
+
return [4 /*yield*/, this.chatClient.startRealtimeNotifications()];
|
111
|
+
case 5:
|
112
|
+
_g.sent();
|
113
|
+
return [3 /*break*/, 7];
|
114
|
+
case 6:
|
115
|
+
error_2 = _g.sent();
|
116
|
+
exceptionDetails = {
|
117
|
+
response: 'StartRealtimeNotificationsFailed',
|
118
|
+
errorObject: "" + error_2
|
119
|
+
};
|
120
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.failScenario(ACSClientEvent.InitializeACSConversation, {
|
121
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
122
|
+
});
|
123
|
+
throw new Error(exceptionDetails.response);
|
124
|
+
case 7:
|
125
|
+
(_e = this.logger) === null || _e === void 0 ? void 0 : _e.completeScenario(ACSClientEvent.InitializeACSConversation);
|
126
|
+
return [2 /*return*/];
|
127
|
+
}
|
128
|
+
});
|
129
|
+
});
|
130
|
+
};
|
131
|
+
ACSConversation.prototype.getMessages = function () {
|
132
|
+
var _a, _b, _c;
|
133
|
+
return __awaiter(this, void 0, void 0, function () {
|
134
|
+
var messages, pagedAsyncIterableIterator, nextMessage, chatMessage, omnichannelMessage, error_3, exceptionDetails;
|
135
|
+
return __generator(this, function (_d) {
|
136
|
+
switch (_d.label) {
|
137
|
+
case 0:
|
138
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.GetMessages);
|
139
|
+
messages = [];
|
140
|
+
_d.label = 1;
|
141
|
+
case 1:
|
142
|
+
_d.trys.push([1, 9, , 10]);
|
143
|
+
return [4 /*yield*/, this.chatThreadClient.listMessages()];
|
144
|
+
case 2:
|
145
|
+
pagedAsyncIterableIterator = _d.sent();
|
146
|
+
return [4 /*yield*/, pagedAsyncIterableIterator.next()];
|
147
|
+
case 3:
|
148
|
+
nextMessage = _d.sent();
|
149
|
+
_d.label = 4;
|
150
|
+
case 4:
|
151
|
+
if (!!nextMessage.done) return [3 /*break*/, 8];
|
152
|
+
chatMessage = nextMessage.value;
|
153
|
+
if (!(chatMessage.type !== ACSChatMessageType_1.default.Text)) return [3 /*break*/, 6];
|
154
|
+
return [4 /*yield*/, pagedAsyncIterableIterator.next()];
|
155
|
+
case 5:
|
156
|
+
nextMessage = _d.sent();
|
157
|
+
return [3 /*break*/, 4];
|
158
|
+
case 6:
|
159
|
+
omnichannelMessage = createOmnichannelMessage_1.default(chatMessage, {
|
160
|
+
liveChatVersion: LiveChatVersion_1.default.V2
|
161
|
+
});
|
162
|
+
messages.push(omnichannelMessage);
|
163
|
+
return [4 /*yield*/, pagedAsyncIterableIterator.next()];
|
164
|
+
case 7:
|
165
|
+
nextMessage = _d.sent();
|
166
|
+
return [3 /*break*/, 4];
|
167
|
+
case 8:
|
168
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.completeScenario(ACSClientEvent.GetMessages);
|
169
|
+
return [3 /*break*/, 10];
|
170
|
+
case 9:
|
171
|
+
error_3 = _d.sent();
|
172
|
+
exceptionDetails = {
|
173
|
+
errorObject: "" + error_3
|
174
|
+
};
|
175
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.failScenario(ACSClientEvent.GetMessages, {
|
176
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
177
|
+
});
|
178
|
+
throw new Error(ACSClientEvent.GetMessages);
|
179
|
+
case 10: return [2 /*return*/, messages];
|
180
|
+
}
|
181
|
+
});
|
182
|
+
});
|
183
|
+
};
|
184
|
+
ACSConversation.prototype.getParticipants = function () {
|
185
|
+
var _a, _b, _c;
|
186
|
+
return __awaiter(this, void 0, void 0, function () {
|
187
|
+
var participants, pagedAsyncIterableIterator, next, user, error_4, exceptionDetails;
|
188
|
+
return __generator(this, function (_d) {
|
189
|
+
switch (_d.label) {
|
190
|
+
case 0:
|
191
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.GetParticipants);
|
192
|
+
participants = [];
|
193
|
+
_d.label = 1;
|
194
|
+
case 1:
|
195
|
+
_d.trys.push([1, 7, , 8]);
|
196
|
+
return [4 /*yield*/, this.chatThreadClient.listParticipants()];
|
197
|
+
case 2:
|
198
|
+
pagedAsyncIterableIterator = _d.sent();
|
199
|
+
return [4 /*yield*/, pagedAsyncIterableIterator.next()];
|
200
|
+
case 3:
|
201
|
+
next = _d.sent();
|
202
|
+
_d.label = 4;
|
203
|
+
case 4:
|
204
|
+
if (!!next.done) return [3 /*break*/, 6];
|
205
|
+
user = next.value;
|
206
|
+
participants.push(user);
|
207
|
+
return [4 /*yield*/, pagedAsyncIterableIterator.next()];
|
208
|
+
case 5:
|
209
|
+
next = _d.sent();
|
210
|
+
return [3 /*break*/, 4];
|
211
|
+
case 6:
|
212
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.completeScenario(ACSClientEvent.GetParticipants);
|
213
|
+
return [3 /*break*/, 8];
|
214
|
+
case 7:
|
215
|
+
error_4 = _d.sent();
|
216
|
+
exceptionDetails = {
|
217
|
+
errorObject: "" + error_4
|
218
|
+
};
|
219
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.failScenario(ACSClientEvent.GetParticipants, {
|
220
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
221
|
+
});
|
222
|
+
throw new Error(ACSClientEvent.GetParticipants);
|
223
|
+
case 8: return [2 /*return*/, participants];
|
224
|
+
}
|
225
|
+
});
|
226
|
+
});
|
227
|
+
};
|
228
|
+
ACSConversation.prototype.registerOnNewMessage = function (onNewMessageCallback) {
|
229
|
+
var _a, _b, _c, _d, _e, _f;
|
230
|
+
return __awaiter(this, void 0, void 0, function () {
|
231
|
+
var isReceivingNotifications, postedMessageIds, pollForMessages_1, listener, error_5, exceptionDetails;
|
232
|
+
var _this = this;
|
233
|
+
return __generator(this, function (_g) {
|
234
|
+
switch (_g.label) {
|
235
|
+
case 0:
|
236
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.RegisterOnNewMessage);
|
237
|
+
isReceivingNotifications = false;
|
238
|
+
postedMessageIds = new Set();
|
239
|
+
_g.label = 1;
|
240
|
+
case 1:
|
241
|
+
_g.trys.push([1, 3, , 4]);
|
242
|
+
pollForMessages_1 = function (delay) { return __awaiter(_this, void 0, void 0, function () {
|
243
|
+
var messages, _i, _a, message, id, sender, customerMessageCondition, _b;
|
244
|
+
return __generator(this, function (_c) {
|
245
|
+
switch (_c.label) {
|
246
|
+
case 0:
|
247
|
+
if (isReceivingNotifications) {
|
248
|
+
return [2 /*return*/];
|
249
|
+
}
|
250
|
+
_c.label = 1;
|
251
|
+
case 1:
|
252
|
+
_c.trys.push([1, 3, , 4]);
|
253
|
+
return [4 /*yield*/, this.getMessages()];
|
254
|
+
case 2:
|
255
|
+
messages = _c.sent();
|
256
|
+
for (_i = 0, _a = messages.reverse(); _i < _a.length; _i++) {
|
257
|
+
message = _a[_i];
|
258
|
+
id = message.id, sender = message.sender;
|
259
|
+
customerMessageCondition = sender.displayName === ACSParticipantDisplayName_1.default.Customer;
|
260
|
+
// Filter out customer messages
|
261
|
+
if (customerMessageCondition) {
|
262
|
+
continue;
|
263
|
+
}
|
264
|
+
// Filter out duplicate messages
|
265
|
+
if (!postedMessageIds.has(id)) {
|
266
|
+
onNewMessageCallback(message);
|
267
|
+
postedMessageIds.add(id);
|
268
|
+
}
|
269
|
+
}
|
270
|
+
return [3 /*break*/, 4];
|
271
|
+
case 3:
|
272
|
+
_b = _c.sent();
|
273
|
+
return [3 /*break*/, 4];
|
274
|
+
case 4:
|
275
|
+
setTimeout(function () {
|
276
|
+
pollForMessages_1(delay);
|
277
|
+
}, delay);
|
278
|
+
return [2 /*return*/];
|
279
|
+
}
|
280
|
+
});
|
281
|
+
}); };
|
282
|
+
// Poll messages until WS established connection
|
283
|
+
return [4 /*yield*/, pollForMessages_1((_b = this.sessionInfo) === null || _b === void 0 ? void 0 : _b.pollingInterval)];
|
284
|
+
case 2:
|
285
|
+
// Poll messages until WS established connection
|
286
|
+
_g.sent();
|
287
|
+
listener = function (event) {
|
288
|
+
var _a;
|
289
|
+
isReceivingNotifications = true;
|
290
|
+
var id = event.id, sender = event.sender;
|
291
|
+
var customerMessageCondition = (sender.communicationUserId === ((_a = _this.sessionInfo) === null || _a === void 0 ? void 0 : _a.id));
|
292
|
+
var isChatMessageEditedEvent = Object.keys(event).includes("editedOn");
|
293
|
+
// Filter out customer messages
|
294
|
+
if (customerMessageCondition) {
|
295
|
+
return;
|
296
|
+
}
|
297
|
+
// Filter out duplicate messages
|
298
|
+
if (postedMessageIds.has(id) && !isChatMessageEditedEvent) {
|
299
|
+
return;
|
300
|
+
}
|
301
|
+
onNewMessageCallback(event);
|
302
|
+
postedMessageIds.add(id);
|
303
|
+
};
|
304
|
+
(_c = this.chatClient) === null || _c === void 0 ? void 0 : _c.on("chatMessageReceived", listener);
|
305
|
+
(_d = this.chatClient) === null || _d === void 0 ? void 0 : _d.on("chatMessageEdited", listener);
|
306
|
+
this.trackListener("chatMessageReceived", listener);
|
307
|
+
this.trackListener("chatMessageEdited", listener);
|
308
|
+
(_e = this.logger) === null || _e === void 0 ? void 0 : _e.completeScenario(ACSClientEvent.RegisterOnNewMessage);
|
309
|
+
return [3 /*break*/, 4];
|
310
|
+
case 3:
|
311
|
+
error_5 = _g.sent();
|
312
|
+
exceptionDetails = {
|
313
|
+
errorObject: "" + error_5
|
314
|
+
};
|
315
|
+
(_f = this.logger) === null || _f === void 0 ? void 0 : _f.failScenario(ACSClientEvent.RegisterOnNewMessage, {
|
316
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
317
|
+
});
|
318
|
+
throw new Error(ACSClientEvent.RegisterOnNewMessage);
|
319
|
+
case 4: return [2 /*return*/];
|
320
|
+
}
|
321
|
+
});
|
322
|
+
});
|
323
|
+
};
|
324
|
+
ACSConversation.prototype.registerOnThreadUpdate = function (onThreadUpdateCallback) {
|
325
|
+
var _a, _b, _c, _d;
|
326
|
+
return __awaiter(this, void 0, void 0, function () {
|
327
|
+
var listener;
|
328
|
+
return __generator(this, function (_e) {
|
329
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.RegisterOnThreadUpdate);
|
330
|
+
try {
|
331
|
+
listener = function (event) {
|
332
|
+
onThreadUpdateCallback(event);
|
333
|
+
};
|
334
|
+
(_b = this.chatClient) === null || _b === void 0 ? void 0 : _b.on("participantsRemoved", listener);
|
335
|
+
this.trackListener("participantsRemoved", listener);
|
336
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.completeScenario(ACSClientEvent.RegisterOnThreadUpdate);
|
337
|
+
}
|
338
|
+
catch (error) {
|
339
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.failScenario(ACSClientEvent.RegisterOnThreadUpdate);
|
340
|
+
}
|
341
|
+
return [2 /*return*/];
|
342
|
+
});
|
343
|
+
});
|
344
|
+
};
|
345
|
+
ACSConversation.prototype.onTypingEvent = function (onTypingEventCallback) {
|
346
|
+
var _a, _b, _c, _d;
|
347
|
+
return __awaiter(this, void 0, void 0, function () {
|
348
|
+
var listener;
|
349
|
+
return __generator(this, function (_e) {
|
350
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.OnTypingEvent);
|
351
|
+
try {
|
352
|
+
listener = function (event) {
|
353
|
+
var sender = event.sender, recipient = event.recipient;
|
354
|
+
// Ignore participant's own typing events
|
355
|
+
if (sender.communicationUserId === recipient.communicationUserId) { // eslint-disable-line @typescript-eslint/no-explicit-any
|
356
|
+
return;
|
357
|
+
}
|
358
|
+
onTypingEventCallback(event);
|
359
|
+
};
|
360
|
+
(_b = this.chatClient) === null || _b === void 0 ? void 0 : _b.on("typingIndicatorReceived", listener);
|
361
|
+
this.trackListener("typingIndicatorReceived", listener);
|
362
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.completeScenario(ACSClientEvent.OnTypingEvent);
|
363
|
+
}
|
364
|
+
catch (error) {
|
365
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.failScenario(ACSClientEvent.OnTypingEvent);
|
366
|
+
}
|
367
|
+
return [2 /*return*/];
|
368
|
+
});
|
369
|
+
});
|
370
|
+
};
|
371
|
+
ACSConversation.prototype.sendMessage = function (message) {
|
372
|
+
var _a, _b, _c, _d;
|
373
|
+
return __awaiter(this, void 0, void 0, function () {
|
374
|
+
var sendMessageRequest, sendMessageOptions, error_6, exceptionDetails;
|
375
|
+
return __generator(this, function (_e) {
|
376
|
+
switch (_e.label) {
|
377
|
+
case 0:
|
378
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.SendMessage);
|
379
|
+
if (!message.metadata) {
|
380
|
+
message.metadata = {};
|
381
|
+
}
|
382
|
+
sendMessageRequest = {
|
383
|
+
content: message.content,
|
384
|
+
};
|
385
|
+
sendMessageOptions = {
|
386
|
+
senderDisplayName: ACSParticipantDisplayName_1.default.Customer,
|
387
|
+
metadata: __assign({ deliveryMode: DeliveryMode_1.default.Bridged, tags: MessageTags_1.defaultMessageTags.join(',') }, message.metadata)
|
388
|
+
};
|
389
|
+
_e.label = 1;
|
390
|
+
case 1:
|
391
|
+
_e.trys.push([1, 3, , 4]);
|
392
|
+
return [4 /*yield*/, ((_b = this.chatThreadClient) === null || _b === void 0 ? void 0 : _b.sendMessage(sendMessageRequest, sendMessageOptions))];
|
393
|
+
case 2:
|
394
|
+
_e.sent();
|
395
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.completeScenario(ACSClientEvent.SendMessage);
|
396
|
+
return [3 /*break*/, 4];
|
397
|
+
case 3:
|
398
|
+
error_6 = _e.sent();
|
399
|
+
exceptionDetails = {
|
400
|
+
response: 'SendMessageFailed',
|
401
|
+
errorObject: "" + error_6
|
402
|
+
};
|
403
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.failScenario(ACSClientEvent.SendMessage, {
|
404
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
405
|
+
});
|
406
|
+
throw new Error('SendMessageFailed');
|
407
|
+
case 4: return [2 /*return*/];
|
408
|
+
}
|
409
|
+
});
|
410
|
+
});
|
411
|
+
};
|
412
|
+
ACSConversation.prototype.sendTyping = function () {
|
413
|
+
var _a, _b, _c, _d;
|
414
|
+
return __awaiter(this, void 0, void 0, function () {
|
415
|
+
var error_7, exceptionDetails;
|
416
|
+
return __generator(this, function (_e) {
|
417
|
+
switch (_e.label) {
|
418
|
+
case 0:
|
419
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.SendTyping);
|
420
|
+
_e.label = 1;
|
421
|
+
case 1:
|
422
|
+
_e.trys.push([1, 3, , 4]);
|
423
|
+
return [4 /*yield*/, ((_b = this.chatThreadClient) === null || _b === void 0 ? void 0 : _b.sendTypingNotification())];
|
424
|
+
case 2:
|
425
|
+
_e.sent();
|
426
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.completeScenario(ACSClientEvent.SendTyping);
|
427
|
+
return [3 /*break*/, 4];
|
428
|
+
case 3:
|
429
|
+
error_7 = _e.sent();
|
430
|
+
exceptionDetails = {
|
431
|
+
response: 'SendTypingFailed',
|
432
|
+
errorObject: "" + error_7
|
433
|
+
};
|
434
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.failScenario(ACSClientEvent.SendTyping, {
|
435
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
436
|
+
});
|
437
|
+
throw new Error('SendTypingFailed');
|
438
|
+
case 4: return [2 /*return*/];
|
439
|
+
}
|
440
|
+
});
|
441
|
+
});
|
442
|
+
};
|
443
|
+
ACSConversation.prototype.sendFileMessage = function () {
|
444
|
+
return __awaiter(this, void 0, void 0, function () {
|
445
|
+
return __generator(this, function (_a) {
|
446
|
+
return [2 /*return*/, undefined];
|
447
|
+
});
|
448
|
+
});
|
449
|
+
};
|
450
|
+
ACSConversation.prototype.sendFileData = function () {
|
451
|
+
return __awaiter(this, void 0, void 0, function () {
|
452
|
+
return __generator(this, function (_a) {
|
453
|
+
return [2 /*return*/, undefined];
|
454
|
+
});
|
455
|
+
});
|
456
|
+
};
|
457
|
+
ACSConversation.prototype.uploadFile = function () {
|
458
|
+
return __awaiter(this, void 0, void 0, function () {
|
459
|
+
return __generator(this, function (_a) {
|
460
|
+
return [2 /*return*/, undefined];
|
461
|
+
});
|
462
|
+
});
|
463
|
+
};
|
464
|
+
ACSConversation.prototype.downloadFile = function () {
|
465
|
+
return __awaiter(this, void 0, void 0, function () {
|
466
|
+
return __generator(this, function (_a) {
|
467
|
+
return [2 /*return*/, undefined];
|
468
|
+
});
|
469
|
+
});
|
470
|
+
};
|
471
|
+
ACSConversation.prototype.disconnect = function () {
|
472
|
+
var _a, _b, _c;
|
473
|
+
return __awaiter(this, void 0, void 0, function () {
|
474
|
+
var _loop_1, _i, _d, _e, event_1, listeners;
|
475
|
+
var _this = this;
|
476
|
+
return __generator(this, function (_f) {
|
477
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.Disconnect);
|
478
|
+
try {
|
479
|
+
_loop_1 = function (event_1, listeners) {
|
480
|
+
listeners.forEach(function (listener) {
|
481
|
+
_this.chatClient.off(event_1, listener); // eslint-disable-line @typescript-eslint/no-explicit-any
|
482
|
+
});
|
483
|
+
};
|
484
|
+
for (_i = 0, _d = Object.entries(this.eventListeners); _i < _d.length; _i++) {
|
485
|
+
_e = _d[_i], event_1 = _e[0], listeners = _e[1];
|
486
|
+
_loop_1(event_1, listeners);
|
487
|
+
}
|
488
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.completeScenario(ACSClientEvent.Disconnect);
|
489
|
+
}
|
490
|
+
catch (_g) {
|
491
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.failScenario(ACSClientEvent.Disconnect);
|
492
|
+
}
|
493
|
+
return [2 /*return*/];
|
494
|
+
});
|
495
|
+
});
|
496
|
+
};
|
497
|
+
ACSConversation.prototype.createParticipantsMapping = function () {
|
498
|
+
return __awaiter(this, void 0, void 0, function () {
|
499
|
+
var participants, participantsMapping, _i, participants_1, participant, id;
|
500
|
+
var _a;
|
501
|
+
return __generator(this, function (_b) {
|
502
|
+
switch (_b.label) {
|
503
|
+
case 0: return [4 /*yield*/, this.getParticipants()];
|
504
|
+
case 1:
|
505
|
+
participants = _b.sent();
|
506
|
+
participantsMapping = {};
|
507
|
+
for (_i = 0, participants_1 = participants; _i < participants_1.length; _i++) {
|
508
|
+
participant = participants_1[_i];
|
509
|
+
id = participant.id;
|
510
|
+
if (!Object.keys(participantsMapping).includes(id.communicationUserId)) {
|
511
|
+
Object.assign(participantsMapping, (_a = {}, _a[id.communicationUserId] = participant, _a));
|
512
|
+
}
|
513
|
+
}
|
514
|
+
return [2 /*return*/, participantsMapping];
|
515
|
+
}
|
516
|
+
});
|
517
|
+
});
|
518
|
+
};
|
519
|
+
ACSConversation.prototype.trackListener = function (event, listener) {
|
520
|
+
if (!(event in this.eventListeners)) {
|
521
|
+
this.eventListeners[event] = [];
|
522
|
+
}
|
523
|
+
this.eventListeners[event].push(listener);
|
524
|
+
};
|
525
|
+
return ACSConversation;
|
526
|
+
}());
|
527
|
+
exports.ACSConversation = ACSConversation;
|
528
|
+
var ACSClient = /** @class */ (function () {
|
529
|
+
function ACSClient(logger) {
|
530
|
+
if (logger === void 0) { logger = null; }
|
531
|
+
this.logger = null;
|
532
|
+
this.tokenCredential = null;
|
533
|
+
this.chatClient = null;
|
534
|
+
this.logger = logger;
|
535
|
+
}
|
536
|
+
ACSClient.prototype.initialize = function (acsClientConfig) {
|
537
|
+
var _a, _b, _c, _d;
|
538
|
+
return __awaiter(this, void 0, void 0, function () {
|
539
|
+
var tokenRefresher, exceptionDetails, exceptionDetails;
|
540
|
+
var _this = this;
|
541
|
+
return __generator(this, function (_e) {
|
542
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.startScenario(ACSClientEvent.InitializeACSClient);
|
543
|
+
tokenRefresher = function () { return __awaiter(_this, void 0, void 0, function () {
|
544
|
+
var token;
|
545
|
+
return __generator(this, function (_a) {
|
546
|
+
switch (_a.label) {
|
547
|
+
case 0:
|
548
|
+
if (!acsClientConfig.tokenRefresher) return [3 /*break*/, 2];
|
549
|
+
return [4 /*yield*/, acsClientConfig.tokenRefresher()];
|
550
|
+
case 1:
|
551
|
+
token = _a.sent();
|
552
|
+
return [2 /*return*/, token];
|
553
|
+
case 2: return [2 /*return*/, acsClientConfig.token];
|
554
|
+
}
|
555
|
+
});
|
556
|
+
}); };
|
557
|
+
try {
|
558
|
+
this.tokenCredential = new communication_common_1.AzureCommunicationTokenCredential({
|
559
|
+
token: acsClientConfig.token,
|
560
|
+
tokenRefresher: tokenRefresher,
|
561
|
+
refreshProactively: true // Flag to whether refresh token 10 mins it expires
|
562
|
+
});
|
563
|
+
}
|
564
|
+
catch (error) {
|
565
|
+
exceptionDetails = {
|
566
|
+
response: 'CreateTokenCredentialFailure',
|
567
|
+
errorObject: "" + error
|
568
|
+
};
|
569
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.failScenario(ACSClientEvent.InitializeACSClient, {
|
570
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
571
|
+
});
|
572
|
+
throw new Error('CreateTokenCredentialFailed');
|
573
|
+
}
|
574
|
+
try {
|
575
|
+
this.chatClient = new communication_chat_1.ChatClient(acsClientConfig.environmentUrl, this.tokenCredential);
|
576
|
+
}
|
577
|
+
catch (error) {
|
578
|
+
exceptionDetails = {
|
579
|
+
response: 'CreateChatClientFailure',
|
580
|
+
errorObject: "" + error
|
581
|
+
};
|
582
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.failScenario(ACSClientEvent.InitializeACSClient, {
|
583
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
584
|
+
});
|
585
|
+
throw new Error('CreateChatClientFailed');
|
586
|
+
}
|
587
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.completeScenario(ACSClientEvent.InitializeACSClient);
|
588
|
+
return [2 /*return*/];
|
589
|
+
});
|
590
|
+
});
|
591
|
+
};
|
592
|
+
ACSClient.prototype.joinConversation = function (sessionInfo) {
|
593
|
+
return __awaiter(this, void 0, void 0, function () {
|
594
|
+
var conversation;
|
595
|
+
return __generator(this, function (_a) {
|
596
|
+
switch (_a.label) {
|
597
|
+
case 0:
|
598
|
+
conversation = new ACSConversation(this.tokenCredential, this.chatClient, this.logger);
|
599
|
+
return [4 /*yield*/, conversation.initialize(sessionInfo)];
|
600
|
+
case 1:
|
601
|
+
_a.sent();
|
602
|
+
return [2 /*return*/, conversation];
|
603
|
+
}
|
604
|
+
});
|
605
|
+
});
|
606
|
+
};
|
607
|
+
ACSClient.prototype.getChatClient = function () {
|
608
|
+
return this.chatClient;
|
609
|
+
};
|
610
|
+
return ACSClient;
|
611
|
+
}());
|
612
|
+
exports.default = ACSClient;
|
613
613
|
//# sourceMappingURL=ACSClient.js.map
|