@microsoft/omnichannel-chat-sdk 0.2.1-main.f5ff432 → 0.3.1-main.577db56
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/CHANGELOG.md +34 -1
- package/README.md +165 -9
- package/lib/OmnichannelChatSDK.d.ts +39 -22
- package/lib/OmnichannelChatSDK.js +1032 -335
- package/lib/OmnichannelChatSDK.js.map +1 -1
- package/lib/api/createVoiceVideoCalling.d.ts +1 -0
- package/lib/api/createVoiceVideoCalling.js +91 -83
- package/lib/api/createVoiceVideoCalling.js.map +1 -1
- package/lib/config/settings.d.ts +4 -3
- package/lib/config/settings.js +5 -3
- package/lib/config/settings.js.map +1 -1
- package/lib/core/{IAuthSettings.d.ts → AuthSettings.d.ts} +1 -1
- package/lib/core/{IAuthSettings.js → AuthSettings.js} +1 -1
- package/lib/core/AuthSettings.js.map +1 -0
- package/lib/core/{IChatConfig.d.ts → ChatConfig.d.ts} +1 -1
- package/lib/core/{IChatConfig.js → ChatConfig.js} +1 -1
- package/lib/core/ChatConfig.js.map +1 -0
- package/lib/core/ChatReconnectContext.d.ts +4 -0
- package/lib/core/ChatReconnectContext.js +3 -0
- package/lib/core/ChatReconnectContext.js.map +1 -0
- package/lib/core/ChatReconnectOptionalParams.d.ts +3 -0
- package/lib/core/ChatReconnectOptionalParams.js +3 -0
- package/lib/core/ChatReconnectOptionalParams.js.map +1 -0
- package/lib/core/{IChatSDKConfig.d.ts → ChatSDKConfig.d.ts} +11 -7
- package/lib/core/{IChatSDKConfig.js → ChatSDKConfig.js} +1 -1
- package/lib/core/ChatSDKConfig.js.map +1 -0
- package/lib/core/{IChatTranscriptBody.d.ts → ChatTranscriptBody.d.ts} +1 -1
- package/lib/core/ChatTranscriptBody.js +3 -0
- package/lib/core/ChatTranscriptBody.js.map +1 -0
- package/lib/core/{ILiveChatContext.d.ts → LiveChatContext.d.ts} +1 -1
- package/lib/core/LiveChatContext.js +3 -0
- package/lib/core/LiveChatContext.js.map +1 -0
- package/lib/core/LiveChatVersion.d.ts +5 -0
- package/lib/core/LiveChatVersion.js +9 -0
- package/lib/core/LiveChatVersion.js.map +1 -0
- package/lib/core/{IOmnichannelConfig.d.ts → OmnichannelConfig.d.ts} +1 -1
- package/lib/core/OmnichannelConfig.js +3 -0
- package/lib/core/OmnichannelConfig.js.map +1 -0
- package/lib/core/{IStartChatOptionalParams.d.ts → StartChatOptionalParams.d.ts} +4 -3
- package/lib/core/StartChatOptionalParams.js +3 -0
- package/lib/core/StartChatOptionalParams.js.map +1 -0
- package/lib/core/messaging/ACSChatMessageType.d.ts +7 -0
- package/lib/core/messaging/ACSChatMessageType.js +11 -0
- package/lib/core/messaging/ACSChatMessageType.js.map +1 -0
- package/lib/core/messaging/ACSClient.d.ts +44 -0
- package/lib/core/messaging/ACSClient.js +588 -0
- package/lib/core/messaging/ACSClient.js.map +1 -0
- package/lib/core/messaging/ACSClientConfig.d.ts +4 -0
- package/lib/core/messaging/ACSClientConfig.js +3 -0
- package/lib/core/messaging/ACSClientConfig.js.map +1 -0
- package/lib/core/messaging/ACSParticipantDisplayName.d.ts +6 -0
- package/lib/core/messaging/ACSParticipantDisplayName.js +10 -0
- package/lib/core/messaging/ACSParticipantDisplayName.js.map +1 -0
- package/lib/core/messaging/ACSSessionInfo.d.ts +5 -0
- package/lib/core/messaging/ACSSessionInfo.js +3 -0
- package/lib/core/messaging/ACSSessionInfo.js.map +1 -0
- package/lib/core/{ChatAdapterConfig.d.ts → messaging/ChatAdapterConfig.d.ts} +2 -0
- package/lib/core/{ChatAdapterConfig.js → messaging/ChatAdapterConfig.js} +0 -0
- package/lib/core/messaging/ChatAdapterConfig.js.map +1 -0
- package/lib/core/{ChatAdapterProtocols.d.ts → messaging/ChatAdapterProtocols.d.ts} +1 -0
- package/lib/core/{ChatAdapterProtocols.js → messaging/ChatAdapterProtocols.js} +3 -1
- package/lib/core/messaging/ChatAdapterProtocols.js.map +1 -0
- package/lib/core/{IChatSDKMessage.d.ts → messaging/ChatSDKMessage.d.ts} +2 -1
- package/lib/core/messaging/ChatSDKMessage.js +3 -0
- package/lib/core/messaging/ChatSDKMessage.js.map +1 -0
- package/lib/core/{IC3Config.d.ts → messaging/IC3Config.d.ts} +0 -0
- package/lib/core/{IC3Config.js → messaging/IC3Config.js} +0 -0
- package/lib/core/messaging/IC3Config.js.map +1 -0
- package/lib/core/messaging/MessageTags.d.ts +1 -0
- package/lib/core/messaging/MessageTags.js +5 -0
- package/lib/core/messaging/MessageTags.js.map +1 -0
- package/lib/core/messaging/OmnichannelMessage.d.ts +64 -0
- package/lib/core/messaging/OmnichannelMessage.js +52 -0
- package/lib/core/messaging/OmnichannelMessage.js.map +1 -0
- package/lib/core/{OnNewMessageOptionalParams.d.ts → messaging/OnNewMessageOptionalParams.d.ts} +0 -0
- package/lib/core/{OnNewMessageOptionalParams.js → messaging/OnNewMessageOptionalParams.js} +0 -0
- package/lib/core/messaging/OnNewMessageOptionalParams.js.map +1 -0
- package/lib/external/ACSAdapter/AMSFileManager.d.ts +39 -0
- package/lib/external/ACSAdapter/AMSFileManager.js +306 -0
- package/lib/external/ACSAdapter/AMSFileManager.js.map +1 -0
- package/lib/external/IC3Adapter/IChatToken.d.ts +2 -0
- package/lib/index.d.ts +2 -2
- package/lib/telemetry/AriaTelemetry.d.ts +4 -0
- package/lib/telemetry/AriaTelemetry.js +150 -13
- package/lib/telemetry/AriaTelemetry.js.map +1 -1
- package/lib/telemetry/EventMarker.d.ts +3 -0
- package/lib/telemetry/EventMarker.js +13 -0
- package/lib/telemetry/EventMarker.js.map +1 -0
- package/lib/telemetry/ScenarioMarker.d.ts +9 -7
- package/lib/telemetry/ScenarioMarker.js +12 -7
- package/lib/telemetry/ScenarioMarker.js.map +1 -1
- package/lib/telemetry/ScenarioType.d.ts +2 -0
- package/lib/telemetry/ScenarioType.js +2 -0
- package/lib/telemetry/ScenarioType.js.map +1 -1
- package/lib/telemetry/TelemetryEvent.d.ts +10 -4
- package/lib/telemetry/TelemetryEvent.js +9 -10
- package/lib/telemetry/TelemetryEvent.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +5378 -1320
- package/lib/utils/createOmnichannelMessage.d.ts +11 -0
- package/lib/utils/createOmnichannelMessage.js +63 -0
- package/lib/utils/createOmnichannelMessage.js.map +1 -0
- package/lib/utils/libraries.d.ts +3 -1
- package/lib/utils/libraries.js +9 -2
- package/lib/utils/libraries.js.map +1 -1
- package/lib/utils/loggers.d.ts +42 -6
- package/lib/utils/loggers.js +197 -2
- package/lib/utils/loggers.js.map +1 -1
- package/lib/utils/utilities.js +10 -3
- package/lib/utils/utilities.js.map +1 -1
- package/lib/validators/OmnichannelConfigValidator.d.ts +2 -2
- package/lib/validators/OmnichannelConfigValidator.js.map +1 -1
- package/lib/validators/SDKConfigValidators.d.ts +3 -3
- package/lib/validators/SDKConfigValidators.js +11 -0
- package/lib/validators/SDKConfigValidators.js.map +1 -1
- package/package.json +14 -10
- package/lib/core/ChatAdapterConfig.js.map +0 -1
- package/lib/core/ChatAdapterProtocols.js.map +0 -1
- package/lib/core/IAuthSettings.js.map +0 -1
- package/lib/core/IC3Config.js.map +0 -1
- package/lib/core/IChatConfig.js.map +0 -1
- package/lib/core/IChatSDKConfig.js.map +0 -1
- package/lib/core/IChatSDKMessage.js +0 -3
- package/lib/core/IChatSDKMessage.js.map +0 -1
- package/lib/core/IChatTranscriptBody.js +0 -3
- package/lib/core/IChatTranscriptBody.js.map +0 -1
- package/lib/core/ILiveChatContext.js +0 -3
- package/lib/core/ILiveChatContext.js.map +0 -1
- package/lib/core/IOmnichannelConfig.js +0 -3
- package/lib/core/IOmnichannelConfig.js.map +0 -1
- package/lib/core/IStartChatOptionalParams.js +0 -3
- package/lib/core/IStartChatOptionalParams.js.map +0 -1
- package/lib/core/OnNewMessageOptionalParams.js.map +0 -1
@@ -47,35 +47,51 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
47
47
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
48
48
|
}
|
49
49
|
};
|
50
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
51
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
52
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
53
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
54
|
+
r[k] = a[j];
|
55
|
+
return r;
|
56
|
+
};
|
50
57
|
Object.defineProperty(exports, "__esModule", { value: true });
|
51
|
-
var
|
52
|
-
var
|
53
|
-
var
|
58
|
+
var ACSClient_1 = require("./core/messaging/ACSClient");
|
59
|
+
var ACSParticipantDisplayName_1 = require("./core/messaging/ACSParticipantDisplayName");
|
60
|
+
var AMSFileManager_1 = require("./external/ACSAdapter/AMSFileManager");
|
61
|
+
var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
|
62
|
+
var ChatAdapterProtocols_1 = require("./core/messaging/ChatAdapterProtocols");
|
63
|
+
var ConversationMode_1 = require("./core/ConversationMode");
|
64
|
+
var omnichannel_amsclient_1 = require("@microsoft/omnichannel-amsclient");
|
65
|
+
var loggers_1 = require("./utils/loggers");
|
66
|
+
var createOmnichannelMessage_1 = require("./utils/createOmnichannelMessage");
|
67
|
+
var createTelemetry_1 = require("./utils/createTelemetry");
|
68
|
+
var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
|
69
|
+
var MessageTags_1 = require("./core/messaging/MessageTags");
|
54
70
|
var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
|
55
71
|
var FileSharingProtocolType_1 = require("@microsoft/omnichannel-ic3core/lib/model/FileSharingProtocolType");
|
56
72
|
var HostType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/HostType");
|
73
|
+
var utilities_1 = require("./utils/utilities");
|
74
|
+
var libraries_1 = require("./utils/libraries");
|
75
|
+
var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
|
76
|
+
var LiveChatVersion_1 = require("./core/LiveChatVersion");
|
77
|
+
var WebUtils_1 = require("./utils/WebUtils");
|
57
78
|
var MessageContentType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageContentType");
|
58
79
|
var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType");
|
59
80
|
var PersonType_1 = require("@microsoft/omnichannel-ic3core/lib/model/PersonType");
|
60
81
|
var platform_1 = require("./utils/platform");
|
61
82
|
var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType");
|
62
|
-
var
|
63
|
-
var
|
83
|
+
var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
|
84
|
+
var ocsdk_1 = require("@microsoft/ocsdk");
|
85
|
+
var omnichannel_ic3core_1 = require("@microsoft/omnichannel-ic3core");
|
86
|
+
var TelemetryEvent_1 = require("./telemetry/TelemetryEvent");
|
64
87
|
var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
|
65
88
|
var SDKConfigValidators_1 = require("./validators/SDKConfigValidators");
|
66
|
-
var WebUtils_1 = require("./utils/WebUtils");
|
67
|
-
var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
|
68
|
-
var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
|
69
|
-
var createTelemetry_1 = require("./utils/createTelemetry");
|
70
|
-
var TelemetryEvent_1 = require("./telemetry/TelemetryEvent");
|
71
|
-
var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
|
72
|
-
var loggers_1 = require("./utils/loggers");
|
73
|
-
var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
|
74
|
-
var ConversationMode_1 = require("./core/ConversationMode");
|
75
89
|
var OmnichannelChatSDK = /** @class */ (function () {
|
76
90
|
function OmnichannelChatSDK(omnichannelConfig, chatSDKConfig) {
|
77
91
|
if (chatSDKConfig === void 0) { chatSDKConfig = SDKConfigValidators_1.defaultChatSDKConfig; }
|
78
|
-
var _a, _b, _c, _d, _e;
|
92
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
93
|
+
this.ACSClient = null;
|
94
|
+
this.AMSClient = null;
|
79
95
|
this.authSettings = null;
|
80
96
|
this.authenticatedUserToken = null;
|
81
97
|
this.conversation = null;
|
@@ -83,13 +99,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
83
99
|
this.telemetry = null;
|
84
100
|
this.ic3ClientLogger = null;
|
85
101
|
this.ocSdkLogger = null;
|
102
|
+
this.acsClientLogger = null;
|
103
|
+
this.acsAdapterLogger = null;
|
86
104
|
this.isPersistentChat = false;
|
105
|
+
this.isChatReconnect = false;
|
87
106
|
this.reconnectId = null;
|
107
|
+
this.refreshTokenTimer = null;
|
88
108
|
this.debug = false;
|
89
109
|
this.omnichannelConfig = omnichannelConfig;
|
90
110
|
this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
|
91
111
|
);
|
92
112
|
this.isInitialized = false;
|
113
|
+
this.liveChatVersion = LiveChatVersion_1.default.V1;
|
93
114
|
this.requestId = ocsdk_1.uuidv4();
|
94
115
|
this.chatToken = {};
|
95
116
|
this.liveChatConfig = {};
|
@@ -100,9 +121,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
100
121
|
this.scenarioMarker = new ScenarioMarker_1.default(this.omnichannelConfig);
|
101
122
|
this.ic3ClientLogger = loggers_1.createIC3ClientLogger(this.omnichannelConfig);
|
102
123
|
this.ocSdkLogger = loggers_1.createOCSDKLogger(this.omnichannelConfig);
|
124
|
+
this.acsClientLogger = loggers_1.createACSClientLogger(this.omnichannelConfig);
|
125
|
+
this.acsAdapterLogger = loggers_1.createACSAdapterLogger(this.omnichannelConfig);
|
103
126
|
this.scenarioMarker.useTelemetry(this.telemetry);
|
104
127
|
this.ic3ClientLogger.useTelemetry(this.telemetry);
|
105
128
|
this.ocSdkLogger.useTelemetry(this.telemetry);
|
129
|
+
this.acsClientLogger.useTelemetry(this.telemetry);
|
130
|
+
this.acsAdapterLogger.useTelemetry(this.telemetry);
|
106
131
|
OmnichannelConfigValidator_1.default(omnichannelConfig);
|
107
132
|
SDKConfigValidators_1.default(chatSDKConfig);
|
108
133
|
((_a = this.chatSDKConfig.telemetry) === null || _a === void 0 ? void 0 : _a.disable) && ((_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.disable());
|
@@ -111,93 +136,199 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
111
136
|
}
|
112
137
|
(_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
|
113
138
|
(_e = this.ocSdkLogger) === null || _e === void 0 ? void 0 : _e.setRequestId(this.requestId);
|
139
|
+
(_f = this.acsClientLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
|
140
|
+
(_g = this.acsAdapterLogger) === null || _g === void 0 ? void 0 : _g.setRequestId(this.requestId);
|
114
141
|
}
|
115
142
|
/* istanbul ignore next */
|
116
143
|
OmnichannelChatSDK.prototype.setDebug = function (flag) {
|
117
|
-
var _a, _b, _c;
|
144
|
+
var _a, _b, _c, _d, _e, _f;
|
118
145
|
this.debug = flag;
|
119
|
-
(_a = this.
|
146
|
+
(_a = this.AMSClient) === null || _a === void 0 ? void 0 : _a.setDebug(flag);
|
147
|
+
(_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.setDebug(flag);
|
120
148
|
this.scenarioMarker.setDebug(flag);
|
121
|
-
(
|
122
|
-
(
|
149
|
+
(_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setDebug(flag);
|
150
|
+
(_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setDebug(flag);
|
151
|
+
(_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setDebug(flag);
|
152
|
+
(_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setDebug(flag);
|
123
153
|
};
|
124
154
|
OmnichannelChatSDK.prototype.initialize = function () {
|
125
155
|
return __awaiter(this, void 0, void 0, function () {
|
126
|
-
var
|
127
|
-
return __generator(this, function (
|
128
|
-
switch (
|
156
|
+
var _a, _b, _c, _d;
|
157
|
+
return __generator(this, function (_e) {
|
158
|
+
switch (_e.label) {
|
129
159
|
case 0:
|
130
160
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.InitializeChatSDK);
|
131
161
|
if (this.isInitialized) {
|
132
162
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeChatSDK);
|
133
163
|
return [2 /*return*/, this.liveChatConfig];
|
134
164
|
}
|
135
|
-
|
165
|
+
_e.label = 1;
|
136
166
|
case 1:
|
137
|
-
|
167
|
+
_e.trys.push([1, 8, , 9]);
|
138
168
|
this.OCSDKProvider = ocsdk_1.SDKProvider;
|
169
|
+
_a = this;
|
139
170
|
return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, {}, this.ocSdkLogger)];
|
140
171
|
case 2:
|
141
|
-
OCClient =
|
142
|
-
return [4 /*yield*/, this.getIC3Client()];
|
143
|
-
case 3:
|
144
|
-
IC3Client = _b.sent();
|
145
|
-
// Assign & Update flag only if all dependencies have been initialized succesfully
|
146
|
-
this.OCClient = OCClient;
|
147
|
-
this.IC3Client = IC3Client;
|
172
|
+
_a.OCClient = _e.sent();
|
148
173
|
return [4 /*yield*/, this.getChatConfig()];
|
174
|
+
case 3:
|
175
|
+
_e.sent();
|
176
|
+
if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 5];
|
177
|
+
this.ACSClient = new ACSClient_1.default(this.acsClientLogger);
|
178
|
+
_b = this;
|
179
|
+
return [4 /*yield*/, omnichannel_amsclient_1.default({
|
180
|
+
framedMode: platform_1.isBrowser(),
|
181
|
+
debug: false,
|
182
|
+
logger: undefined
|
183
|
+
})];
|
149
184
|
case 4:
|
150
|
-
_b.sent();
|
185
|
+
_b.AMSClient = _e.sent();
|
186
|
+
return [3 /*break*/, 7];
|
187
|
+
case 5:
|
188
|
+
_c = this;
|
189
|
+
return [4 /*yield*/, this.getIC3Client()];
|
190
|
+
case 6:
|
191
|
+
_c.IC3Client = _e.sent();
|
192
|
+
_e.label = 7;
|
193
|
+
case 7:
|
151
194
|
this.isInitialized = true;
|
152
195
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeChatSDK);
|
153
|
-
return [3 /*break*/,
|
154
|
-
case
|
155
|
-
|
196
|
+
return [3 /*break*/, 9];
|
197
|
+
case 8:
|
198
|
+
_d = _e.sent();
|
156
199
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.InitializeChatSDK);
|
157
|
-
return [3 /*break*/,
|
158
|
-
case
|
200
|
+
return [3 /*break*/, 9];
|
201
|
+
case 9: return [2 /*return*/, this.liveChatConfig];
|
202
|
+
}
|
203
|
+
});
|
204
|
+
});
|
205
|
+
};
|
206
|
+
OmnichannelChatSDK.prototype.getChatReconnectContext = function (optionalParams) {
|
207
|
+
if (optionalParams === void 0) { optionalParams = {}; }
|
208
|
+
return __awaiter(this, void 0, void 0, function () {
|
209
|
+
var context, reconnectableChatsParams, reconnectableChatsResponse, error_1, exceptionDetails, reconnectAvailabilityResponse, error_2, exceptionDetails;
|
210
|
+
return __generator(this, function (_a) {
|
211
|
+
switch (_a.label) {
|
212
|
+
case 0:
|
213
|
+
this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetChatReconnectContext, {
|
214
|
+
RequestId: this.requestId,
|
215
|
+
ChatId: this.chatToken.chatId
|
216
|
+
});
|
217
|
+
context = {
|
218
|
+
reconnectId: null,
|
219
|
+
redirectURL: null
|
220
|
+
};
|
221
|
+
if (!this.authenticatedUserToken) return [3 /*break*/, 5];
|
222
|
+
_a.label = 1;
|
223
|
+
case 1:
|
224
|
+
_a.trys.push([1, 3, , 4]);
|
225
|
+
reconnectableChatsParams = {
|
226
|
+
authenticatedUserToken: this.authenticatedUserToken
|
227
|
+
};
|
228
|
+
return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
|
229
|
+
case 2:
|
230
|
+
reconnectableChatsResponse = _a.sent();
|
231
|
+
if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
|
232
|
+
context.reconnectId = reconnectableChatsResponse.reconnectid;
|
233
|
+
}
|
234
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetChatReconnectContext, {
|
235
|
+
RequestId: this.requestId,
|
236
|
+
ChatId: this.chatToken.chatId
|
237
|
+
});
|
238
|
+
return [3 /*break*/, 4];
|
239
|
+
case 3:
|
240
|
+
error_1 = _a.sent();
|
241
|
+
exceptionDetails = {
|
242
|
+
response: "OCClientGetReconnectableChatsFailed"
|
243
|
+
};
|
244
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetChatReconnectContext, {
|
245
|
+
RequestId: this.requestId,
|
246
|
+
ChatId: this.chatToken.chatId,
|
247
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
248
|
+
});
|
249
|
+
console.error("OmnichannelChatSDK/GetChatReconnectContext/error " + error_1);
|
250
|
+
return [3 /*break*/, 4];
|
251
|
+
case 4: return [3 /*break*/, 9];
|
252
|
+
case 5:
|
253
|
+
if (!optionalParams.reconnectId) return [3 /*break*/, 9];
|
254
|
+
_a.label = 6;
|
255
|
+
case 6:
|
256
|
+
_a.trys.push([6, 8, , 9]);
|
257
|
+
return [4 /*yield*/, this.OCClient.getReconnectAvailability(optionalParams.reconnectId)];
|
258
|
+
case 7:
|
259
|
+
reconnectAvailabilityResponse = _a.sent();
|
260
|
+
if (reconnectAvailabilityResponse && !reconnectAvailabilityResponse.isReconnectAvailable) {
|
261
|
+
if (reconnectAvailabilityResponse.reconnectRedirectionURL) {
|
262
|
+
context.redirectURL = reconnectAvailabilityResponse.reconnectRedirectionURL;
|
263
|
+
}
|
264
|
+
}
|
265
|
+
else {
|
266
|
+
context.reconnectId = optionalParams.reconnectId;
|
267
|
+
}
|
268
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetChatReconnectContext, {
|
269
|
+
RequestId: this.requestId,
|
270
|
+
ChatId: this.chatToken.chatId
|
271
|
+
});
|
272
|
+
return [3 /*break*/, 9];
|
273
|
+
case 8:
|
274
|
+
error_2 = _a.sent();
|
275
|
+
exceptionDetails = {
|
276
|
+
response: "OCClientGetReconnectAvailabilityFailed"
|
277
|
+
};
|
278
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetChatReconnectContext, {
|
279
|
+
RequestId: this.requestId,
|
280
|
+
ChatId: this.chatToken.chatId,
|
281
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
282
|
+
});
|
283
|
+
console.error("OmnichannelChatSDK/GetChatReconnectContext/error " + error_2);
|
284
|
+
return [3 /*break*/, 9];
|
285
|
+
case 9: return [2 /*return*/, context];
|
159
286
|
}
|
160
287
|
});
|
161
288
|
});
|
162
289
|
};
|
163
290
|
OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
|
164
|
-
var _a, _b, _c, _d;
|
291
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
165
292
|
if (optionalParams === void 0) { optionalParams = {}; }
|
166
293
|
return __awaiter(this, void 0, void 0, function () {
|
167
|
-
var reconnectableChatsParams, reconnectableChatsResponse,
|
168
|
-
|
169
|
-
|
294
|
+
var reconnectableChatsParams, reconnectableChatsResponse, _p, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _q, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _r, error_8, exceptionDetails;
|
295
|
+
var _this = this;
|
296
|
+
return __generator(this, function (_s) {
|
297
|
+
switch (_s.label) {
|
170
298
|
case 0:
|
171
299
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
|
172
300
|
RequestId: this.requestId
|
173
301
|
});
|
174
|
-
if (
|
175
|
-
|
302
|
+
if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
|
303
|
+
this.reconnectId = optionalParams.reconnectId;
|
304
|
+
}
|
305
|
+
if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 4];
|
306
|
+
_s.label = 1;
|
176
307
|
case 1:
|
177
|
-
|
308
|
+
_s.trys.push([1, 3, , 4]);
|
178
309
|
reconnectableChatsParams = {
|
179
310
|
authenticatedUserToken: this.authenticatedUserToken
|
180
311
|
};
|
181
312
|
return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
|
182
313
|
case 2:
|
183
|
-
reconnectableChatsResponse =
|
314
|
+
reconnectableChatsResponse = _s.sent();
|
184
315
|
if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
|
185
316
|
this.reconnectId = reconnectableChatsResponse.reconnectid;
|
186
317
|
}
|
187
318
|
return [3 /*break*/, 4];
|
188
319
|
case 3:
|
189
|
-
|
320
|
+
_p = _s.sent();
|
190
321
|
exceptionDetails = {
|
191
322
|
response: "OCClientGetReconnectableChatsFailed"
|
192
323
|
};
|
193
324
|
throw Error(exceptionDetails.response);
|
194
325
|
case 4:
|
195
|
-
if (!(optionalParams.liveChatContext && !this.isPersistentChat)) return [3 /*break*/, 6];
|
326
|
+
if (!(optionalParams.liveChatContext && !this.isPersistentChat && !this.isChatReconnect)) return [3 /*break*/, 6];
|
196
327
|
this.chatToken = optionalParams.liveChatContext.chatToken || {};
|
197
328
|
this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
|
198
329
|
return [4 /*yield*/, this.getConversationDetails()];
|
199
330
|
case 5:
|
200
|
-
conversationDetails =
|
331
|
+
conversationDetails = _s.sent();
|
201
332
|
if (Object.keys(conversationDetails).length === 0) {
|
202
333
|
exceptionDetails = {
|
203
334
|
response: "InvalidConversation"
|
@@ -222,20 +353,25 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
222
353
|
console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
|
223
354
|
throw Error(exceptionDetails.response);
|
224
355
|
}
|
225
|
-
|
356
|
+
_s.label = 6;
|
226
357
|
case 6:
|
227
358
|
if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 8];
|
228
359
|
return [4 /*yield*/, this.getChatToken(false)];
|
229
360
|
case 7:
|
230
|
-
|
231
|
-
|
361
|
+
_s.sent();
|
362
|
+
_s.label = 8;
|
232
363
|
case 8:
|
233
|
-
(
|
234
|
-
(
|
364
|
+
(_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
|
365
|
+
(_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
|
366
|
+
(_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId(this.chatToken.chatId || '');
|
367
|
+
(_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setChatId(this.chatToken.chatId || '');
|
235
368
|
sessionInitOptionalParams = {
|
236
369
|
initContext: {}
|
237
370
|
};
|
238
|
-
if (this.isPersistentChat && !((
|
371
|
+
if (this.isPersistentChat && !((_g = this.chatSDKConfig.persistentChat) === null || _g === void 0 ? void 0 : _g.disable)) {
|
372
|
+
sessionInitOptionalParams.reconnectId = this.reconnectId;
|
373
|
+
}
|
374
|
+
if (this.isChatReconnect && !((_h = this.chatSDKConfig.chatReconnect) === null || _h === void 0 ? void 0 : _h.disable) && !this.isPersistentChat) {
|
239
375
|
sessionInitOptionalParams.reconnectId = this.reconnectId;
|
240
376
|
}
|
241
377
|
if (optionalParams.customContext) {
|
@@ -263,15 +399,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
263
399
|
if (this.authenticatedUserToken) {
|
264
400
|
sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
|
265
401
|
}
|
266
|
-
|
402
|
+
_s.label = 9;
|
267
403
|
case 9:
|
268
|
-
|
404
|
+
_s.trys.push([9, 11, , 12]);
|
269
405
|
return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
|
270
406
|
case 10:
|
271
|
-
|
407
|
+
_s.sent();
|
272
408
|
return [3 /*break*/, 12];
|
273
409
|
case 11:
|
274
|
-
|
410
|
+
error_3 = _s.sent();
|
275
411
|
exceptionDetails = {
|
276
412
|
response: "OCClientSessionInitFailed"
|
277
413
|
};
|
@@ -280,20 +416,98 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
280
416
|
ChatId: this.chatToken.chatId,
|
281
417
|
ExceptionDetails: JSON.stringify(exceptionDetails)
|
282
418
|
});
|
283
|
-
console.error("OmnichannelChatSDK/startChat/sessionInit/error " +
|
284
|
-
return [2 /*return*/,
|
419
|
+
console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_3);
|
420
|
+
return [2 /*return*/, error_3];
|
285
421
|
case 12:
|
286
|
-
|
422
|
+
if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 23];
|
423
|
+
chatAdapterConfig = {
|
424
|
+
token: this.chatToken.token,
|
425
|
+
id: this.chatToken.visitorId || 'teamsvisitor',
|
426
|
+
threadId: this.chatToken.chatId,
|
427
|
+
environmentUrl: this.chatToken.acsEndpoint,
|
428
|
+
pollingInterval: 1000
|
429
|
+
};
|
430
|
+
_s.label = 13;
|
431
|
+
case 13:
|
432
|
+
_s.trys.push([13, 15, , 16]);
|
433
|
+
return [4 /*yield*/, ((_j = this.ACSClient) === null || _j === void 0 ? void 0 : _j.initialize({
|
434
|
+
token: chatAdapterConfig.token,
|
435
|
+
environmentUrl: chatAdapterConfig.environmentUrl
|
436
|
+
}))];
|
437
|
+
case 14:
|
438
|
+
_s.sent();
|
439
|
+
return [3 /*break*/, 16];
|
440
|
+
case 15:
|
441
|
+
error_4 = _s.sent();
|
442
|
+
exceptionDetails = {
|
443
|
+
response: "ACSClientInitializeFailed"
|
444
|
+
};
|
445
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
|
446
|
+
RequestId: this.requestId,
|
447
|
+
ChatId: this.chatToken.chatId,
|
448
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
449
|
+
});
|
450
|
+
console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
|
451
|
+
return [2 /*return*/, error_4];
|
452
|
+
case 16:
|
453
|
+
_s.trys.push([16, 18, , 19]);
|
454
|
+
_q = this;
|
455
|
+
return [4 /*yield*/, ((_k = this.ACSClient) === null || _k === void 0 ? void 0 : _k.joinConversation({
|
456
|
+
id: chatAdapterConfig.id,
|
457
|
+
threadId: chatAdapterConfig.threadId,
|
458
|
+
pollingInterval: chatAdapterConfig.pollingInterval
|
459
|
+
}))];
|
460
|
+
case 17:
|
461
|
+
_q.conversation = (_s.sent());
|
462
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
|
463
|
+
RequestId: this.requestId,
|
464
|
+
ChatId: this.chatToken.chatId
|
465
|
+
});
|
466
|
+
return [3 /*break*/, 19];
|
467
|
+
case 18:
|
468
|
+
error_5 = _s.sent();
|
469
|
+
exceptionDetails = {
|
470
|
+
response: "ACSClientJoinConversationFailed"
|
471
|
+
};
|
472
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
|
473
|
+
RequestId: this.requestId,
|
474
|
+
ChatId: this.chatToken.chatId,
|
475
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
476
|
+
});
|
477
|
+
console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
|
478
|
+
throw Error(exceptionDetails.response);
|
479
|
+
case 19:
|
480
|
+
_s.trys.push([19, 21, , 22]);
|
481
|
+
return [4 /*yield*/, ((_l = this.AMSClient) === null || _l === void 0 ? void 0 : _l.initialize({
|
482
|
+
chatToken: this.chatToken
|
483
|
+
}))];
|
484
|
+
case 20:
|
485
|
+
_s.sent();
|
486
|
+
return [3 /*break*/, 22];
|
487
|
+
case 21:
|
488
|
+
error_6 = _s.sent();
|
489
|
+
exceptionDetails = {
|
490
|
+
response: "AMSClientInitializeFailed"
|
491
|
+
};
|
492
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
|
493
|
+
RequestId: this.requestId,
|
494
|
+
ChatId: this.chatToken.chatId,
|
495
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
496
|
+
});
|
497
|
+
throw Error(exceptionDetails.response);
|
498
|
+
case 22: return [3 /*break*/, 29];
|
499
|
+
case 23:
|
500
|
+
_s.trys.push([23, 25, , 26]);
|
287
501
|
return [4 /*yield*/, this.IC3Client.initialize({
|
288
502
|
token: this.chatToken.token,
|
289
503
|
regionGtms: this.chatToken.regionGTMS,
|
290
504
|
visitor: true
|
291
505
|
})];
|
292
|
-
case
|
293
|
-
|
294
|
-
return [3 /*break*/,
|
295
|
-
case
|
296
|
-
|
506
|
+
case 24:
|
507
|
+
_s.sent();
|
508
|
+
return [3 /*break*/, 26];
|
509
|
+
case 25:
|
510
|
+
error_7 = _s.sent();
|
297
511
|
exceptionDetails = {
|
298
512
|
response: "IC3ClientInitializeFailed"
|
299
513
|
};
|
@@ -302,21 +516,21 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
302
516
|
ChatId: this.chatToken.chatId,
|
303
517
|
ExceptionDetails: JSON.stringify(exceptionDetails)
|
304
518
|
});
|
305
|
-
console.error("OmnichannelChatSDK/startChat/initialize/error " +
|
306
|
-
return [2 /*return*/,
|
307
|
-
case
|
308
|
-
|
309
|
-
|
519
|
+
console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
|
520
|
+
return [2 /*return*/, error_7];
|
521
|
+
case 26:
|
522
|
+
_s.trys.push([26, 28, , 29]);
|
523
|
+
_r = this;
|
310
524
|
return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
|
311
|
-
case
|
312
|
-
|
525
|
+
case 27:
|
526
|
+
_r.conversation = _s.sent();
|
313
527
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
|
314
528
|
RequestId: this.requestId,
|
315
529
|
ChatId: this.chatToken.chatId
|
316
530
|
});
|
317
|
-
return [3 /*break*/,
|
318
|
-
case
|
319
|
-
|
531
|
+
return [3 /*break*/, 29];
|
532
|
+
case 28:
|
533
|
+
error_8 = _s.sent();
|
320
534
|
exceptionDetails = {
|
321
535
|
response: "IC3ClientJoinConversationFailed"
|
322
536
|
};
|
@@ -325,19 +539,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
325
539
|
ChatId: this.chatToken.chatId,
|
326
540
|
ExceptionDetails: JSON.stringify(exceptionDetails)
|
327
541
|
});
|
328
|
-
console.error("OmnichannelChatSDK/startChat/joinConversation/error " +
|
329
|
-
return [2 /*return*/,
|
330
|
-
case
|
542
|
+
console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
|
543
|
+
return [2 /*return*/, error_8];
|
544
|
+
case 29:
|
545
|
+
if (this.isPersistentChat && !((_m = this.chatSDKConfig.persistentChat) === null || _m === void 0 ? void 0 : _m.disable)) {
|
546
|
+
this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
547
|
+
return __generator(this, function (_a) {
|
548
|
+
switch (_a.label) {
|
549
|
+
case 0: return [4 /*yield*/, this.getChatToken(false)];
|
550
|
+
case 1:
|
551
|
+
_a.sent();
|
552
|
+
this.updateChatToken(this.chatToken.token, this.chatToken.regionGTMS);
|
553
|
+
return [2 /*return*/];
|
554
|
+
}
|
555
|
+
});
|
556
|
+
}); }, (_o = this.chatSDKConfig.persistentChat) === null || _o === void 0 ? void 0 : _o.tokenUpdateTime);
|
557
|
+
}
|
558
|
+
return [2 /*return*/];
|
331
559
|
}
|
332
560
|
});
|
333
561
|
});
|
334
562
|
};
|
335
563
|
OmnichannelChatSDK.prototype.endChat = function () {
|
336
|
-
var _a, _b, _c, _d, _e;
|
564
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
337
565
|
return __awaiter(this, void 0, void 0, function () {
|
338
|
-
var sessionCloseOptionalParams, isReconnectChat,
|
339
|
-
return __generator(this, function (
|
340
|
-
switch (
|
566
|
+
var sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_9, exceptionDetails;
|
567
|
+
return __generator(this, function (_m) {
|
568
|
+
switch (_m.label) {
|
341
569
|
case 0:
|
342
570
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.EndChat, {
|
343
571
|
RequestId: this.requestId,
|
@@ -349,30 +577,39 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
349
577
|
sessionCloseOptionalParams.isPersistentChat = this.isPersistentChat;
|
350
578
|
sessionCloseOptionalParams.isReconnectChat = isReconnectChat;
|
351
579
|
}
|
580
|
+
if (this.isChatReconnect && !((_b = this.chatSDKConfig.chatReconnect) === null || _b === void 0 ? void 0 : _b.disable) && !this.isPersistentChat) {
|
581
|
+
isChatReconnect = this.reconnectId !== null ? true : false;
|
582
|
+
sessionCloseOptionalParams.isReconnectChat = isChatReconnect;
|
583
|
+
}
|
352
584
|
if (this.authenticatedUserToken) {
|
353
585
|
sessionCloseOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
|
354
586
|
}
|
355
|
-
|
587
|
+
_m.label = 1;
|
356
588
|
case 1:
|
357
|
-
|
589
|
+
_m.trys.push([1, 3, , 4]);
|
358
590
|
return [4 /*yield*/, this.OCClient.sessionClose(this.requestId, sessionCloseOptionalParams)];
|
359
591
|
case 2:
|
360
|
-
|
592
|
+
_m.sent();
|
361
593
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, {
|
362
594
|
RequestId: this.requestId,
|
363
595
|
ChatId: this.chatToken.chatId
|
364
596
|
});
|
365
|
-
this.conversation.disconnect();
|
597
|
+
(_c = this.conversation) === null || _c === void 0 ? void 0 : _c.disconnect();
|
366
598
|
this.conversation = null;
|
367
599
|
this.requestId = ocsdk_1.uuidv4();
|
368
600
|
this.chatToken = {};
|
369
|
-
|
370
|
-
(
|
371
|
-
(
|
372
|
-
(
|
601
|
+
this.reconnectId = null;
|
602
|
+
(_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
|
603
|
+
(_e = this.ic3ClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId('');
|
604
|
+
(_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
|
605
|
+
(_g = this.ocSdkLogger) === null || _g === void 0 ? void 0 : _g.setChatId('');
|
606
|
+
(_h = this.acsClientLogger) === null || _h === void 0 ? void 0 : _h.setRequestId(this.requestId);
|
607
|
+
(_j = this.acsClientLogger) === null || _j === void 0 ? void 0 : _j.setChatId('');
|
608
|
+
(_k = this.acsAdapterLogger) === null || _k === void 0 ? void 0 : _k.setRequestId(this.requestId);
|
609
|
+
(_l = this.acsAdapterLogger) === null || _l === void 0 ? void 0 : _l.setChatId('');
|
373
610
|
return [3 /*break*/, 4];
|
374
611
|
case 3:
|
375
|
-
|
612
|
+
error_9 = _m.sent();
|
376
613
|
exceptionDetails = {
|
377
614
|
response: "OCClientSessionCloseFailed"
|
378
615
|
};
|
@@ -381,9 +618,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
381
618
|
ChatId: this.chatToken.chatId,
|
382
619
|
ExceptionDetails: JSON.stringify(exceptionDetails),
|
383
620
|
});
|
384
|
-
console.error("OmnichannelChatSDK/endChat/error " +
|
385
|
-
return [2 /*return*/,
|
386
|
-
case 4:
|
621
|
+
console.error("OmnichannelChatSDK/endChat/error " + error_9);
|
622
|
+
return [2 /*return*/, error_9];
|
623
|
+
case 4:
|
624
|
+
if (this.refreshTokenTimer !== null) {
|
625
|
+
clearInterval(this.refreshTokenTimer);
|
626
|
+
this.refreshTokenTimer = null;
|
627
|
+
}
|
628
|
+
return [2 /*return*/];
|
387
629
|
}
|
388
630
|
});
|
389
631
|
});
|
@@ -397,6 +639,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
397
639
|
case 1:
|
398
640
|
chatToken = _a.sent();
|
399
641
|
requestId = this.requestId;
|
642
|
+
this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetCurrentLiveChatContext, {
|
643
|
+
RequestId: requestId,
|
644
|
+
ChatId: chatToken.chatId
|
645
|
+
});
|
400
646
|
chatSession = {
|
401
647
|
chatToken: chatToken,
|
402
648
|
requestId: requestId
|
@@ -404,6 +650,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
404
650
|
if (Object.keys(chatSession.chatToken).length === 0) {
|
405
651
|
return [2 /*return*/, {}];
|
406
652
|
}
|
653
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetCurrentLiveChatContext, {
|
654
|
+
RequestId: requestId,
|
655
|
+
ChatId: chatToken.chatId
|
656
|
+
});
|
407
657
|
return [2 /*return*/, chatSession];
|
408
658
|
}
|
409
659
|
});
|
@@ -412,7 +662,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
412
662
|
OmnichannelChatSDK.prototype.getConversationDetails = function () {
|
413
663
|
var _a, _b;
|
414
664
|
return __awaiter(this, void 0, void 0, function () {
|
415
|
-
var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails,
|
665
|
+
var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
|
416
666
|
return __generator(this, function (_c) {
|
417
667
|
switch (_c.label) {
|
418
668
|
case 0:
|
@@ -440,12 +690,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
440
690
|
});
|
441
691
|
return [2 /*return*/, liveWorkItemDetails];
|
442
692
|
case 3:
|
443
|
-
|
693
|
+
error_10 = _c.sent();
|
444
694
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetConversationDetails, {
|
445
695
|
RequestId: this.requestId,
|
446
696
|
ChatId: this.chatToken.chatId || '',
|
447
697
|
});
|
448
|
-
console.error("OmnichannelChatSDK/getConversationDetails/error " +
|
698
|
+
console.error("OmnichannelChatSDK/getConversationDetails/error " + error_10);
|
449
699
|
return [3 /*break*/, 4];
|
450
700
|
case 4: return [2 /*return*/, {}];
|
451
701
|
}
|
@@ -459,8 +709,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
459
709
|
OmnichannelChatSDK.prototype.getPreChatSurvey = function (parse) {
|
460
710
|
if (parse === void 0) { parse = true; }
|
461
711
|
return __awaiter(this, void 0, void 0, function () {
|
712
|
+
var result;
|
462
713
|
return __generator(this, function (_a) {
|
463
|
-
|
714
|
+
this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetPreChatSurvey);
|
715
|
+
try {
|
716
|
+
result = parse ? JSON.parse(this.preChatSurvey) : this.preChatSurvey;
|
717
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetPreChatSurvey);
|
718
|
+
return [2 /*return*/, result];
|
719
|
+
}
|
720
|
+
catch (_b) {
|
721
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPreChatSurvey);
|
722
|
+
}
|
723
|
+
return [2 /*return*/];
|
464
724
|
});
|
465
725
|
});
|
466
726
|
};
|
@@ -476,20 +736,20 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
476
736
|
});
|
477
737
|
};
|
478
738
|
OmnichannelChatSDK.prototype.getChatToken = function (cached) {
|
479
|
-
var _a;
|
739
|
+
var _a, _b;
|
480
740
|
if (cached === void 0) { cached = true; }
|
481
741
|
return __awaiter(this, void 0, void 0, function () {
|
482
|
-
var getChatTokenOptionalParams, chatToken, chatId, token, regionGtms, expiresIn, visitorId, voiceVideoCallToken,
|
483
|
-
return __generator(this, function (
|
484
|
-
switch (
|
742
|
+
var getChatTokenOptionalParams, chatToken, chatId, token, regionGtms, expiresIn, visitorId, voiceVideoCallToken, acsEndpoint, attachmentConfiguration, error_11, exceptionDetails;
|
743
|
+
return __generator(this, function (_c) {
|
744
|
+
switch (_c.label) {
|
485
745
|
case 0:
|
486
746
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetChatToken, {
|
487
747
|
RequestId: this.requestId
|
488
748
|
});
|
489
749
|
if (!!cached) return [3 /*break*/, 5];
|
490
|
-
|
750
|
+
_c.label = 1;
|
491
751
|
case 1:
|
492
|
-
|
752
|
+
_c.trys.push([1, 3, , 4]);
|
493
753
|
getChatTokenOptionalParams = {};
|
494
754
|
if (this.authenticatedUserToken) {
|
495
755
|
getChatTokenOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
|
@@ -497,10 +757,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
497
757
|
if (this.isPersistentChat && !((_a = this.chatSDKConfig.persistentChat) === null || _a === void 0 ? void 0 : _a.disable)) {
|
498
758
|
getChatTokenOptionalParams.reconnectId = this.reconnectId;
|
499
759
|
}
|
760
|
+
if (this.isChatReconnect && !((_b = this.chatSDKConfig.chatReconnect) === null || _b === void 0 ? void 0 : _b.disable) && !this.isPersistentChat) {
|
761
|
+
getChatTokenOptionalParams.reconnectId = this.reconnectId;
|
762
|
+
}
|
500
763
|
return [4 /*yield*/, this.OCClient.getChatToken(this.requestId, getChatTokenOptionalParams)];
|
501
764
|
case 2:
|
502
|
-
chatToken =
|
503
|
-
chatId = chatToken.ChatId, token = chatToken.Token, regionGtms = chatToken.RegionGtms, expiresIn = chatToken.ExpiresIn, visitorId = chatToken.VisitorId, voiceVideoCallToken = chatToken.VoiceVideoCallToken;
|
765
|
+
chatToken = _c.sent();
|
766
|
+
chatId = chatToken.ChatId, token = chatToken.Token, regionGtms = chatToken.RegionGtms, expiresIn = chatToken.ExpiresIn, visitorId = chatToken.VisitorId, voiceVideoCallToken = chatToken.VoiceVideoCallToken, acsEndpoint = chatToken.ACSEndpoint, attachmentConfiguration = chatToken.AttachmentConfiguration;
|
504
767
|
this.chatToken = {
|
505
768
|
chatId: chatId,
|
506
769
|
regionGTMS: JSON.parse(regionGtms),
|
@@ -508,15 +771,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
508
771
|
token: token,
|
509
772
|
expiresIn: expiresIn,
|
510
773
|
visitorId: visitorId,
|
511
|
-
voiceVideoCallToken: voiceVideoCallToken
|
774
|
+
voiceVideoCallToken: voiceVideoCallToken,
|
775
|
+
acsEndpoint: acsEndpoint,
|
512
776
|
};
|
777
|
+
if (attachmentConfiguration && attachmentConfiguration.AttachmentServiceEndpoint) {
|
778
|
+
this.chatToken.amsEndpoint = attachmentConfiguration.AttachmentServiceEndpoint;
|
779
|
+
}
|
513
780
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetChatToken, {
|
514
781
|
RequestId: this.requestId,
|
515
782
|
ChatId: this.chatToken.chatId
|
516
783
|
});
|
517
784
|
return [3 /*break*/, 4];
|
518
785
|
case 3:
|
519
|
-
|
786
|
+
error_11 = _c.sent();
|
520
787
|
exceptionDetails = {
|
521
788
|
response: "OCClientGetChatTokenFailed"
|
522
789
|
};
|
@@ -525,7 +792,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
525
792
|
ChatId: this.chatToken.chatId,
|
526
793
|
ExceptionDetails: JSON.stringify(exceptionDetails),
|
527
794
|
});
|
528
|
-
console.error("OmnichannelChatSDK/getChatToken/error " +
|
795
|
+
console.error("OmnichannelChatSDK/getChatToken/error " + error_11);
|
529
796
|
return [3 /*break*/, 4];
|
530
797
|
case 4: return [3 /*break*/, 6];
|
531
798
|
case 5:
|
@@ -533,7 +800,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
533
800
|
RequestId: this.requestId,
|
534
801
|
ChatId: this.chatToken.chatId
|
535
802
|
});
|
536
|
-
|
803
|
+
_c.label = 6;
|
537
804
|
case 6: return [2 /*return*/, this.chatToken];
|
538
805
|
}
|
539
806
|
});
|
@@ -546,11 +813,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
546
813
|
return [2 /*return*/, ''];
|
547
814
|
}
|
548
815
|
if (this.chatToken.voiceVideoCallToken) {
|
549
|
-
|
816
|
+
/* istanbul ignore next */
|
817
|
+
this.debug && console.log("calling:acs");
|
550
818
|
return [2 /*return*/, this.chatToken.voiceVideoCallToken.Token];
|
551
819
|
}
|
552
820
|
else {
|
553
|
-
|
821
|
+
/* istanbul ignore next */
|
822
|
+
this.debug && console.log("calling:skype");
|
554
823
|
return [2 /*return*/, this.chatToken.token];
|
555
824
|
}
|
556
825
|
return [2 /*return*/];
|
@@ -560,8 +829,34 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
560
829
|
OmnichannelChatSDK.prototype.getMessages = function () {
|
561
830
|
var _a;
|
562
831
|
return __awaiter(this, void 0, void 0, function () {
|
563
|
-
|
564
|
-
|
832
|
+
var messages, _b;
|
833
|
+
return __generator(this, function (_c) {
|
834
|
+
switch (_c.label) {
|
835
|
+
case 0:
|
836
|
+
this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetMessages, {
|
837
|
+
RequestId: this.requestId,
|
838
|
+
ChatId: this.chatToken.chatId
|
839
|
+
});
|
840
|
+
_c.label = 1;
|
841
|
+
case 1:
|
842
|
+
_c.trys.push([1, 3, , 4]);
|
843
|
+
return [4 /*yield*/, ((_a = this.conversation) === null || _a === void 0 ? void 0 : _a.getMessages())];
|
844
|
+
case 2:
|
845
|
+
messages = _c.sent();
|
846
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetMessages, {
|
847
|
+
RequestId: this.requestId,
|
848
|
+
ChatId: this.chatToken.chatId
|
849
|
+
});
|
850
|
+
return [2 /*return*/, messages];
|
851
|
+
case 3:
|
852
|
+
_b = _c.sent();
|
853
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetMessages, {
|
854
|
+
RequestId: this.requestId,
|
855
|
+
ChatId: this.chatToken.chatId
|
856
|
+
});
|
857
|
+
return [3 /*break*/, 4];
|
858
|
+
case 4: return [2 /*return*/];
|
859
|
+
}
|
565
860
|
});
|
566
861
|
});
|
567
862
|
};
|
@@ -573,129 +868,276 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
573
868
|
});
|
574
869
|
};
|
575
870
|
OmnichannelChatSDK.prototype.sendMessage = function (message) {
|
871
|
+
var _a;
|
576
872
|
return __awaiter(this, void 0, void 0, function () {
|
577
|
-
var
|
578
|
-
return __generator(this, function (
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
873
|
+
var _b, disable, maskingCharacter, content, _i, _c, maskingRule, regex, match, replaceStr, sendMessageRequest, error_12, messageToSend, _d;
|
874
|
+
return __generator(this, function (_e) {
|
875
|
+
switch (_e.label) {
|
876
|
+
case 0:
|
877
|
+
this.scenarioMarker.startScenario(TelemetryEvent_1.default.SendMessages, {
|
878
|
+
RequestId: this.requestId,
|
879
|
+
ChatId: this.chatToken.chatId
|
880
|
+
});
|
881
|
+
_b = this.chatSDKConfig.dataMasking, disable = _b.disable, maskingCharacter = _b.maskingCharacter;
|
882
|
+
content = message.content;
|
883
|
+
if (Object.keys(this.dataMaskingRules).length > 0 && !disable) {
|
884
|
+
for (_i = 0, _c = Object.values(this.dataMaskingRules); _i < _c.length; _i++) {
|
885
|
+
maskingRule = _c[_i];
|
886
|
+
regex = new RegExp(maskingRule, 'g');
|
887
|
+
match = void 0;
|
888
|
+
while (match = regex.exec(content)) { // eslint-disable-line no-cond-assign
|
889
|
+
replaceStr = match[0].replace(/./g, maskingCharacter);
|
890
|
+
content = content.replace(match[0], replaceStr);
|
891
|
+
}
|
892
|
+
}
|
589
893
|
}
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
894
|
+
message.content = content;
|
895
|
+
if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 5];
|
896
|
+
sendMessageRequest = {
|
897
|
+
content: message.content,
|
898
|
+
};
|
899
|
+
_e.label = 1;
|
900
|
+
case 1:
|
901
|
+
_e.trys.push([1, 3, , 4]);
|
902
|
+
return [4 /*yield*/, ((_a = this.conversation) === null || _a === void 0 ? void 0 : _a.sendMessage(sendMessageRequest))];
|
903
|
+
case 2:
|
904
|
+
_e.sent();
|
905
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendMessages, {
|
906
|
+
RequestId: this.requestId,
|
907
|
+
ChatId: this.chatToken.chatId
|
908
|
+
});
|
909
|
+
return [3 /*break*/, 4];
|
910
|
+
case 3:
|
911
|
+
error_12 = _e.sent();
|
912
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendMessages, {
|
913
|
+
RequestId: this.requestId,
|
914
|
+
ChatId: this.chatToken.chatId
|
915
|
+
});
|
916
|
+
throw new Error('ChatSDKSendMessageFailed');
|
917
|
+
case 4: return [3 /*break*/, 9];
|
918
|
+
case 5:
|
919
|
+
messageToSend = {
|
920
|
+
content: message.content,
|
921
|
+
timestamp: new Date(),
|
922
|
+
contentType: MessageContentType_1.default.Text,
|
923
|
+
deliveryMode: DeliveryMode_1.default.Bridged,
|
924
|
+
messageType: MessageType_1.default.UserMessage,
|
925
|
+
properties: undefined,
|
926
|
+
tags: __spreadArrays(MessageTags_1.defaultMessageTags),
|
927
|
+
sender: {
|
928
|
+
displayName: "Customer",
|
929
|
+
id: "customer",
|
930
|
+
type: PersonType_1.default.User
|
931
|
+
}
|
932
|
+
};
|
933
|
+
if (message.tags) {
|
934
|
+
messageToSend.tags = message.tags;
|
935
|
+
}
|
936
|
+
if (message.timestamp) {
|
937
|
+
messageToSend.timestamp = message.timestamp;
|
938
|
+
}
|
939
|
+
_e.label = 6;
|
940
|
+
case 6:
|
941
|
+
_e.trys.push([6, 8, , 9]);
|
942
|
+
return [4 /*yield*/, this.conversation.sendMessage(messageToSend)];
|
943
|
+
case 7:
|
944
|
+
_e.sent();
|
945
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendMessages, {
|
946
|
+
RequestId: this.requestId,
|
947
|
+
ChatId: this.chatToken.chatId
|
948
|
+
});
|
949
|
+
return [3 /*break*/, 9];
|
950
|
+
case 8:
|
951
|
+
_d = _e.sent();
|
952
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendMessages, {
|
953
|
+
RequestId: this.requestId,
|
954
|
+
ChatId: this.chatToken.chatId
|
955
|
+
});
|
956
|
+
throw new Error('ChatSDKSendMessageFailed');
|
957
|
+
case 9: return [2 /*return*/];
|
612
958
|
}
|
613
|
-
return [2 /*return*/, this.conversation.sendMessage(messageToSend)];
|
614
959
|
});
|
615
960
|
});
|
616
961
|
};
|
617
962
|
OmnichannelChatSDK.prototype.onNewMessage = function (onNewMessageCallback, optionalParams) {
|
618
|
-
var _a;
|
963
|
+
var _a, _b;
|
619
964
|
if (optionalParams === void 0) { optionalParams = {}; }
|
620
965
|
return __awaiter(this, void 0, void 0, function () {
|
621
|
-
var
|
622
|
-
|
623
|
-
|
966
|
+
var postedMessages_1, messages, _i, _c, message, id, postedMessages_2, messages, _d, _e, message, clientmessageid, omnichannelMessage;
|
967
|
+
var _this = this;
|
968
|
+
return __generator(this, function (_f) {
|
969
|
+
switch (_f.label) {
|
624
970
|
case 0:
|
625
|
-
|
971
|
+
this.scenarioMarker.startScenario(TelemetryEvent_1.default.OnNewMessage, {
|
972
|
+
RequestId: this.requestId,
|
973
|
+
ChatId: this.chatToken.chatId
|
974
|
+
});
|
975
|
+
if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 3];
|
976
|
+
postedMessages_1 = new Set();
|
626
977
|
if (!optionalParams.rehydrate) return [3 /*break*/, 2];
|
627
978
|
this.debug && console.log('[OmnichannelChatSDK][onNewMessage] rehydrate');
|
628
979
|
return [4 /*yield*/, this.getMessages()];
|
629
980
|
case 1:
|
630
|
-
messages =
|
631
|
-
for (_i = 0,
|
632
|
-
message =
|
633
|
-
|
634
|
-
if (
|
981
|
+
messages = _f.sent();
|
982
|
+
for (_i = 0, _c = messages.reverse(); _i < _c.length; _i++) {
|
983
|
+
message = _c[_i];
|
984
|
+
id = message.id;
|
985
|
+
if (postedMessages_1.has(id)) {
|
635
986
|
continue;
|
636
987
|
}
|
637
|
-
|
988
|
+
postedMessages_1.add(id);
|
638
989
|
onNewMessageCallback(message);
|
639
990
|
}
|
640
|
-
|
991
|
+
_f.label = 2;
|
641
992
|
case 2:
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
993
|
+
try {
|
994
|
+
(_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnNewMessage(function (event) {
|
995
|
+
var id = event.id;
|
996
|
+
var omnichannelMessage = createOmnichannelMessage_1.default(event, {
|
997
|
+
liveChatVersion: _this.liveChatVersion,
|
998
|
+
debug: _this.debug
|
999
|
+
});
|
1000
|
+
if (!postedMessages_1.has(id)) {
|
1001
|
+
onNewMessageCallback(omnichannelMessage);
|
1002
|
+
postedMessages_1.add(id);
|
1003
|
+
}
|
1004
|
+
});
|
1005
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnNewMessage, {
|
1006
|
+
RequestId: this.requestId,
|
1007
|
+
ChatId: this.chatToken.chatId
|
1008
|
+
});
|
1009
|
+
}
|
1010
|
+
catch (_g) {
|
1011
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnNewMessage, {
|
1012
|
+
RequestId: this.requestId,
|
1013
|
+
ChatId: this.chatToken.chatId
|
1014
|
+
});
|
1015
|
+
}
|
1016
|
+
return [3 /*break*/, 6];
|
1017
|
+
case 3:
|
1018
|
+
postedMessages_2 = new Set();
|
1019
|
+
if (!optionalParams.rehydrate) return [3 /*break*/, 5];
|
1020
|
+
this.debug && console.log('[OmnichannelChatSDK][onNewMessage] rehydrate');
|
1021
|
+
return [4 /*yield*/, this.getMessages()];
|
1022
|
+
case 4:
|
1023
|
+
messages = _f.sent();
|
1024
|
+
if (messages) {
|
1025
|
+
for (_d = 0, _e = messages.reverse(); _d < _e.length; _d++) {
|
1026
|
+
message = _e[_d];
|
1027
|
+
clientmessageid = message.clientmessageid;
|
1028
|
+
if (postedMessages_2.has(clientmessageid)) {
|
1029
|
+
continue;
|
1030
|
+
}
|
1031
|
+
postedMessages_2.add(clientmessageid);
|
1032
|
+
omnichannelMessage = createOmnichannelMessage_1.default(message, {
|
1033
|
+
liveChatVersion: this.liveChatVersion,
|
1034
|
+
debug: this.debug
|
1035
|
+
});
|
1036
|
+
onNewMessageCallback(omnichannelMessage);
|
654
1037
|
}
|
655
|
-
}
|
656
|
-
|
1038
|
+
}
|
1039
|
+
_f.label = 5;
|
1040
|
+
case 5:
|
1041
|
+
try {
|
1042
|
+
(_b = this.conversation) === null || _b === void 0 ? void 0 : _b.registerOnNewMessage(function (message) {
|
1043
|
+
var clientmessageid = message.clientmessageid, messageType = message.messageType;
|
1044
|
+
// Filter out customer messages
|
1045
|
+
if (utilities_1.isCustomerMessage(message)) {
|
1046
|
+
return;
|
1047
|
+
}
|
1048
|
+
// Skip duplicates
|
1049
|
+
if (postedMessages_2.has(clientmessageid)) {
|
1050
|
+
return;
|
1051
|
+
}
|
1052
|
+
if (messageType !== MessageType_1.default.Typing) {
|
1053
|
+
var omnichannelMessage = createOmnichannelMessage_1.default(message, {
|
1054
|
+
liveChatVersion: _this.liveChatVersion,
|
1055
|
+
debug: _this.debug
|
1056
|
+
});
|
1057
|
+
onNewMessageCallback(omnichannelMessage);
|
1058
|
+
}
|
1059
|
+
});
|
1060
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnNewMessage, {
|
1061
|
+
RequestId: this.requestId,
|
1062
|
+
ChatId: this.chatToken.chatId
|
1063
|
+
});
|
1064
|
+
}
|
1065
|
+
catch (_h) {
|
1066
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnNewMessage, {
|
1067
|
+
RequestId: this.requestId,
|
1068
|
+
ChatId: this.chatToken.chatId
|
1069
|
+
});
|
1070
|
+
}
|
1071
|
+
_f.label = 6;
|
1072
|
+
case 6: return [2 /*return*/];
|
657
1073
|
}
|
658
1074
|
});
|
659
1075
|
});
|
660
1076
|
};
|
661
1077
|
OmnichannelChatSDK.prototype.sendTypingEvent = function () {
|
662
1078
|
return __awaiter(this, void 0, void 0, function () {
|
663
|
-
var typingPayload, members, botMembers,
|
1079
|
+
var error_13, typingPayload, members, botMembers, error_14;
|
664
1080
|
return __generator(this, function (_a) {
|
665
1081
|
switch (_a.label) {
|
666
1082
|
case 0:
|
667
|
-
typingPayload = "{isTyping: 0}";
|
668
1083
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.SendTypingEvent, {
|
669
1084
|
RequestId: this.requestId,
|
670
1085
|
ChatId: this.chatToken.chatId
|
671
1086
|
});
|
1087
|
+
if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 6];
|
672
1088
|
_a.label = 1;
|
673
1089
|
case 1:
|
674
|
-
_a.trys.push([1,
|
675
|
-
return [4 /*yield*/, this.
|
1090
|
+
_a.trys.push([1, 4, , 5]);
|
1091
|
+
return [4 /*yield*/, this.OCClient.sendTypingIndicator(this.requestId, LiveChatVersion_1.default.V2, {
|
1092
|
+
customerDisplayName: ACSParticipantDisplayName_1.default.Customer
|
1093
|
+
})];
|
676
1094
|
case 2:
|
677
1095
|
_a.sent();
|
678
|
-
return [4 /*yield*/, this.conversation.
|
1096
|
+
return [4 /*yield*/, this.conversation.sendTyping()];
|
679
1097
|
case 3:
|
1098
|
+
_a.sent();
|
1099
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendTypingEvent, {
|
1100
|
+
RequestId: this.requestId,
|
1101
|
+
ChatId: this.chatToken.chatId
|
1102
|
+
});
|
1103
|
+
return [3 /*break*/, 5];
|
1104
|
+
case 4:
|
1105
|
+
error_13 = _a.sent();
|
1106
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
|
1107
|
+
RequestId: this.requestId,
|
1108
|
+
ChatId: this.chatToken.chatId
|
1109
|
+
});
|
1110
|
+
throw new Error('OCClientSendTypingFailed');
|
1111
|
+
case 5: return [3 /*break*/, 12];
|
1112
|
+
case 6:
|
1113
|
+
typingPayload = "{isTyping: 0}";
|
1114
|
+
_a.label = 7;
|
1115
|
+
case 7:
|
1116
|
+
_a.trys.push([7, 11, , 12]);
|
1117
|
+
return [4 /*yield*/, this.conversation.indicateTypingStatus(0)];
|
1118
|
+
case 8:
|
1119
|
+
_a.sent();
|
1120
|
+
return [4 /*yield*/, this.conversation.getMembers()];
|
1121
|
+
case 9:
|
680
1122
|
members = _a.sent();
|
681
1123
|
botMembers = members.filter(function (member) { return member.type === PersonType_1.default.Bot; });
|
682
1124
|
return [4 /*yield*/, this.conversation.sendMessageToBot(botMembers[0].id, { payload: typingPayload })];
|
683
|
-
case
|
1125
|
+
case 10:
|
684
1126
|
_a.sent();
|
685
1127
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendTypingEvent, {
|
686
1128
|
RequestId: this.requestId,
|
687
1129
|
ChatId: this.chatToken.chatId
|
688
1130
|
});
|
689
|
-
return [3 /*break*/,
|
690
|
-
case
|
691
|
-
|
1131
|
+
return [3 /*break*/, 12];
|
1132
|
+
case 11:
|
1133
|
+
error_14 = _a.sent();
|
692
1134
|
console.error("OmnichannelChatSDK/sendTypingEvent/error");
|
693
1135
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
|
694
1136
|
RequestId: this.requestId,
|
695
1137
|
ChatId: this.chatToken.chatId
|
696
1138
|
});
|
697
|
-
return [2 /*return*/,
|
698
|
-
case
|
1139
|
+
return [2 /*return*/, error_14];
|
1140
|
+
case 12: return [2 /*return*/];
|
699
1141
|
}
|
700
1142
|
});
|
701
1143
|
});
|
@@ -704,16 +1146,49 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
704
1146
|
var _a;
|
705
1147
|
return __awaiter(this, void 0, void 0, function () {
|
706
1148
|
return __generator(this, function (_b) {
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
1149
|
+
this.scenarioMarker.startScenario(TelemetryEvent_1.default.OnTypingEvent, {
|
1150
|
+
RequestId: this.requestId,
|
1151
|
+
ChatId: this.chatToken.chatId
|
1152
|
+
});
|
1153
|
+
if (this.liveChatVersion === LiveChatVersion_1.default.V2) {
|
1154
|
+
try {
|
1155
|
+
this.conversation.onTypingEvent(onTypingEventCallback);
|
1156
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnTypingEvent, {
|
1157
|
+
RequestId: this.requestId,
|
1158
|
+
ChatId: this.chatToken.chatId
|
1159
|
+
});
|
712
1160
|
}
|
713
|
-
|
714
|
-
|
1161
|
+
catch (_c) {
|
1162
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnTypingEvent, {
|
1163
|
+
RequestId: this.requestId,
|
1164
|
+
ChatId: this.chatToken.chatId
|
1165
|
+
});
|
715
1166
|
}
|
716
|
-
}
|
1167
|
+
}
|
1168
|
+
else {
|
1169
|
+
try {
|
1170
|
+
(_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnNewMessage(function (message) {
|
1171
|
+
var messageType = message.messageType;
|
1172
|
+
// Filter out customer messages
|
1173
|
+
if (utilities_1.isCustomerMessage(message)) {
|
1174
|
+
return;
|
1175
|
+
}
|
1176
|
+
if (messageType === MessageType_1.default.Typing) {
|
1177
|
+
onTypingEventCallback(message);
|
1178
|
+
}
|
1179
|
+
});
|
1180
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnTypingEvent, {
|
1181
|
+
RequestId: this.requestId,
|
1182
|
+
ChatId: this.chatToken.chatId
|
1183
|
+
});
|
1184
|
+
}
|
1185
|
+
catch (_d) {
|
1186
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnTypingEvent, {
|
1187
|
+
RequestId: this.requestId,
|
1188
|
+
ChatId: this.chatToken.chatId
|
1189
|
+
});
|
1190
|
+
}
|
1191
|
+
}
|
717
1192
|
return [2 /*return*/];
|
718
1193
|
});
|
719
1194
|
});
|
@@ -721,61 +1196,143 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
721
1196
|
OmnichannelChatSDK.prototype.onAgentEndSession = function (onAgentEndSessionCallback) {
|
722
1197
|
var _a;
|
723
1198
|
return __awaiter(this, void 0, void 0, function () {
|
1199
|
+
var _this = this;
|
724
1200
|
return __generator(this, function (_b) {
|
725
1201
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.OnAgentEndSession, {
|
726
1202
|
RequestId: this.requestId,
|
727
1203
|
ChatId: this.chatToken.chatId
|
728
1204
|
});
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
1205
|
+
if (this.liveChatVersion === LiveChatVersion_1.default.V2) {
|
1206
|
+
try {
|
1207
|
+
this.conversation.registerOnThreadUpdate(function (event) {
|
1208
|
+
onAgentEndSessionCallback(event);
|
1209
|
+
});
|
1210
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
|
1211
|
+
RequestId: this.requestId,
|
1212
|
+
ChatId: this.chatToken.chatId
|
1213
|
+
});
|
1214
|
+
}
|
1215
|
+
catch (error) {
|
1216
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
|
1217
|
+
RequestId: this.requestId,
|
1218
|
+
ChatId: this.chatToken.chatId
|
1219
|
+
});
|
1220
|
+
}
|
741
1221
|
}
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
1222
|
+
else {
|
1223
|
+
try {
|
1224
|
+
(_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnThreadUpdate(function (message) {
|
1225
|
+
var members = message.members;
|
1226
|
+
// Agent ending conversation would have 1 member left in the chat thread
|
1227
|
+
if (members.length === 1) {
|
1228
|
+
onAgentEndSessionCallback(message);
|
1229
|
+
if (_this.refreshTokenTimer !== null) {
|
1230
|
+
clearInterval(_this.refreshTokenTimer);
|
1231
|
+
_this.refreshTokenTimer = null;
|
1232
|
+
}
|
1233
|
+
}
|
1234
|
+
});
|
1235
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
|
1236
|
+
RequestId: this.requestId,
|
1237
|
+
ChatId: this.chatToken.chatId
|
1238
|
+
});
|
1239
|
+
}
|
1240
|
+
catch (error) {
|
1241
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
|
1242
|
+
RequestId: this.requestId,
|
1243
|
+
ChatId: this.chatToken.chatId
|
1244
|
+
});
|
1245
|
+
}
|
747
1246
|
}
|
748
1247
|
return [2 /*return*/];
|
749
1248
|
});
|
750
1249
|
});
|
751
1250
|
};
|
752
1251
|
OmnichannelChatSDK.prototype.uploadFileAttachment = function (fileInfo) {
|
1252
|
+
var _a, _b, _c, _d;
|
753
1253
|
return __awaiter(this, void 0, void 0, function () {
|
754
|
-
var fileMetadata, messageToSend,
|
755
|
-
return __generator(this, function (
|
756
|
-
switch (
|
1254
|
+
var createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_15, fileMetadata, messageToSend, error_16;
|
1255
|
+
return __generator(this, function (_e) {
|
1256
|
+
switch (_e.label) {
|
757
1257
|
case 0:
|
758
1258
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.UploadFileAttachment, {
|
759
1259
|
RequestId: this.requestId,
|
760
1260
|
ChatId: this.chatToken.chatId
|
761
1261
|
});
|
762
|
-
if (!(
|
763
|
-
return [4 /*yield*/, this.
|
1262
|
+
if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 7];
|
1263
|
+
return [4 /*yield*/, ((_a = this.AMSClient) === null || _a === void 0 ? void 0 : _a.createObject((_b = this.chatToken) === null || _b === void 0 ? void 0 : _b.chatId, fileInfo))];
|
764
1264
|
case 1:
|
765
|
-
|
766
|
-
|
767
|
-
|
1265
|
+
createObjectResponse = _e.sent();
|
1266
|
+
documentId = createObjectResponse.id;
|
1267
|
+
return [4 /*yield*/, ((_c = this.AMSClient) === null || _c === void 0 ? void 0 : _c.uploadDocument(documentId, fileInfo))];
|
1268
|
+
case 2:
|
1269
|
+
uploadDocumentResponse = _e.sent();
|
1270
|
+
fileIdsProperty = {
|
1271
|
+
amsReferences: JSON.stringify([documentId])
|
1272
|
+
};
|
1273
|
+
fileMetaProperty = {
|
1274
|
+
amsMetadata: JSON.stringify([{
|
1275
|
+
contentType: fileInfo.type,
|
1276
|
+
fileName: fileInfo.name
|
1277
|
+
}])
|
1278
|
+
};
|
1279
|
+
sendMessageRequest = {
|
1280
|
+
content: '',
|
1281
|
+
metadata: __assign(__assign({}, fileIdsProperty), fileMetaProperty)
|
1282
|
+
};
|
1283
|
+
messageToSend = {
|
1284
|
+
content: "",
|
1285
|
+
timestamp: new Date(),
|
1286
|
+
contentType: MessageContentType_1.default.Text,
|
1287
|
+
deliveryMode: DeliveryMode_1.default.Bridged,
|
1288
|
+
messageType: MessageType_1.default.UserMessage,
|
1289
|
+
tags: __spreadArrays(MessageTags_1.defaultMessageTags),
|
1290
|
+
sender: {
|
1291
|
+
displayName: "Customer",
|
1292
|
+
id: "customer",
|
1293
|
+
type: PersonType_1.default.User,
|
1294
|
+
},
|
1295
|
+
fileMetadata: uploadDocumentResponse
|
1296
|
+
};
|
1297
|
+
_e.label = 3;
|
768
1298
|
case 3:
|
769
|
-
|
770
|
-
|
1299
|
+
_e.trys.push([3, 5, , 6]);
|
1300
|
+
return [4 /*yield*/, ((_d = this.conversation) === null || _d === void 0 ? void 0 : _d.sendMessage(sendMessageRequest))];
|
771
1301
|
case 4:
|
1302
|
+
_e.sent();
|
1303
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.UploadFileAttachment, {
|
1304
|
+
RequestId: this.requestId,
|
1305
|
+
ChatId: this.chatToken.chatId
|
1306
|
+
});
|
1307
|
+
return [2 /*return*/, messageToSend];
|
1308
|
+
case 5:
|
1309
|
+
error_15 = _e.sent();
|
1310
|
+
console.error("OmnichannelChatSDK/uploadFileAttachment/sendMessage/error");
|
1311
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
|
1312
|
+
RequestId: this.requestId,
|
1313
|
+
ChatId: this.chatToken.chatId
|
1314
|
+
});
|
1315
|
+
return [3 /*break*/, 6];
|
1316
|
+
case 6: return [2 /*return*/, {}];
|
1317
|
+
case 7:
|
1318
|
+
fileMetadata = void 0;
|
1319
|
+
if (!(platform_1.default.isReactNative() || platform_1.default.isNode())) return [3 /*break*/, 9];
|
1320
|
+
return [4 /*yield*/, this.conversation.sendFileData(fileInfo, FileSharingProtocolType_1.default.AmsBasedFileSharing)];
|
1321
|
+
case 8:
|
1322
|
+
fileMetadata = _e.sent();
|
1323
|
+
return [3 /*break*/, 11];
|
1324
|
+
case 9: return [4 /*yield*/, this.conversation.uploadFile(fileInfo, FileSharingProtocolType_1.default.AmsBasedFileSharing)];
|
1325
|
+
case 10:
|
1326
|
+
fileMetadata = _e.sent();
|
1327
|
+
_e.label = 11;
|
1328
|
+
case 11:
|
772
1329
|
messageToSend = {
|
773
1330
|
content: "",
|
774
1331
|
timestamp: new Date(),
|
775
1332
|
contentType: MessageContentType_1.default.Text,
|
776
1333
|
deliveryMode: DeliveryMode_1.default.Bridged,
|
777
1334
|
messageType: MessageType_1.default.UserMessage,
|
778
|
-
tags:
|
1335
|
+
tags: __spreadArrays(MessageTags_1.defaultMessageTags),
|
779
1336
|
sender: {
|
780
1337
|
displayName: "Customer",
|
781
1338
|
id: "customer",
|
@@ -783,60 +1340,84 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
783
1340
|
},
|
784
1341
|
fileMetadata: fileMetadata
|
785
1342
|
};
|
786
|
-
|
787
|
-
case
|
788
|
-
|
1343
|
+
_e.label = 12;
|
1344
|
+
case 12:
|
1345
|
+
_e.trys.push([12, 14, , 15]);
|
789
1346
|
return [4 /*yield*/, this.conversation.sendFileMessage(fileMetadata, messageToSend)];
|
790
|
-
case
|
791
|
-
|
1347
|
+
case 13:
|
1348
|
+
_e.sent();
|
792
1349
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.UploadFileAttachment, {
|
793
1350
|
RequestId: this.requestId,
|
794
1351
|
ChatId: this.chatToken.chatId
|
795
1352
|
});
|
796
1353
|
return [2 /*return*/, messageToSend];
|
797
|
-
case
|
798
|
-
|
799
|
-
console.error("OmnichannelChatSDK/uploadFileAttachment/error: " +
|
1354
|
+
case 14:
|
1355
|
+
error_16 = _e.sent();
|
1356
|
+
console.error("OmnichannelChatSDK/uploadFileAttachment/error: " + error_16);
|
800
1357
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
|
801
1358
|
RequestId: this.requestId,
|
802
1359
|
ChatId: this.chatToken.chatId
|
803
1360
|
});
|
804
|
-
return [2 /*return*/,
|
805
|
-
case
|
1361
|
+
return [2 /*return*/, error_16];
|
1362
|
+
case 15: return [2 /*return*/];
|
806
1363
|
}
|
807
1364
|
});
|
808
1365
|
});
|
809
1366
|
};
|
810
1367
|
OmnichannelChatSDK.prototype.downloadFileAttachment = function (fileMetadata) {
|
1368
|
+
var _a, _b;
|
811
1369
|
return __awaiter(this, void 0, void 0, function () {
|
812
|
-
var downloadedFile,
|
813
|
-
return __generator(this, function (
|
814
|
-
switch (
|
1370
|
+
var response, view_location, viewResponse, _c, downloadedFile, error_17;
|
1371
|
+
return __generator(this, function (_d) {
|
1372
|
+
switch (_d.label) {
|
815
1373
|
case 0:
|
816
1374
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
|
817
1375
|
RequestId: this.requestId,
|
818
1376
|
ChatId: this.chatToken.chatId
|
819
1377
|
});
|
820
|
-
|
1378
|
+
if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 6];
|
1379
|
+
_d.label = 1;
|
821
1380
|
case 1:
|
822
|
-
|
823
|
-
return [4 /*yield*/, this.
|
1381
|
+
_d.trys.push([1, 4, , 5]);
|
1382
|
+
return [4 /*yield*/, ((_a = this.AMSClient) === null || _a === void 0 ? void 0 : _a.getViewStatus(fileMetadata))];
|
824
1383
|
case 2:
|
825
|
-
|
1384
|
+
response = _d.sent();
|
1385
|
+
view_location = response.view_location;
|
1386
|
+
return [4 /*yield*/, ((_b = this.AMSClient) === null || _b === void 0 ? void 0 : _b.getView(fileMetadata, view_location))];
|
1387
|
+
case 3:
|
1388
|
+
viewResponse = _d.sent();
|
1389
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
|
1390
|
+
RequestId: this.requestId,
|
1391
|
+
ChatId: this.chatToken.chatId
|
1392
|
+
});
|
1393
|
+
return [2 /*return*/, viewResponse];
|
1394
|
+
case 4:
|
1395
|
+
_c = _d.sent();
|
1396
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
|
1397
|
+
RequestId: this.requestId,
|
1398
|
+
ChatId: this.chatToken.chatId
|
1399
|
+
});
|
1400
|
+
throw new Error('DownloadFileAttachmentFailed');
|
1401
|
+
case 5: return [3 /*break*/, 9];
|
1402
|
+
case 6:
|
1403
|
+
_d.trys.push([6, 8, , 9]);
|
1404
|
+
return [4 /*yield*/, this.conversation.downloadFile(fileMetadata)];
|
1405
|
+
case 7:
|
1406
|
+
downloadedFile = _d.sent();
|
826
1407
|
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
|
827
1408
|
RequestId: this.requestId,
|
828
1409
|
ChatId: this.chatToken.chatId
|
829
1410
|
});
|
830
1411
|
return [2 /*return*/, downloadedFile];
|
831
|
-
case
|
832
|
-
|
833
|
-
console.error("OmnichannelChatSDK/downloadFileAttachment/error: " +
|
1412
|
+
case 8:
|
1413
|
+
error_17 = _d.sent();
|
1414
|
+
console.error("OmnichannelChatSDK/downloadFileAttachment/error: " + error_17);
|
834
1415
|
this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
|
835
1416
|
RequestId: this.requestId,
|
836
1417
|
ChatId: this.chatToken.chatId
|
837
1418
|
});
|
838
1419
|
throw new Error('DownloadFileAttachmentFailed');
|
839
|
-
case
|
1420
|
+
case 9: return [2 /*return*/];
|
840
1421
|
}
|
841
1422
|
});
|
842
1423
|
});
|
@@ -909,51 +1490,98 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
909
1490
|
});
|
910
1491
|
};
|
911
1492
|
OmnichannelChatSDK.prototype.createChatAdapter = function (protocol) {
|
912
|
-
if (protocol === void 0) { protocol =
|
1493
|
+
if (protocol === void 0) { protocol = null; }
|
913
1494
|
return __awaiter(this, void 0, void 0, function () {
|
1495
|
+
var supportedChatAdapterProtocols;
|
914
1496
|
var _this = this;
|
915
1497
|
return __generator(this, function (_a) {
|
916
1498
|
if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
|
917
1499
|
return [2 /*return*/, Promise.reject('ChatAdapter is only supported on browser')];
|
918
1500
|
}
|
919
|
-
|
1501
|
+
supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
|
1502
|
+
if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
|
920
1503
|
return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
|
921
1504
|
}
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
1505
|
+
if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
|
1506
|
+
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
1507
|
+
var featuresOption, acsAdapterCDNUrl;
|
1508
|
+
var _this = this;
|
1509
|
+
var _a;
|
1510
|
+
return __generator(this, function (_b) {
|
1511
|
+
switch (_b.label) {
|
1512
|
+
case 0:
|
1513
|
+
featuresOption = {
|
1514
|
+
enableAdaptiveCards: false,
|
1515
|
+
enableThreadMemberUpdateNotification: true,
|
1516
|
+
enableLeaveThreadOnWindowClosed: false
|
1517
|
+
};
|
1518
|
+
acsAdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.ACS);
|
1519
|
+
(_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
|
1520
|
+
ACSAdapter: acsAdapterCDNUrl
|
1521
|
+
});
|
1522
|
+
return [4 /*yield*/, WebUtils_1.loadScript(acsAdapterCDNUrl, function () {
|
1523
|
+
/* istanbul ignore next */
|
1524
|
+
_this.debug && console.debug('ACSAdapter loaded!');
|
1525
|
+
try {
|
1526
|
+
var ChatAdapter = window.ChatAdapter; // eslint-disable-line @typescript-eslint/no-explicit-any
|
1527
|
+
var fileManager = new AMSFileManager_1.default(_this.AMSClient, _this.acsAdapterLogger);
|
1528
|
+
var adapter = ChatAdapter.createACSAdapter(_this.chatToken.token, _this.chatToken.visitorId || 'teamsvisitor', _this.chatToken.chatId, _this.chatToken.acsEndpoint, fileManager, 1000, ACSParticipantDisplayName_1.default.Customer, undefined, featuresOption);
|
1529
|
+
resolve(adapter);
|
1530
|
+
}
|
1531
|
+
catch (_a) {
|
1532
|
+
throw new Error('Failed to load ACSAdapter');
|
1533
|
+
}
|
1534
|
+
}, function () {
|
1535
|
+
reject('Failed to load ACSADapter');
|
1536
|
+
})];
|
1537
|
+
case 1:
|
1538
|
+
_b.sent();
|
1539
|
+
return [2 /*return*/];
|
1540
|
+
}
|
1541
|
+
});
|
1542
|
+
}); })];
|
1543
|
+
}
|
1544
|
+
else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
|
1545
|
+
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
1546
|
+
var ic3AdapterCDNUrl;
|
1547
|
+
var _this = this;
|
1548
|
+
var _a;
|
1549
|
+
return __generator(this, function (_b) {
|
1550
|
+
switch (_b.label) {
|
1551
|
+
case 0:
|
1552
|
+
ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.IC3);
|
1553
|
+
(_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
|
1554
|
+
IC3Adapter: ic3AdapterCDNUrl
|
1555
|
+
});
|
1556
|
+
this.scenarioMarker.startScenario(TelemetryEvent_1.default.CreateIC3Adapter);
|
1557
|
+
return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
|
1558
|
+
/* istanbul ignore next */
|
1559
|
+
_this.debug && console.debug('IC3Adapter loaded!');
|
1560
|
+
var adapterConfig = {
|
1561
|
+
chatToken: _this.chatToken,
|
1562
|
+
userDisplayName: 'Customer',
|
1563
|
+
userId: 'teamsvisitor',
|
1564
|
+
sdkURL: _this.resolveIC3ClientUrl(),
|
1565
|
+
sdk: _this.IC3Client
|
1566
|
+
};
|
1567
|
+
var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
|
1568
|
+
adapter.logger = _this.ic3ClientLogger;
|
1569
|
+
// Keep iframe communication alive to reuse the same IC3Client instance
|
1570
|
+
window.Microsoft.BotFramework.WebChat.IC3SDKProvider.disposeSdk = function () { }; // eslint-disable-line @typescript-eslint/no-empty-function
|
1571
|
+
_this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
|
1572
|
+
resolve(adapter);
|
1573
|
+
}, function () {
|
1574
|
+
_this.scenarioMarker.failScenario(TelemetryEvent_1.default.CreateIC3Adapter);
|
1575
|
+
reject('Failed to load IC3Adapter');
|
1576
|
+
})];
|
1577
|
+
case 1:
|
1578
|
+
_b.sent();
|
1579
|
+
return [2 /*return*/];
|
1580
|
+
}
|
1581
|
+
});
|
1582
|
+
}); })];
|
1583
|
+
}
|
1584
|
+
return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
|
957
1585
|
});
|
958
1586
|
});
|
959
1587
|
};
|
@@ -980,33 +1608,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
980
1608
|
result = msdyn_widgetsnippet.match(widgetSnippetSourceRegex);
|
981
1609
|
if (result && result.length) {
|
982
1610
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
983
|
-
var
|
1611
|
+
var LiveChatWidgetLibCDNUrl;
|
984
1612
|
var _this = this;
|
985
|
-
var _a
|
986
|
-
return __generator(this, function (
|
987
|
-
switch (
|
1613
|
+
var _a;
|
1614
|
+
return __generator(this, function (_b) {
|
1615
|
+
switch (_b.label) {
|
988
1616
|
case 0:
|
989
|
-
spoolSDKCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/spool-sdk/sdk.bundle.js";
|
990
|
-
(_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
|
991
|
-
SpoolSDK: spoolSDKCDNUrl
|
992
|
-
});
|
993
1617
|
this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
|
994
|
-
|
995
|
-
|
996
|
-
_this.debug && console.debug(spoolSDKCDNUrl + " loaded!");
|
997
|
-
}, function () {
|
998
|
-
var exceptionDetails = {
|
999
|
-
response: "SpoolSDKLoadFailed"
|
1000
|
-
};
|
1001
|
-
_this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
|
1002
|
-
ExceptionDetails: JSON.stringify(exceptionDetails)
|
1003
|
-
});
|
1004
|
-
reject('Failed to load SpoolSDK');
|
1005
|
-
})];
|
1006
|
-
case 1:
|
1007
|
-
_c.sent();
|
1008
|
-
LiveChatWidgetLibCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/LiveChatWidgetLibs.min.js";
|
1009
|
-
(_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.setCDNPackages({
|
1618
|
+
LiveChatWidgetLibCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/CallingBundle.js";
|
1619
|
+
(_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
|
1010
1620
|
VoiceVideoCalling: LiveChatWidgetLibCDNUrl
|
1011
1621
|
});
|
1012
1622
|
return [4 /*yield*/, WebUtils_1.loadScript(LiveChatWidgetLibCDNUrl, function () { return __awaiter(_this, void 0, void 0, function () {
|
@@ -1037,8 +1647,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1037
1647
|
return [2 /*return*/];
|
1038
1648
|
});
|
1039
1649
|
}); })];
|
1040
|
-
case
|
1041
|
-
|
1650
|
+
case 1:
|
1651
|
+
_b.sent();
|
1042
1652
|
return [2 /*return*/];
|
1043
1653
|
}
|
1044
1654
|
});
|
@@ -1134,15 +1744,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1134
1744
|
};
|
1135
1745
|
OmnichannelChatSDK.prototype.getChatConfig = function () {
|
1136
1746
|
return __awaiter(this, void 0, void 0, function () {
|
1137
|
-
var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, isPreChatEnabled, token,
|
1138
|
-
return __generator(this, function (
|
1139
|
-
switch (
|
1747
|
+
var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, token, exceptionDetails, _a, exceptionDetails, exceptionDetails, error_18;
|
1748
|
+
return __generator(this, function (_b) {
|
1749
|
+
switch (_b.label) {
|
1140
1750
|
case 0:
|
1141
|
-
|
1751
|
+
_b.trys.push([0, 8, , 9]);
|
1142
1752
|
return [4 /*yield*/, this.OCClient.getChatConfig()];
|
1143
1753
|
case 1:
|
1144
|
-
liveChatConfig =
|
1145
|
-
dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin;
|
1754
|
+
liveChatConfig = _b.sent();
|
1755
|
+
dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion;
|
1756
|
+
this.liveChatVersion = liveChatVersion || LiveChatVersion_1.default.V1;
|
1757
|
+
/* istanbul ignore next */
|
1758
|
+
this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] " + this.liveChatVersion);
|
1146
1759
|
setting = dataMaskingConfig.setting;
|
1147
1760
|
if (setting.msdyn_maskforcustomer) {
|
1148
1761
|
this.dataMaskingRules = dataMaskingConfig.dataMaskingRules;
|
@@ -1150,31 +1763,59 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1150
1763
|
if (authSettings) {
|
1151
1764
|
this.authSettings = authSettings;
|
1152
1765
|
}
|
1153
|
-
preChatSurvey = liveWSAndLiveChatEngJoin.PreChatSurvey, msdyn_prechatenabled = liveWSAndLiveChatEngJoin.msdyn_prechatenabled, msdyn_callingoptions = liveWSAndLiveChatEngJoin.msdyn_callingoptions, msdyn_conversationmode = liveWSAndLiveChatEngJoin.msdyn_conversationmode;
|
1766
|
+
preChatSurvey = liveWSAndLiveChatEngJoin.PreChatSurvey, msdyn_prechatenabled = liveWSAndLiveChatEngJoin.msdyn_prechatenabled, msdyn_callingoptions = liveWSAndLiveChatEngJoin.msdyn_callingoptions, msdyn_conversationmode = liveWSAndLiveChatEngJoin.msdyn_conversationmode, msdyn_enablechatreconnect = liveWSAndLiveChatEngJoin.msdyn_enablechatreconnect;
|
1154
1767
|
isPreChatEnabled = msdyn_prechatenabled === true || msdyn_prechatenabled == "true";
|
1768
|
+
isChatReconnectEnabled = msdyn_enablechatreconnect === true || msdyn_enablechatreconnect == "true";
|
1155
1769
|
if ((msdyn_conversationmode === null || msdyn_conversationmode === void 0 ? void 0 : msdyn_conversationmode.toString()) === ConversationMode_1.default.PersistentChat.toString()) {
|
1156
1770
|
this.isPersistentChat = true;
|
1157
1771
|
}
|
1772
|
+
if (isChatReconnectEnabled && !this.isPersistentChat) {
|
1773
|
+
this.isChatReconnect = true;
|
1774
|
+
}
|
1158
1775
|
if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
|
1159
1776
|
this.preChatSurvey = preChatSurvey;
|
1160
1777
|
}
|
1161
|
-
if (!this.authSettings) return [3 /*break*/,
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1778
|
+
if (!this.authSettings) return [3 /*break*/, 7];
|
1779
|
+
this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
|
1780
|
+
if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 6];
|
1781
|
+
_b.label = 2;
|
1165
1782
|
case 2:
|
1166
|
-
|
1783
|
+
_b.trys.push([2, 4, , 5]);
|
1784
|
+
return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
|
1785
|
+
case 3:
|
1786
|
+
token = _b.sent();
|
1167
1787
|
if (token) {
|
1168
1788
|
this.authenticatedUserToken = token;
|
1789
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
|
1169
1790
|
}
|
1170
1791
|
else {
|
1171
|
-
|
1792
|
+
exceptionDetails = {
|
1793
|
+
response: "UndefinedAuthToken"
|
1794
|
+
};
|
1795
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
|
1796
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
1797
|
+
});
|
1172
1798
|
}
|
1173
|
-
return [3 /*break*/,
|
1174
|
-
case 3:
|
1175
|
-
console.warn("OmnichannelChatSDK/getChatConfig/auth, chat requires auth, but getAuthToken() is missing");
|
1176
|
-
_a.label = 4;
|
1799
|
+
return [3 /*break*/, 5];
|
1177
1800
|
case 4:
|
1801
|
+
_a = _b.sent();
|
1802
|
+
exceptionDetails = {
|
1803
|
+
response: "GetAuthTokenFailed"
|
1804
|
+
};
|
1805
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
|
1806
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
1807
|
+
});
|
1808
|
+
return [3 /*break*/, 5];
|
1809
|
+
case 5: return [3 /*break*/, 7];
|
1810
|
+
case 6:
|
1811
|
+
exceptionDetails = {
|
1812
|
+
response: "GetAuthTokenNotFound"
|
1813
|
+
};
|
1814
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
|
1815
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
1816
|
+
});
|
1817
|
+
_b.label = 7;
|
1818
|
+
case 7:
|
1178
1819
|
if (this.preChatSurvey) {
|
1179
1820
|
/* istanbul ignore next */
|
1180
1821
|
this.debug && console.log('Prechat Survey!');
|
@@ -1182,11 +1823,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1182
1823
|
this.callingOption = msdyn_callingoptions;
|
1183
1824
|
this.liveChatConfig = liveChatConfig;
|
1184
1825
|
return [2 /*return*/, this.liveChatConfig];
|
1185
|
-
case
|
1186
|
-
|
1187
|
-
console.error("OmnichannelChatSDK/getChatConfig/error " +
|
1188
|
-
return [2 /*return*/,
|
1189
|
-
case
|
1826
|
+
case 8:
|
1827
|
+
error_18 = _b.sent();
|
1828
|
+
console.error("OmnichannelChatSDK/getChatConfig/error " + error_18);
|
1829
|
+
return [2 /*return*/, error_18];
|
1830
|
+
case 9: return [2 /*return*/];
|
1190
1831
|
}
|
1191
1832
|
});
|
1192
1833
|
});
|
@@ -1201,16 +1842,72 @@ var OmnichannelChatSDK = /** @class */ (function () {
|
|
1201
1842
|
return libraries_1.default.getIC3ClientCDNUrl();
|
1202
1843
|
};
|
1203
1844
|
OmnichannelChatSDK.prototype.resolveChatAdapterUrl = function (protocol) {
|
1204
|
-
|
1845
|
+
var supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
|
1846
|
+
if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
|
1205
1847
|
throw new Error("ChatAdapter for protocol " + protocol + " currently not supported");
|
1206
1848
|
}
|
1207
|
-
if (
|
1208
|
-
|
1849
|
+
if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
|
1850
|
+
if (this.chatSDKConfig.chatAdapterConfig && 'webChatACSAdapterCDNUrl' in this.chatSDKConfig.chatAdapterConfig) {
|
1851
|
+
return this.chatSDKConfig.chatAdapterConfig.webChatACSAdapterCDNUrl;
|
1852
|
+
}
|
1853
|
+
if (this.chatSDKConfig.chatAdapterConfig && 'webChatACSAdapterVersion' in this.chatSDKConfig.chatAdapterConfig) {
|
1854
|
+
return libraries_1.default.getACSAdapterCDNUrl(this.chatSDKConfig.chatAdapterConfig.webChatACSAdapterVersion);
|
1855
|
+
}
|
1856
|
+
return libraries_1.default.getACSAdapterCDNUrl();
|
1209
1857
|
}
|
1210
|
-
if (
|
1211
|
-
|
1858
|
+
else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
|
1859
|
+
if (this.chatSDKConfig.chatAdapterConfig && 'webChatIC3AdapterCDNUrl' in this.chatSDKConfig.chatAdapterConfig) {
|
1860
|
+
return this.chatSDKConfig.chatAdapterConfig.webChatIC3AdapterCDNUrl;
|
1861
|
+
}
|
1862
|
+
if (this.chatSDKConfig.chatAdapterConfig && 'webChatIC3AdapterVersion' in this.chatSDKConfig.chatAdapterConfig) {
|
1863
|
+
return libraries_1.default.getIC3AdapterCDNUrl(this.chatSDKConfig.chatAdapterConfig.webChatIC3AdapterVersion);
|
1864
|
+
}
|
1865
|
+
return libraries_1.default.getIC3AdapterCDNUrl();
|
1212
1866
|
}
|
1213
|
-
return
|
1867
|
+
return '';
|
1868
|
+
};
|
1869
|
+
OmnichannelChatSDK.prototype.updateChatToken = function (newToken, newRegionGTMS) {
|
1870
|
+
return __awaiter(this, void 0, void 0, function () {
|
1871
|
+
var sessionInfo, error_19, exceptionDetails;
|
1872
|
+
return __generator(this, function (_a) {
|
1873
|
+
switch (_a.label) {
|
1874
|
+
case 0:
|
1875
|
+
this.scenarioMarker.startScenario(TelemetryEvent_1.default.UpdateChatToken, {
|
1876
|
+
RequestId: this.requestId,
|
1877
|
+
ChatId: this.chatToken.chatId
|
1878
|
+
});
|
1879
|
+
_a.label = 1;
|
1880
|
+
case 1:
|
1881
|
+
_a.trys.push([1, 3, , 4]);
|
1882
|
+
sessionInfo = {
|
1883
|
+
token: newToken,
|
1884
|
+
regionGtms: newRegionGTMS,
|
1885
|
+
visitor: true
|
1886
|
+
};
|
1887
|
+
return [4 /*yield*/, this.IC3Client.initialize(sessionInfo)];
|
1888
|
+
case 2:
|
1889
|
+
_a.sent();
|
1890
|
+
this.scenarioMarker.completeScenario(TelemetryEvent_1.default.UpdateChatToken, {
|
1891
|
+
RequestId: this.requestId,
|
1892
|
+
ChatId: this.chatToken.chatId
|
1893
|
+
});
|
1894
|
+
return [3 /*break*/, 4];
|
1895
|
+
case 3:
|
1896
|
+
error_19 = _a.sent();
|
1897
|
+
exceptionDetails = {
|
1898
|
+
response: "UpdateChatTokenFailed"
|
1899
|
+
};
|
1900
|
+
this.scenarioMarker.failScenario(TelemetryEvent_1.default.UpdateChatToken, {
|
1901
|
+
RequestId: this.requestId,
|
1902
|
+
ChatId: this.chatToken.chatId,
|
1903
|
+
ExceptionDetails: JSON.stringify(exceptionDetails)
|
1904
|
+
});
|
1905
|
+
console.error("OmnichannelChatSDK/updateChatToken/error " + error_19);
|
1906
|
+
return [3 /*break*/, 4];
|
1907
|
+
case 4: return [2 /*return*/];
|
1908
|
+
}
|
1909
|
+
});
|
1910
|
+
});
|
1214
1911
|
};
|
1215
1912
|
return OmnichannelChatSDK;
|
1216
1913
|
}());
|