@microsoft/omnichannel-chat-sdk 0.3.1-main.dcd02d3 → 1.0.1-main.67b480d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/README.md +71 -8
  3. package/lib/OmnichannelChatSDK.d.ts +36 -24
  4. package/lib/OmnichannelChatSDK.js +950 -333
  5. package/lib/OmnichannelChatSDK.js.map +1 -1
  6. package/lib/api/createVoiceVideoCalling.d.ts +1 -0
  7. package/lib/api/createVoiceVideoCalling.js +91 -83
  8. package/lib/api/createVoiceVideoCalling.js.map +1 -1
  9. package/lib/config/settings.d.ts +2 -1
  10. package/lib/config/settings.js +3 -1
  11. package/lib/config/settings.js.map +1 -1
  12. package/lib/core/{IAuthSettings.d.ts → AuthSettings.d.ts} +1 -1
  13. package/lib/core/{IAuthSettings.js → AuthSettings.js} +1 -1
  14. package/lib/core/AuthSettings.js.map +1 -0
  15. package/lib/core/ChatConfig.d.ts +9 -0
  16. package/lib/core/{IChatConfig.js → ChatConfig.js} +1 -1
  17. package/lib/core/ChatConfig.js.map +1 -0
  18. package/lib/core/{IChatSDKConfig.d.ts → ChatSDKConfig.d.ts} +7 -7
  19. package/lib/core/{IChatSDKConfig.js → ChatSDKConfig.js} +1 -1
  20. package/lib/core/ChatSDKConfig.js.map +1 -0
  21. package/lib/core/{IChatTranscriptBody.d.ts → ChatTranscriptBody.d.ts} +1 -1
  22. package/lib/core/ChatTranscriptBody.js +3 -0
  23. package/lib/core/ChatTranscriptBody.js.map +1 -0
  24. package/lib/core/{ILiveChatContext.d.ts → LiveChatContext.d.ts} +1 -1
  25. package/lib/core/LiveChatContext.js +3 -0
  26. package/lib/core/LiveChatContext.js.map +1 -0
  27. package/lib/core/LiveChatVersion.d.ts +5 -0
  28. package/lib/core/LiveChatVersion.js +9 -0
  29. package/lib/core/LiveChatVersion.js.map +1 -0
  30. package/lib/core/{IOmnichannelConfig.d.ts → OmnichannelConfig.d.ts} +1 -1
  31. package/lib/core/OmnichannelConfig.js +3 -0
  32. package/lib/core/OmnichannelConfig.js.map +1 -0
  33. package/lib/core/PostChatContext.d.ts +5 -0
  34. package/lib/core/PostChatContext.js +3 -0
  35. package/lib/core/PostChatContext.js.map +1 -0
  36. package/lib/core/{IStartChatOptionalParams.d.ts → StartChatOptionalParams.d.ts} +3 -3
  37. package/lib/core/StartChatOptionalParams.js +3 -0
  38. package/lib/core/StartChatOptionalParams.js.map +1 -0
  39. package/lib/core/messaging/ACSChatMessageType.d.ts +7 -0
  40. package/lib/core/messaging/ACSChatMessageType.js +11 -0
  41. package/lib/core/messaging/ACSChatMessageType.js.map +1 -0
  42. package/lib/core/messaging/ACSClient.d.ts +44 -0
  43. package/lib/core/messaging/ACSClient.js +588 -0
  44. package/lib/core/messaging/ACSClient.js.map +1 -0
  45. package/lib/core/messaging/ACSClientConfig.d.ts +4 -0
  46. package/lib/core/messaging/ACSClientConfig.js +3 -0
  47. package/lib/core/messaging/ACSClientConfig.js.map +1 -0
  48. package/lib/core/messaging/ACSParticipantDisplayName.d.ts +6 -0
  49. package/lib/core/messaging/ACSParticipantDisplayName.js +10 -0
  50. package/lib/core/messaging/ACSParticipantDisplayName.js.map +1 -0
  51. package/lib/core/messaging/ACSSessionInfo.d.ts +5 -0
  52. package/lib/core/messaging/ACSSessionInfo.js +3 -0
  53. package/lib/core/messaging/ACSSessionInfo.js.map +1 -0
  54. package/lib/core/{ChatAdapterConfig.d.ts → messaging/ChatAdapterConfig.d.ts} +2 -0
  55. package/lib/core/{ChatAdapterConfig.js → messaging/ChatAdapterConfig.js} +0 -0
  56. package/lib/core/messaging/ChatAdapterConfig.js.map +1 -0
  57. package/lib/core/{ChatAdapterProtocols.d.ts → messaging/ChatAdapterProtocols.d.ts} +1 -0
  58. package/lib/core/{ChatAdapterProtocols.js → messaging/ChatAdapterProtocols.js} +3 -1
  59. package/lib/core/messaging/ChatAdapterProtocols.js.map +1 -0
  60. package/lib/core/{IChatSDKMessage.d.ts → messaging/ChatSDKMessage.d.ts} +2 -1
  61. package/lib/core/messaging/ChatSDKMessage.js +3 -0
  62. package/lib/core/messaging/ChatSDKMessage.js.map +1 -0
  63. package/lib/core/{IC3Config.d.ts → messaging/IC3Config.d.ts} +0 -0
  64. package/lib/core/{IC3Config.js → messaging/IC3Config.js} +0 -0
  65. package/lib/core/messaging/IC3Config.js.map +1 -0
  66. package/lib/core/{MessageTags.d.ts → messaging/MessageTags.d.ts} +0 -0
  67. package/lib/core/{MessageTags.js → messaging/MessageTags.js} +1 -1
  68. package/lib/core/messaging/MessageTags.js.map +1 -0
  69. package/lib/core/messaging/OmnichannelMessage.d.ts +64 -0
  70. package/lib/core/messaging/OmnichannelMessage.js +52 -0
  71. package/lib/core/messaging/OmnichannelMessage.js.map +1 -0
  72. package/lib/core/{OnNewMessageOptionalParams.d.ts → messaging/OnNewMessageOptionalParams.d.ts} +0 -0
  73. package/lib/core/{OnNewMessageOptionalParams.js → messaging/OnNewMessageOptionalParams.js} +0 -0
  74. package/lib/core/messaging/OnNewMessageOptionalParams.js.map +1 -0
  75. package/lib/external/ACSAdapter/AMSFileManager.d.ts +39 -0
  76. package/lib/external/ACSAdapter/AMSFileManager.js +306 -0
  77. package/lib/external/ACSAdapter/AMSFileManager.js.map +1 -0
  78. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.d.ts +2 -0
  79. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.js +31 -0
  80. package/lib/external/ACSAdapter/createFormatEgressTagsMiddleware.js.map +1 -0
  81. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.d.ts +2 -0
  82. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.js +25 -0
  83. package/lib/external/ACSAdapter/createFormatIngressTagsMiddleware.js.map +1 -0
  84. package/lib/external/IC3Adapter/IChatToken.d.ts +2 -0
  85. package/lib/index.d.ts +2 -2
  86. package/lib/telemetry/AriaTelemetry.d.ts +4 -0
  87. package/lib/telemetry/AriaTelemetry.js +150 -13
  88. package/lib/telemetry/AriaTelemetry.js.map +1 -1
  89. package/lib/telemetry/EventMarker.d.ts +3 -0
  90. package/lib/telemetry/EventMarker.js +13 -0
  91. package/lib/telemetry/EventMarker.js.map +1 -0
  92. package/lib/telemetry/ScenarioMarker.d.ts +9 -7
  93. package/lib/telemetry/ScenarioMarker.js +12 -7
  94. package/lib/telemetry/ScenarioMarker.js.map +1 -1
  95. package/lib/telemetry/ScenarioType.d.ts +2 -0
  96. package/lib/telemetry/ScenarioType.js +2 -0
  97. package/lib/telemetry/ScenarioType.js.map +1 -1
  98. package/lib/telemetry/TelemetryEvent.d.ts +9 -4
  99. package/lib/telemetry/TelemetryEvent.js +8 -10
  100. package/lib/telemetry/TelemetryEvent.js.map +1 -1
  101. package/lib/tsconfig.tsbuildinfo +5087 -1320
  102. package/lib/utils/createOmnichannelMessage.d.ts +11 -0
  103. package/lib/utils/createOmnichannelMessage.js +63 -0
  104. package/lib/utils/createOmnichannelMessage.js.map +1 -0
  105. package/lib/utils/libraries.d.ts +3 -1
  106. package/lib/utils/libraries.js +9 -2
  107. package/lib/utils/libraries.js.map +1 -1
  108. package/lib/utils/locale.d.ts +2 -0
  109. package/lib/utils/locale.js +59 -0
  110. package/lib/utils/locale.js.map +1 -0
  111. package/lib/utils/loggers.d.ts +42 -6
  112. package/lib/utils/loggers.js +197 -2
  113. package/lib/utils/loggers.js.map +1 -1
  114. package/lib/utils/utilities.js +10 -3
  115. package/lib/utils/utilities.js.map +1 -1
  116. package/lib/validators/OmnichannelConfigValidator.d.ts +2 -2
  117. package/lib/validators/OmnichannelConfigValidator.js.map +1 -1
  118. package/lib/validators/SDKConfigValidators.d.ts +3 -3
  119. package/lib/validators/SDKConfigValidators.js.map +1 -1
  120. package/package.json +7 -3
  121. package/lib/core/ChatAdapterConfig.js.map +0 -1
  122. package/lib/core/ChatAdapterProtocols.js.map +0 -1
  123. package/lib/core/IAuthSettings.js.map +0 -1
  124. package/lib/core/IC3Config.js.map +0 -1
  125. package/lib/core/IChatConfig.d.ts +0 -5
  126. package/lib/core/IChatConfig.js.map +0 -1
  127. package/lib/core/IChatSDKConfig.js.map +0 -1
  128. package/lib/core/IChatSDKMessage.js +0 -3
  129. package/lib/core/IChatSDKMessage.js.map +0 -1
  130. package/lib/core/IChatTranscriptBody.js +0 -3
  131. package/lib/core/IChatTranscriptBody.js.map +0 -1
  132. package/lib/core/ILiveChatContext.js +0 -3
  133. package/lib/core/ILiveChatContext.js.map +0 -1
  134. package/lib/core/IOmnichannelConfig.js +0 -3
  135. package/lib/core/IOmnichannelConfig.js.map +0 -1
  136. package/lib/core/IStartChatOptionalParams.js +0 -3
  137. package/lib/core/IStartChatOptionalParams.js.map +0 -1
  138. package/lib/core/MessageTags.js.map +0 -1
  139. package/lib/core/OnNewMessageOptionalParams.js.map +0 -1
@@ -55,35 +55,46 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
55
55
  return r;
56
56
  };
57
57
  Object.defineProperty(exports, "__esModule", { value: true });
58
+ var loggers_1 = require("./utils/loggers");
59
+ var ACSClient_1 = require("./core/messaging/ACSClient");
60
+ var ocsdk_1 = require("@microsoft/ocsdk");
61
+ var platform_1 = require("./utils/platform");
62
+ var SDKConfigValidators_1 = require("./validators/SDKConfigValidators");
63
+ var ACSParticipantDisplayName_1 = require("./core/messaging/ACSParticipantDisplayName");
64
+ var AMSFileManager_1 = require("./external/ACSAdapter/AMSFileManager");
58
65
  var CallingOptionsOptionSetNumber_1 = require("./core/CallingOptionsOptionSetNumber");
59
- var ChatAdapterProtocols_1 = require("./core/ChatAdapterProtocols");
66
+ var ChatAdapterProtocols_1 = require("./core/messaging/ChatAdapterProtocols");
60
67
  var ConversationMode_1 = require("./core/ConversationMode");
61
- var loggers_1 = require("./utils/loggers");
62
- var createTelemetry_1 = require("./utils/createTelemetry");
63
- var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
64
- var MessageTags_1 = require("./core/MessageTags");
68
+ var createFormatEgressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatEgressTagsMiddleware");
69
+ var createFormatIngressTagsMiddleware_1 = require("./external/ACSAdapter/createFormatIngressTagsMiddleware");
65
70
  var DeliveryMode_1 = require("@microsoft/omnichannel-ic3core/lib/model/DeliveryMode");
66
71
  var FileSharingProtocolType_1 = require("@microsoft/omnichannel-ic3core/lib/model/FileSharingProtocolType");
67
72
  var HostType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/HostType");
68
- var utilities_1 = require("./utils/utilities");
69
- var libraries_1 = require("./utils/libraries");
73
+ var omnichannel_ic3core_1 = require("@microsoft/omnichannel-ic3core");
74
+ var LiveChatVersion_1 = require("./core/LiveChatVersion");
70
75
  var LiveWorkItemState_1 = require("./core/LiveWorkItemState");
71
- var WebUtils_1 = require("./utils/WebUtils");
72
76
  var MessageContentType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageContentType");
73
77
  var MessageType_1 = require("@microsoft/omnichannel-ic3core/lib/model/MessageType");
74
78
  var PersonType_1 = require("@microsoft/omnichannel-ic3core/lib/model/PersonType");
75
- var platform_1 = require("./utils/platform");
76
79
  var ProtocoleType_1 = require("@microsoft/omnichannel-ic3core/lib/interfaces/ProtocoleType");
77
80
  var ScenarioMarker_1 = require("./telemetry/ScenarioMarker");
78
- var ocsdk_1 = require("@microsoft/ocsdk");
79
- var omnichannel_ic3core_1 = require("@microsoft/omnichannel-ic3core");
80
81
  var TelemetryEvent_1 = require("./telemetry/TelemetryEvent");
82
+ var omnichannel_amsclient_1 = require("@microsoft/omnichannel-amsclient");
83
+ var createOmnichannelMessage_1 = require("./utils/createOmnichannelMessage");
84
+ var createTelemetry_1 = require("./utils/createTelemetry");
85
+ var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
86
+ var MessageTags_1 = require("./core/messaging/MessageTags");
87
+ var locale_1 = require("./utils/locale");
88
+ var utilities_1 = require("./utils/utilities");
89
+ var libraries_1 = require("./utils/libraries");
90
+ var WebUtils_1 = require("./utils/WebUtils");
81
91
  var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
82
- var SDKConfigValidators_1 = require("./validators/SDKConfigValidators");
83
92
  var OmnichannelChatSDK = /** @class */ (function () {
84
93
  function OmnichannelChatSDK(omnichannelConfig, chatSDKConfig) {
85
94
  if (chatSDKConfig === void 0) { chatSDKConfig = SDKConfigValidators_1.defaultChatSDKConfig; }
86
- var _a, _b, _c, _d, _e;
95
+ var _a, _b, _c, _d, _e, _f, _g;
96
+ this.ACSClient = null;
97
+ this.AMSClient = null;
87
98
  this.authSettings = null;
88
99
  this.authenticatedUserToken = null;
89
100
  this.conversation = null;
@@ -91,6 +102,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
91
102
  this.telemetry = null;
92
103
  this.ic3ClientLogger = null;
93
104
  this.ocSdkLogger = null;
105
+ this.acsClientLogger = null;
106
+ this.acsAdapterLogger = null;
94
107
  this.isPersistentChat = false;
95
108
  this.isChatReconnect = false;
96
109
  this.reconnectId = null;
@@ -100,6 +113,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
100
113
  this.chatSDKConfig = __assign(__assign({}, SDKConfigValidators_1.defaultChatSDKConfig), chatSDKConfig // overrides
101
114
  );
102
115
  this.isInitialized = false;
116
+ this.liveChatVersion = LiveChatVersion_1.default.V1;
103
117
  this.requestId = ocsdk_1.uuidv4();
104
118
  this.chatToken = {};
105
119
  this.liveChatConfig = {};
@@ -110,9 +124,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
110
124
  this.scenarioMarker = new ScenarioMarker_1.default(this.omnichannelConfig);
111
125
  this.ic3ClientLogger = loggers_1.createIC3ClientLogger(this.omnichannelConfig);
112
126
  this.ocSdkLogger = loggers_1.createOCSDKLogger(this.omnichannelConfig);
127
+ this.acsClientLogger = loggers_1.createACSClientLogger(this.omnichannelConfig);
128
+ this.acsAdapterLogger = loggers_1.createACSAdapterLogger(this.omnichannelConfig);
113
129
  this.scenarioMarker.useTelemetry(this.telemetry);
114
130
  this.ic3ClientLogger.useTelemetry(this.telemetry);
115
131
  this.ocSdkLogger.useTelemetry(this.telemetry);
132
+ this.acsClientLogger.useTelemetry(this.telemetry);
133
+ this.acsAdapterLogger.useTelemetry(this.telemetry);
116
134
  OmnichannelConfigValidator_1.default(omnichannelConfig);
117
135
  SDKConfigValidators_1.default(chatSDKConfig);
118
136
  ((_a = this.chatSDKConfig.telemetry) === null || _a === void 0 ? void 0 : _a.disable) && ((_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.disable());
@@ -121,51 +139,69 @@ var OmnichannelChatSDK = /** @class */ (function () {
121
139
  }
122
140
  (_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
123
141
  (_e = this.ocSdkLogger) === null || _e === void 0 ? void 0 : _e.setRequestId(this.requestId);
142
+ (_f = this.acsClientLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
143
+ (_g = this.acsAdapterLogger) === null || _g === void 0 ? void 0 : _g.setRequestId(this.requestId);
124
144
  }
125
145
  /* istanbul ignore next */
126
146
  OmnichannelChatSDK.prototype.setDebug = function (flag) {
127
- var _a, _b, _c;
147
+ var _a, _b, _c, _d, _e, _f;
128
148
  this.debug = flag;
129
- (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setDebug(flag);
149
+ (_a = this.AMSClient) === null || _a === void 0 ? void 0 : _a.setDebug(flag);
150
+ (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.setDebug(flag);
130
151
  this.scenarioMarker.setDebug(flag);
131
- (_b = this.ic3ClientLogger) === null || _b === void 0 ? void 0 : _b.setDebug(flag);
132
- (_c = this.ocSdkLogger) === null || _c === void 0 ? void 0 : _c.setDebug(flag);
152
+ (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setDebug(flag);
153
+ (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setDebug(flag);
154
+ (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setDebug(flag);
155
+ (_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setDebug(flag);
133
156
  };
134
157
  OmnichannelChatSDK.prototype.initialize = function () {
135
158
  return __awaiter(this, void 0, void 0, function () {
136
- var OCClient, IC3Client, _a;
137
- return __generator(this, function (_b) {
138
- switch (_b.label) {
159
+ var _a, _b, _c, _d;
160
+ return __generator(this, function (_e) {
161
+ switch (_e.label) {
139
162
  case 0:
140
163
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.InitializeChatSDK);
141
164
  if (this.isInitialized) {
142
165
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeChatSDK);
143
166
  return [2 /*return*/, this.liveChatConfig];
144
167
  }
145
- _b.label = 1;
168
+ _e.label = 1;
146
169
  case 1:
147
- _b.trys.push([1, 5, , 6]);
170
+ _e.trys.push([1, 8, , 9]);
148
171
  this.OCSDKProvider = ocsdk_1.SDKProvider;
172
+ _a = this;
149
173
  return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, {}, this.ocSdkLogger)];
150
174
  case 2:
151
- OCClient = _b.sent();
152
- return [4 /*yield*/, this.getIC3Client()];
153
- case 3:
154
- IC3Client = _b.sent();
155
- // Assign & Update flag only if all dependencies have been initialized succesfully
156
- this.OCClient = OCClient;
157
- this.IC3Client = IC3Client;
175
+ _a.OCClient = _e.sent();
158
176
  return [4 /*yield*/, this.getChatConfig()];
177
+ case 3:
178
+ _e.sent();
179
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 5];
180
+ this.ACSClient = new ACSClient_1.default(this.acsClientLogger);
181
+ _b = this;
182
+ return [4 /*yield*/, omnichannel_amsclient_1.default({
183
+ framedMode: platform_1.isBrowser(),
184
+ debug: false,
185
+ logger: undefined
186
+ })];
159
187
  case 4:
160
- _b.sent();
188
+ _b.AMSClient = _e.sent();
189
+ return [3 /*break*/, 7];
190
+ case 5:
191
+ _c = this;
192
+ return [4 /*yield*/, this.getIC3Client()];
193
+ case 6:
194
+ _c.IC3Client = _e.sent();
195
+ _e.label = 7;
196
+ case 7:
161
197
  this.isInitialized = true;
162
198
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeChatSDK);
163
- return [3 /*break*/, 6];
164
- case 5:
165
- _a = _b.sent();
199
+ return [3 /*break*/, 9];
200
+ case 8:
201
+ _d = _e.sent();
166
202
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.InitializeChatSDK);
167
- return [3 /*break*/, 6];
168
- case 6: return [2 /*return*/, this.liveChatConfig];
203
+ return [3 /*break*/, 9];
204
+ case 9: return [2 /*return*/, this.liveChatConfig];
169
205
  }
170
206
  });
171
207
  });
@@ -255,13 +291,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
255
291
  });
256
292
  };
257
293
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
258
- var _a, _b, _c, _d, _e, _f, _g, _h;
294
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
259
295
  if (optionalParams === void 0) { optionalParams = {}; }
260
296
  return __awaiter(this, void 0, void 0, function () {
261
- var reconnectableChatsParams, reconnectableChatsResponse, _j, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, sessionInitOptionalParams, error_3, exceptionDetails, error_4, exceptionDetails, _k, error_5, exceptionDetails;
297
+ 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;
262
298
  var _this = this;
263
- return __generator(this, function (_l) {
264
- switch (_l.label) {
299
+ return __generator(this, function (_s) {
300
+ switch (_s.label) {
265
301
  case 0:
266
302
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
267
303
  RequestId: this.requestId
@@ -270,32 +306,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
270
306
  this.reconnectId = optionalParams.reconnectId;
271
307
  }
272
308
  if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 4];
273
- _l.label = 1;
309
+ _s.label = 1;
274
310
  case 1:
275
- _l.trys.push([1, 3, , 4]);
311
+ _s.trys.push([1, 3, , 4]);
276
312
  reconnectableChatsParams = {
277
313
  authenticatedUserToken: this.authenticatedUserToken
278
314
  };
279
315
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
280
316
  case 2:
281
- reconnectableChatsResponse = _l.sent();
317
+ reconnectableChatsResponse = _s.sent();
282
318
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
283
319
  this.reconnectId = reconnectableChatsResponse.reconnectid;
284
320
  }
285
321
  return [3 /*break*/, 4];
286
322
  case 3:
287
- _j = _l.sent();
323
+ _p = _s.sent();
288
324
  exceptionDetails = {
289
325
  response: "OCClientGetReconnectableChatsFailed"
290
326
  };
291
327
  throw Error(exceptionDetails.response);
292
328
  case 4:
293
- if (!(optionalParams.liveChatContext && !this.isPersistentChat && !this.isChatReconnect)) return [3 /*break*/, 6];
329
+ if (!(optionalParams.liveChatContext && !this.reconnectId)) return [3 /*break*/, 6];
294
330
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
295
331
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
296
332
  return [4 /*yield*/, this.getConversationDetails()];
297
333
  case 5:
298
- conversationDetails = _l.sent();
334
+ conversationDetails = _s.sent();
299
335
  if (Object.keys(conversationDetails).length === 0) {
300
336
  exceptionDetails = {
301
337
  response: "InvalidConversation"
@@ -320,23 +356,25 @@ var OmnichannelChatSDK = /** @class */ (function () {
320
356
  console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
321
357
  throw Error(exceptionDetails.response);
322
358
  }
323
- _l.label = 6;
359
+ _s.label = 6;
324
360
  case 6:
325
361
  if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 8];
326
362
  return [4 /*yield*/, this.getChatToken(false)];
327
363
  case 7:
328
- _l.sent();
329
- _l.label = 8;
364
+ _s.sent();
365
+ _s.label = 8;
330
366
  case 8:
331
367
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
332
368
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
369
+ (_e = this.acsClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId(this.chatToken.chatId || '');
370
+ (_f = this.acsAdapterLogger) === null || _f === void 0 ? void 0 : _f.setChatId(this.chatToken.chatId || '');
333
371
  sessionInitOptionalParams = {
334
372
  initContext: {}
335
373
  };
336
- if (this.isPersistentChat && !((_e = this.chatSDKConfig.persistentChat) === null || _e === void 0 ? void 0 : _e.disable)) {
374
+ if (this.isPersistentChat && !((_g = this.chatSDKConfig.persistentChat) === null || _g === void 0 ? void 0 : _g.disable)) {
337
375
  sessionInitOptionalParams.reconnectId = this.reconnectId;
338
376
  }
339
- if (this.isChatReconnect && !((_f = this.chatSDKConfig.chatReconnect) === null || _f === void 0 ? void 0 : _f.disable) && !this.isPersistentChat) {
377
+ if (this.isChatReconnect && !((_h = this.chatSDKConfig.chatReconnect) === null || _h === void 0 ? void 0 : _h.disable) && !this.isPersistentChat) {
340
378
  sessionInitOptionalParams.reconnectId = this.reconnectId;
341
379
  }
342
380
  if (optionalParams.customContext) {
@@ -364,15 +402,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
364
402
  if (this.authenticatedUserToken) {
365
403
  sessionInitOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
366
404
  }
367
- _l.label = 9;
405
+ if (!!optionalParams.liveChatContext) return [3 /*break*/, 12];
406
+ _s.label = 9;
368
407
  case 9:
369
- _l.trys.push([9, 11, , 12]);
408
+ _s.trys.push([9, 11, , 12]);
370
409
  return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
371
410
  case 10:
372
- _l.sent();
411
+ _s.sent();
373
412
  return [3 /*break*/, 12];
374
413
  case 11:
375
- error_3 = _l.sent();
414
+ error_3 = _s.sent();
376
415
  exceptionDetails = {
377
416
  response: "OCClientSessionInitFailed"
378
417
  };
@@ -384,17 +423,95 @@ var OmnichannelChatSDK = /** @class */ (function () {
384
423
  console.error("OmnichannelChatSDK/startChat/sessionInit/error " + error_3);
385
424
  return [2 /*return*/, error_3];
386
425
  case 12:
387
- _l.trys.push([12, 14, , 15]);
426
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 23];
427
+ chatAdapterConfig = {
428
+ token: this.chatToken.token,
429
+ id: this.chatToken.visitorId || 'teamsvisitor',
430
+ threadId: this.chatToken.chatId,
431
+ environmentUrl: this.chatToken.acsEndpoint,
432
+ pollingInterval: 1000
433
+ };
434
+ _s.label = 13;
435
+ case 13:
436
+ _s.trys.push([13, 15, , 16]);
437
+ return [4 /*yield*/, ((_j = this.ACSClient) === null || _j === void 0 ? void 0 : _j.initialize({
438
+ token: chatAdapterConfig.token,
439
+ environmentUrl: chatAdapterConfig.environmentUrl
440
+ }))];
441
+ case 14:
442
+ _s.sent();
443
+ return [3 /*break*/, 16];
444
+ case 15:
445
+ error_4 = _s.sent();
446
+ exceptionDetails = {
447
+ response: "ACSClientInitializeFailed"
448
+ };
449
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
450
+ RequestId: this.requestId,
451
+ ChatId: this.chatToken.chatId,
452
+ ExceptionDetails: JSON.stringify(exceptionDetails)
453
+ });
454
+ console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
455
+ return [2 /*return*/, error_4];
456
+ case 16:
457
+ _s.trys.push([16, 18, , 19]);
458
+ _q = this;
459
+ return [4 /*yield*/, ((_k = this.ACSClient) === null || _k === void 0 ? void 0 : _k.joinConversation({
460
+ id: chatAdapterConfig.id,
461
+ threadId: chatAdapterConfig.threadId,
462
+ pollingInterval: chatAdapterConfig.pollingInterval
463
+ }))];
464
+ case 17:
465
+ _q.conversation = (_s.sent());
466
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
467
+ RequestId: this.requestId,
468
+ ChatId: this.chatToken.chatId
469
+ });
470
+ return [3 /*break*/, 19];
471
+ case 18:
472
+ error_5 = _s.sent();
473
+ exceptionDetails = {
474
+ response: "ACSClientJoinConversationFailed"
475
+ };
476
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
477
+ RequestId: this.requestId,
478
+ ChatId: this.chatToken.chatId,
479
+ ExceptionDetails: JSON.stringify(exceptionDetails)
480
+ });
481
+ console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
482
+ throw Error(exceptionDetails.response);
483
+ case 19:
484
+ _s.trys.push([19, 21, , 22]);
485
+ return [4 /*yield*/, ((_l = this.AMSClient) === null || _l === void 0 ? void 0 : _l.initialize({
486
+ chatToken: this.chatToken
487
+ }))];
488
+ case 20:
489
+ _s.sent();
490
+ return [3 /*break*/, 22];
491
+ case 21:
492
+ error_6 = _s.sent();
493
+ exceptionDetails = {
494
+ response: "AMSClientInitializeFailed"
495
+ };
496
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
497
+ RequestId: this.requestId,
498
+ ChatId: this.chatToken.chatId,
499
+ ExceptionDetails: JSON.stringify(exceptionDetails)
500
+ });
501
+ throw Error(exceptionDetails.response);
502
+ case 22: return [3 /*break*/, 29];
503
+ case 23:
504
+ _s.trys.push([23, 25, , 26]);
388
505
  return [4 /*yield*/, this.IC3Client.initialize({
389
506
  token: this.chatToken.token,
390
507
  regionGtms: this.chatToken.regionGTMS,
391
508
  visitor: true
392
509
  })];
393
- case 13:
394
- _l.sent();
395
- return [3 /*break*/, 15];
396
- case 14:
397
- error_4 = _l.sent();
510
+ case 24:
511
+ _s.sent();
512
+ return [3 /*break*/, 26];
513
+ case 25:
514
+ error_7 = _s.sent();
398
515
  exceptionDetails = {
399
516
  response: "IC3ClientInitializeFailed"
400
517
  };
@@ -403,21 +520,21 @@ var OmnichannelChatSDK = /** @class */ (function () {
403
520
  ChatId: this.chatToken.chatId,
404
521
  ExceptionDetails: JSON.stringify(exceptionDetails)
405
522
  });
406
- console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
407
- return [2 /*return*/, error_4];
408
- case 15:
409
- _l.trys.push([15, 17, , 18]);
410
- _k = this;
523
+ console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
524
+ return [2 /*return*/, error_7];
525
+ case 26:
526
+ _s.trys.push([26, 28, , 29]);
527
+ _r = this;
411
528
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
412
- case 16:
413
- _k.conversation = _l.sent();
529
+ case 27:
530
+ _r.conversation = _s.sent();
414
531
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
415
532
  RequestId: this.requestId,
416
533
  ChatId: this.chatToken.chatId
417
534
  });
418
- return [3 /*break*/, 18];
419
- case 17:
420
- error_5 = _l.sent();
535
+ return [3 /*break*/, 29];
536
+ case 28:
537
+ error_8 = _s.sent();
421
538
  exceptionDetails = {
422
539
  response: "IC3ClientJoinConversationFailed"
423
540
  };
@@ -426,10 +543,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
426
543
  ChatId: this.chatToken.chatId,
427
544
  ExceptionDetails: JSON.stringify(exceptionDetails)
428
545
  });
429
- console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
430
- return [2 /*return*/, error_5];
431
- case 18:
432
- if (this.isPersistentChat && !((_g = this.chatSDKConfig.persistentChat) === null || _g === void 0 ? void 0 : _g.disable)) {
546
+ console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
547
+ return [2 /*return*/, error_8];
548
+ case 29:
549
+ if (this.isPersistentChat && !((_m = this.chatSDKConfig.persistentChat) === null || _m === void 0 ? void 0 : _m.disable)) {
433
550
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
434
551
  return __generator(this, function (_a) {
435
552
  switch (_a.label) {
@@ -440,7 +557,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
440
557
  return [2 /*return*/];
441
558
  }
442
559
  });
443
- }); }, (_h = this.chatSDKConfig.persistentChat) === null || _h === void 0 ? void 0 : _h.tokenUpdateTime);
560
+ }); }, (_o = this.chatSDKConfig.persistentChat) === null || _o === void 0 ? void 0 : _o.tokenUpdateTime);
444
561
  }
445
562
  return [2 /*return*/];
446
563
  }
@@ -448,11 +565,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
448
565
  });
449
566
  };
450
567
  OmnichannelChatSDK.prototype.endChat = function () {
451
- var _a, _b, _c, _d, _e, _f;
568
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
452
569
  return __awaiter(this, void 0, void 0, function () {
453
- var sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_6, exceptionDetails;
454
- return __generator(this, function (_g) {
455
- switch (_g.label) {
570
+ var sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_9, exceptionDetails;
571
+ return __generator(this, function (_m) {
572
+ switch (_m.label) {
456
573
  case 0:
457
574
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.EndChat, {
458
575
  RequestId: this.requestId,
@@ -471,28 +588,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
471
588
  if (this.authenticatedUserToken) {
472
589
  sessionCloseOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
473
590
  }
474
- _g.label = 1;
591
+ _m.label = 1;
475
592
  case 1:
476
- _g.trys.push([1, 3, , 4]);
593
+ _m.trys.push([1, 3, , 4]);
477
594
  return [4 /*yield*/, this.OCClient.sessionClose(this.requestId, sessionCloseOptionalParams)];
478
595
  case 2:
479
- _g.sent();
596
+ _m.sent();
480
597
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, {
481
598
  RequestId: this.requestId,
482
599
  ChatId: this.chatToken.chatId
483
600
  });
484
- this.conversation.disconnect();
601
+ (_c = this.conversation) === null || _c === void 0 ? void 0 : _c.disconnect();
485
602
  this.conversation = null;
486
603
  this.requestId = ocsdk_1.uuidv4();
487
604
  this.chatToken = {};
488
605
  this.reconnectId = null;
489
- (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setRequestId(this.requestId);
490
- (_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setChatId('');
491
- (_e = this.ocSdkLogger) === null || _e === void 0 ? void 0 : _e.setRequestId(this.requestId);
492
- (_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setChatId('');
606
+ (_d = this.ic3ClientLogger) === null || _d === void 0 ? void 0 : _d.setRequestId(this.requestId);
607
+ (_e = this.ic3ClientLogger) === null || _e === void 0 ? void 0 : _e.setChatId('');
608
+ (_f = this.ocSdkLogger) === null || _f === void 0 ? void 0 : _f.setRequestId(this.requestId);
609
+ (_g = this.ocSdkLogger) === null || _g === void 0 ? void 0 : _g.setChatId('');
610
+ (_h = this.acsClientLogger) === null || _h === void 0 ? void 0 : _h.setRequestId(this.requestId);
611
+ (_j = this.acsClientLogger) === null || _j === void 0 ? void 0 : _j.setChatId('');
612
+ (_k = this.acsAdapterLogger) === null || _k === void 0 ? void 0 : _k.setRequestId(this.requestId);
613
+ (_l = this.acsAdapterLogger) === null || _l === void 0 ? void 0 : _l.setChatId('');
493
614
  return [3 /*break*/, 4];
494
615
  case 3:
495
- error_6 = _g.sent();
616
+ error_9 = _m.sent();
496
617
  exceptionDetails = {
497
618
  response: "OCClientSessionCloseFailed"
498
619
  };
@@ -501,8 +622,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
501
622
  ChatId: this.chatToken.chatId,
502
623
  ExceptionDetails: JSON.stringify(exceptionDetails),
503
624
  });
504
- console.error("OmnichannelChatSDK/endChat/error " + error_6);
505
- return [2 /*return*/, error_6];
625
+ console.error("OmnichannelChatSDK/endChat/error " + error_9);
626
+ return [2 /*return*/, error_9];
506
627
  case 4:
507
628
  if (this.refreshTokenTimer !== null) {
508
629
  clearInterval(this.refreshTokenTimer);
@@ -522,6 +643,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
522
643
  case 1:
523
644
  chatToken = _a.sent();
524
645
  requestId = this.requestId;
646
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetCurrentLiveChatContext, {
647
+ RequestId: requestId,
648
+ ChatId: chatToken.chatId
649
+ });
525
650
  chatSession = {
526
651
  chatToken: chatToken,
527
652
  requestId: requestId
@@ -529,6 +654,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
529
654
  if (Object.keys(chatSession.chatToken).length === 0) {
530
655
  return [2 /*return*/, {}];
531
656
  }
657
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetCurrentLiveChatContext, {
658
+ RequestId: requestId,
659
+ ChatId: chatToken.chatId
660
+ });
532
661
  return [2 /*return*/, chatSession];
533
662
  }
534
663
  });
@@ -537,7 +666,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
537
666
  OmnichannelChatSDK.prototype.getConversationDetails = function () {
538
667
  var _a, _b;
539
668
  return __awaiter(this, void 0, void 0, function () {
540
- var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_7;
669
+ var lwiDetails, state, conversationId, agentAcceptedOn, liveWorkItemDetails, error_10;
541
670
  return __generator(this, function (_c) {
542
671
  switch (_c.label) {
543
672
  case 0:
@@ -565,12 +694,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
565
694
  });
566
695
  return [2 /*return*/, liveWorkItemDetails];
567
696
  case 3:
568
- error_7 = _c.sent();
697
+ error_10 = _c.sent();
569
698
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetConversationDetails, {
570
699
  RequestId: this.requestId,
571
700
  ChatId: this.chatToken.chatId || '',
572
701
  });
573
- console.error("OmnichannelChatSDK/getConversationDetails/error " + error_7);
702
+ console.error("OmnichannelChatSDK/getConversationDetails/error " + error_10);
574
703
  return [3 /*break*/, 4];
575
704
  case 4: return [2 /*return*/, {}];
576
705
  }
@@ -584,8 +713,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
584
713
  OmnichannelChatSDK.prototype.getPreChatSurvey = function (parse) {
585
714
  if (parse === void 0) { parse = true; }
586
715
  return __awaiter(this, void 0, void 0, function () {
716
+ var result;
587
717
  return __generator(this, function (_a) {
588
- return [2 /*return*/, parse ? JSON.parse(this.preChatSurvey) : this.preChatSurvey];
718
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetPreChatSurvey);
719
+ try {
720
+ result = parse ? JSON.parse(this.preChatSurvey) : this.preChatSurvey;
721
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetPreChatSurvey);
722
+ return [2 /*return*/, result];
723
+ }
724
+ catch (_b) {
725
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPreChatSurvey);
726
+ }
727
+ return [2 /*return*/];
589
728
  });
590
729
  });
591
730
  };
@@ -604,7 +743,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
604
743
  var _a, _b;
605
744
  if (cached === void 0) { cached = true; }
606
745
  return __awaiter(this, void 0, void 0, function () {
607
- var getChatTokenOptionalParams, chatToken, chatId, token, regionGtms, expiresIn, visitorId, voiceVideoCallToken, error_8, exceptionDetails;
746
+ var getChatTokenOptionalParams, chatToken, chatId, token, regionGtms, expiresIn, visitorId, voiceVideoCallToken, acsEndpoint, attachmentConfiguration, error_11, exceptionDetails;
608
747
  return __generator(this, function (_c) {
609
748
  switch (_c.label) {
610
749
  case 0:
@@ -628,7 +767,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
628
767
  return [4 /*yield*/, this.OCClient.getChatToken(this.requestId, getChatTokenOptionalParams)];
629
768
  case 2:
630
769
  chatToken = _c.sent();
631
- chatId = chatToken.ChatId, token = chatToken.Token, regionGtms = chatToken.RegionGtms, expiresIn = chatToken.ExpiresIn, visitorId = chatToken.VisitorId, voiceVideoCallToken = chatToken.VoiceVideoCallToken;
770
+ chatId = chatToken.ChatId, token = chatToken.Token, regionGtms = chatToken.RegionGtms, expiresIn = chatToken.ExpiresIn, visitorId = chatToken.VisitorId, voiceVideoCallToken = chatToken.VoiceVideoCallToken, acsEndpoint = chatToken.ACSEndpoint, attachmentConfiguration = chatToken.AttachmentConfiguration;
632
771
  this.chatToken = {
633
772
  chatId: chatId,
634
773
  regionGTMS: JSON.parse(regionGtms),
@@ -636,15 +775,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
636
775
  token: token,
637
776
  expiresIn: expiresIn,
638
777
  visitorId: visitorId,
639
- voiceVideoCallToken: voiceVideoCallToken
778
+ voiceVideoCallToken: voiceVideoCallToken,
779
+ acsEndpoint: acsEndpoint,
640
780
  };
781
+ if (attachmentConfiguration && attachmentConfiguration.AttachmentServiceEndpoint) {
782
+ this.chatToken.amsEndpoint = attachmentConfiguration.AttachmentServiceEndpoint;
783
+ }
641
784
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetChatToken, {
642
785
  RequestId: this.requestId,
643
786
  ChatId: this.chatToken.chatId
644
787
  });
645
788
  return [3 /*break*/, 4];
646
789
  case 3:
647
- error_8 = _c.sent();
790
+ error_11 = _c.sent();
648
791
  exceptionDetails = {
649
792
  response: "OCClientGetChatTokenFailed"
650
793
  };
@@ -653,7 +796,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
653
796
  ChatId: this.chatToken.chatId,
654
797
  ExceptionDetails: JSON.stringify(exceptionDetails),
655
798
  });
656
- console.error("OmnichannelChatSDK/getChatToken/error " + error_8);
799
+ console.error("OmnichannelChatSDK/getChatToken/error " + error_11);
657
800
  return [3 /*break*/, 4];
658
801
  case 4: return [3 /*break*/, 6];
659
802
  case 5:
@@ -674,11 +817,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
674
817
  return [2 /*return*/, ''];
675
818
  }
676
819
  if (this.chatToken.voiceVideoCallToken) {
677
- console.log("calling:acs");
820
+ /* istanbul ignore next */
821
+ this.debug && console.log("calling:acs");
678
822
  return [2 /*return*/, this.chatToken.voiceVideoCallToken.Token];
679
823
  }
680
824
  else {
681
- console.log("calling:skype");
825
+ /* istanbul ignore next */
826
+ this.debug && console.log("calling:skype");
682
827
  return [2 /*return*/, this.chatToken.token];
683
828
  }
684
829
  return [2 /*return*/];
@@ -688,8 +833,34 @@ var OmnichannelChatSDK = /** @class */ (function () {
688
833
  OmnichannelChatSDK.prototype.getMessages = function () {
689
834
  var _a;
690
835
  return __awaiter(this, void 0, void 0, function () {
691
- return __generator(this, function (_b) {
692
- return [2 /*return*/, (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.getMessages()];
836
+ var messages, _b;
837
+ return __generator(this, function (_c) {
838
+ switch (_c.label) {
839
+ case 0:
840
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetMessages, {
841
+ RequestId: this.requestId,
842
+ ChatId: this.chatToken.chatId
843
+ });
844
+ _c.label = 1;
845
+ case 1:
846
+ _c.trys.push([1, 3, , 4]);
847
+ return [4 /*yield*/, ((_a = this.conversation) === null || _a === void 0 ? void 0 : _a.getMessages())];
848
+ case 2:
849
+ messages = _c.sent();
850
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetMessages, {
851
+ RequestId: this.requestId,
852
+ ChatId: this.chatToken.chatId
853
+ });
854
+ return [2 /*return*/, messages];
855
+ case 3:
856
+ _b = _c.sent();
857
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetMessages, {
858
+ RequestId: this.requestId,
859
+ ChatId: this.chatToken.chatId
860
+ });
861
+ return [3 /*break*/, 4];
862
+ case 4: return [2 /*return*/];
863
+ }
693
864
  });
694
865
  });
695
866
  };
@@ -701,131 +872,283 @@ var OmnichannelChatSDK = /** @class */ (function () {
701
872
  });
702
873
  };
703
874
  OmnichannelChatSDK.prototype.sendMessage = function (message) {
875
+ var _a;
704
876
  return __awaiter(this, void 0, void 0, function () {
705
- var _a, disable, maskingCharacter, content, _i, _b, maskingRule, regex, match, replaceStr, messageToSend;
706
- return __generator(this, function (_c) {
707
- _a = this.chatSDKConfig.dataMasking, disable = _a.disable, maskingCharacter = _a.maskingCharacter;
708
- content = message.content;
709
- if (Object.keys(this.dataMaskingRules).length > 0 && !disable) {
710
- for (_i = 0, _b = Object.values(this.dataMaskingRules); _i < _b.length; _i++) {
711
- maskingRule = _b[_i];
712
- regex = new RegExp(maskingRule, 'g');
713
- match = void 0;
714
- while (match = regex.exec(content)) { // eslint-disable-line no-cond-assign
715
- replaceStr = match[0].replace(/./g, maskingCharacter);
716
- content = content.replace(match[0], replaceStr);
877
+ var _b, disable, maskingCharacter, content, _i, _c, maskingRule, regex, match, replaceStr, sendMessageRequest, error_12, messageToSend, _d;
878
+ return __generator(this, function (_e) {
879
+ switch (_e.label) {
880
+ case 0:
881
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.SendMessages, {
882
+ RequestId: this.requestId,
883
+ ChatId: this.chatToken.chatId
884
+ });
885
+ _b = this.chatSDKConfig.dataMasking, disable = _b.disable, maskingCharacter = _b.maskingCharacter;
886
+ content = message.content;
887
+ if (Object.keys(this.dataMaskingRules).length > 0 && !disable) {
888
+ for (_i = 0, _c = Object.values(this.dataMaskingRules); _i < _c.length; _i++) {
889
+ maskingRule = _c[_i];
890
+ regex = new RegExp(maskingRule, 'g');
891
+ match = void 0;
892
+ while (match = regex.exec(content)) { // eslint-disable-line no-cond-assign
893
+ replaceStr = match[0].replace(/./g, maskingCharacter);
894
+ content = content.replace(match[0], replaceStr);
895
+ }
896
+ }
717
897
  }
718
- }
719
- }
720
- message.content = content;
721
- messageToSend = {
722
- content: message.content,
723
- timestamp: new Date(),
724
- contentType: MessageContentType_1.default.Text,
725
- deliveryMode: DeliveryMode_1.default.Bridged,
726
- messageType: MessageType_1.default.UserMessage,
727
- properties: undefined,
728
- tags: __spreadArrays(MessageTags_1.defaultMessageTags),
729
- sender: {
730
- displayName: "Customer",
731
- id: "customer",
732
- type: PersonType_1.default.User
733
- }
734
- };
735
- if (message.tags) {
736
- messageToSend.tags = message.tags;
737
- }
738
- if (message.timestamp) {
739
- messageToSend.timestamp = message.timestamp;
898
+ message.content = content;
899
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 5];
900
+ sendMessageRequest = {
901
+ content: message.content,
902
+ };
903
+ sendMessageRequest.metadata = {
904
+ widgetId: this.omnichannelConfig.widgetId,
905
+ clientMessageId: Date.now().toString()
906
+ };
907
+ if (message.metadata) {
908
+ sendMessageRequest.metadata = __assign(__assign({}, sendMessageRequest.metadata), message.metadata);
909
+ }
910
+ _e.label = 1;
911
+ case 1:
912
+ _e.trys.push([1, 3, , 4]);
913
+ return [4 /*yield*/, ((_a = this.conversation) === null || _a === void 0 ? void 0 : _a.sendMessage(sendMessageRequest))];
914
+ case 2:
915
+ _e.sent();
916
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendMessages, {
917
+ RequestId: this.requestId,
918
+ ChatId: this.chatToken.chatId
919
+ });
920
+ return [3 /*break*/, 4];
921
+ case 3:
922
+ error_12 = _e.sent();
923
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendMessages, {
924
+ RequestId: this.requestId,
925
+ ChatId: this.chatToken.chatId
926
+ });
927
+ throw new Error('ChatSDKSendMessageFailed');
928
+ case 4: return [3 /*break*/, 9];
929
+ case 5:
930
+ messageToSend = {
931
+ content: message.content,
932
+ timestamp: new Date(),
933
+ contentType: MessageContentType_1.default.Text,
934
+ deliveryMode: DeliveryMode_1.default.Bridged,
935
+ messageType: MessageType_1.default.UserMessage,
936
+ properties: undefined,
937
+ tags: __spreadArrays(MessageTags_1.defaultMessageTags),
938
+ sender: {
939
+ displayName: "Customer",
940
+ id: "customer",
941
+ type: PersonType_1.default.User
942
+ }
943
+ };
944
+ if (message.tags) {
945
+ messageToSend.tags = message.tags;
946
+ }
947
+ if (message.timestamp) {
948
+ messageToSend.timestamp = message.timestamp;
949
+ }
950
+ _e.label = 6;
951
+ case 6:
952
+ _e.trys.push([6, 8, , 9]);
953
+ return [4 /*yield*/, this.conversation.sendMessage(messageToSend)];
954
+ case 7:
955
+ _e.sent();
956
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendMessages, {
957
+ RequestId: this.requestId,
958
+ ChatId: this.chatToken.chatId
959
+ });
960
+ return [3 /*break*/, 9];
961
+ case 8:
962
+ _d = _e.sent();
963
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendMessages, {
964
+ RequestId: this.requestId,
965
+ ChatId: this.chatToken.chatId
966
+ });
967
+ throw new Error('ChatSDKSendMessageFailed');
968
+ case 9: return [2 /*return*/];
740
969
  }
741
- return [2 /*return*/, this.conversation.sendMessage(messageToSend)];
742
970
  });
743
971
  });
744
972
  };
745
973
  OmnichannelChatSDK.prototype.onNewMessage = function (onNewMessageCallback, optionalParams) {
746
- var _a;
974
+ var _a, _b;
747
975
  if (optionalParams === void 0) { optionalParams = {}; }
748
976
  return __awaiter(this, void 0, void 0, function () {
749
- var postedMessages, messages, _i, _b, message, clientmessageid;
750
- return __generator(this, function (_c) {
751
- switch (_c.label) {
977
+ var postedMessages_1, messages, _i, _c, message, id, postedMessages_2, messages, _d, _e, message, clientmessageid, omnichannelMessage;
978
+ var _this = this;
979
+ return __generator(this, function (_f) {
980
+ switch (_f.label) {
752
981
  case 0:
753
- postedMessages = new Set();
982
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.OnNewMessage, {
983
+ RequestId: this.requestId,
984
+ ChatId: this.chatToken.chatId
985
+ });
986
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 3];
987
+ postedMessages_1 = new Set();
754
988
  if (!optionalParams.rehydrate) return [3 /*break*/, 2];
755
989
  this.debug && console.log('[OmnichannelChatSDK][onNewMessage] rehydrate');
756
990
  return [4 /*yield*/, this.getMessages()];
757
991
  case 1:
758
- messages = _c.sent();
992
+ messages = _f.sent();
993
+ for (_i = 0, _c = messages.reverse(); _i < _c.length; _i++) {
994
+ message = _c[_i];
995
+ id = message.id;
996
+ if (postedMessages_1.has(id)) {
997
+ continue;
998
+ }
999
+ postedMessages_1.add(id);
1000
+ onNewMessageCallback(message);
1001
+ }
1002
+ _f.label = 2;
1003
+ case 2:
1004
+ try {
1005
+ (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnNewMessage(function (event) {
1006
+ var id = event.id;
1007
+ var omnichannelMessage = createOmnichannelMessage_1.default(event, {
1008
+ liveChatVersion: _this.liveChatVersion,
1009
+ debug: _this.debug
1010
+ });
1011
+ if (!postedMessages_1.has(id)) {
1012
+ onNewMessageCallback(omnichannelMessage);
1013
+ postedMessages_1.add(id);
1014
+ }
1015
+ });
1016
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnNewMessage, {
1017
+ RequestId: this.requestId,
1018
+ ChatId: this.chatToken.chatId
1019
+ });
1020
+ }
1021
+ catch (_g) {
1022
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnNewMessage, {
1023
+ RequestId: this.requestId,
1024
+ ChatId: this.chatToken.chatId
1025
+ });
1026
+ }
1027
+ return [3 /*break*/, 6];
1028
+ case 3:
1029
+ postedMessages_2 = new Set();
1030
+ if (!optionalParams.rehydrate) return [3 /*break*/, 5];
1031
+ this.debug && console.log('[OmnichannelChatSDK][onNewMessage] rehydrate');
1032
+ return [4 /*yield*/, this.getMessages()];
1033
+ case 4:
1034
+ messages = _f.sent();
759
1035
  if (messages) {
760
- for (_i = 0, _b = messages.reverse(); _i < _b.length; _i++) {
761
- message = _b[_i];
1036
+ for (_d = 0, _e = messages.reverse(); _d < _e.length; _d++) {
1037
+ message = _e[_d];
762
1038
  clientmessageid = message.clientmessageid;
763
- if (postedMessages.has(clientmessageid)) {
1039
+ if (postedMessages_2.has(clientmessageid)) {
764
1040
  continue;
765
1041
  }
766
- postedMessages.add(clientmessageid);
767
- onNewMessageCallback(message);
1042
+ postedMessages_2.add(clientmessageid);
1043
+ omnichannelMessage = createOmnichannelMessage_1.default(message, {
1044
+ liveChatVersion: this.liveChatVersion,
1045
+ debug: this.debug
1046
+ });
1047
+ onNewMessageCallback(omnichannelMessage);
768
1048
  }
769
1049
  }
770
- _c.label = 2;
771
- case 2:
772
- (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnNewMessage(function (message) {
773
- var clientmessageid = message.clientmessageid, messageType = message.messageType;
774
- // Filter out customer messages
775
- if (utilities_1.isCustomerMessage(message)) {
776
- return;
777
- }
778
- // Skip duplicates
779
- if (postedMessages.has(clientmessageid)) {
780
- return;
781
- }
782
- if (messageType !== MessageType_1.default.Typing) {
783
- onNewMessageCallback(message);
784
- }
785
- });
786
- return [2 /*return*/];
1050
+ _f.label = 5;
1051
+ case 5:
1052
+ try {
1053
+ (_b = this.conversation) === null || _b === void 0 ? void 0 : _b.registerOnNewMessage(function (message) {
1054
+ var clientmessageid = message.clientmessageid, messageType = message.messageType;
1055
+ // Filter out customer messages
1056
+ if (utilities_1.isCustomerMessage(message)) {
1057
+ return;
1058
+ }
1059
+ // Skip duplicates
1060
+ if (postedMessages_2.has(clientmessageid)) {
1061
+ return;
1062
+ }
1063
+ if (messageType !== MessageType_1.default.Typing) {
1064
+ var omnichannelMessage = createOmnichannelMessage_1.default(message, {
1065
+ liveChatVersion: _this.liveChatVersion,
1066
+ debug: _this.debug
1067
+ });
1068
+ onNewMessageCallback(omnichannelMessage);
1069
+ }
1070
+ });
1071
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnNewMessage, {
1072
+ RequestId: this.requestId,
1073
+ ChatId: this.chatToken.chatId
1074
+ });
1075
+ }
1076
+ catch (_h) {
1077
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnNewMessage, {
1078
+ RequestId: this.requestId,
1079
+ ChatId: this.chatToken.chatId
1080
+ });
1081
+ }
1082
+ _f.label = 6;
1083
+ case 6: return [2 /*return*/];
787
1084
  }
788
1085
  });
789
1086
  });
790
1087
  };
791
1088
  OmnichannelChatSDK.prototype.sendTypingEvent = function () {
792
1089
  return __awaiter(this, void 0, void 0, function () {
793
- var typingPayload, members, botMembers, error_9;
1090
+ var error_13, typingPayload, members, botMembers, error_14;
794
1091
  return __generator(this, function (_a) {
795
1092
  switch (_a.label) {
796
1093
  case 0:
797
- typingPayload = "{isTyping: 0}";
798
1094
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.SendTypingEvent, {
799
1095
  RequestId: this.requestId,
800
1096
  ChatId: this.chatToken.chatId
801
1097
  });
1098
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 6];
802
1099
  _a.label = 1;
803
1100
  case 1:
804
- _a.trys.push([1, 5, , 6]);
805
- return [4 /*yield*/, this.conversation.indicateTypingStatus(0)];
1101
+ _a.trys.push([1, 4, , 5]);
1102
+ return [4 /*yield*/, this.OCClient.sendTypingIndicator(this.requestId, LiveChatVersion_1.default.V2, {
1103
+ customerDisplayName: ACSParticipantDisplayName_1.default.Customer
1104
+ })];
806
1105
  case 2:
807
1106
  _a.sent();
808
- return [4 /*yield*/, this.conversation.getMembers()];
1107
+ return [4 /*yield*/, this.conversation.sendTyping()];
809
1108
  case 3:
1109
+ _a.sent();
1110
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendTypingEvent, {
1111
+ RequestId: this.requestId,
1112
+ ChatId: this.chatToken.chatId
1113
+ });
1114
+ return [3 /*break*/, 5];
1115
+ case 4:
1116
+ error_13 = _a.sent();
1117
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
1118
+ RequestId: this.requestId,
1119
+ ChatId: this.chatToken.chatId
1120
+ });
1121
+ throw new Error('OCClientSendTypingFailed');
1122
+ case 5: return [3 /*break*/, 12];
1123
+ case 6:
1124
+ typingPayload = "{isTyping: 0}";
1125
+ _a.label = 7;
1126
+ case 7:
1127
+ _a.trys.push([7, 11, , 12]);
1128
+ return [4 /*yield*/, this.conversation.indicateTypingStatus(0)];
1129
+ case 8:
1130
+ _a.sent();
1131
+ return [4 /*yield*/, this.conversation.getMembers()];
1132
+ case 9:
810
1133
  members = _a.sent();
811
1134
  botMembers = members.filter(function (member) { return member.type === PersonType_1.default.Bot; });
812
1135
  return [4 /*yield*/, this.conversation.sendMessageToBot(botMembers[0].id, { payload: typingPayload })];
813
- case 4:
1136
+ case 10:
814
1137
  _a.sent();
815
1138
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendTypingEvent, {
816
1139
  RequestId: this.requestId,
817
1140
  ChatId: this.chatToken.chatId
818
1141
  });
819
- return [3 /*break*/, 6];
820
- case 5:
821
- error_9 = _a.sent();
1142
+ return [3 /*break*/, 12];
1143
+ case 11:
1144
+ error_14 = _a.sent();
822
1145
  console.error("OmnichannelChatSDK/sendTypingEvent/error");
823
1146
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
824
1147
  RequestId: this.requestId,
825
1148
  ChatId: this.chatToken.chatId
826
1149
  });
827
- return [2 /*return*/, error_9];
828
- case 6: return [2 /*return*/];
1150
+ return [2 /*return*/, error_14];
1151
+ case 12: return [2 /*return*/];
829
1152
  }
830
1153
  });
831
1154
  });
@@ -834,16 +1157,49 @@ var OmnichannelChatSDK = /** @class */ (function () {
834
1157
  var _a;
835
1158
  return __awaiter(this, void 0, void 0, function () {
836
1159
  return __generator(this, function (_b) {
837
- (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnNewMessage(function (message) {
838
- var messageType = message.messageType;
839
- // Filter out customer messages
840
- if (utilities_1.isCustomerMessage(message)) {
841
- return;
1160
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.OnTypingEvent, {
1161
+ RequestId: this.requestId,
1162
+ ChatId: this.chatToken.chatId
1163
+ });
1164
+ if (this.liveChatVersion === LiveChatVersion_1.default.V2) {
1165
+ try {
1166
+ this.conversation.onTypingEvent(onTypingEventCallback);
1167
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnTypingEvent, {
1168
+ RequestId: this.requestId,
1169
+ ChatId: this.chatToken.chatId
1170
+ });
842
1171
  }
843
- if (messageType === MessageType_1.default.Typing) {
844
- onTypingEventCallback(message);
1172
+ catch (_c) {
1173
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnTypingEvent, {
1174
+ RequestId: this.requestId,
1175
+ ChatId: this.chatToken.chatId
1176
+ });
845
1177
  }
846
- });
1178
+ }
1179
+ else {
1180
+ try {
1181
+ (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnNewMessage(function (message) {
1182
+ var messageType = message.messageType;
1183
+ // Filter out customer messages
1184
+ if (utilities_1.isCustomerMessage(message)) {
1185
+ return;
1186
+ }
1187
+ if (messageType === MessageType_1.default.Typing) {
1188
+ onTypingEventCallback(message);
1189
+ }
1190
+ });
1191
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnTypingEvent, {
1192
+ RequestId: this.requestId,
1193
+ ChatId: this.chatToken.chatId
1194
+ });
1195
+ }
1196
+ catch (_d) {
1197
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnTypingEvent, {
1198
+ RequestId: this.requestId,
1199
+ ChatId: this.chatToken.chatId
1200
+ });
1201
+ }
1202
+ }
847
1203
  return [2 /*return*/];
848
1204
  });
849
1205
  });
@@ -857,53 +1213,130 @@ var OmnichannelChatSDK = /** @class */ (function () {
857
1213
  RequestId: this.requestId,
858
1214
  ChatId: this.chatToken.chatId
859
1215
  });
860
- try {
861
- (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnThreadUpdate(function (message) {
862
- var members = message.members;
863
- // Agent ending conversation would have 1 member left in the chat thread
864
- if (members.length === 1) {
865
- onAgentEndSessionCallback(message);
866
- if (_this.refreshTokenTimer !== null) {
867
- clearInterval(_this.refreshTokenTimer);
868
- _this.refreshTokenTimer = null;
869
- }
870
- }
871
- });
872
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
873
- RequestId: this.requestId,
874
- ChatId: this.chatToken.chatId
875
- });
1216
+ if (this.liveChatVersion === LiveChatVersion_1.default.V2) {
1217
+ try {
1218
+ this.conversation.registerOnThreadUpdate(function (event) {
1219
+ onAgentEndSessionCallback(event);
1220
+ });
1221
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1222
+ RequestId: this.requestId,
1223
+ ChatId: this.chatToken.chatId
1224
+ });
1225
+ }
1226
+ catch (error) {
1227
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1228
+ RequestId: this.requestId,
1229
+ ChatId: this.chatToken.chatId
1230
+ });
1231
+ }
876
1232
  }
877
- catch (error) {
878
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
879
- RequestId: this.requestId,
880
- ChatId: this.chatToken.chatId
881
- });
1233
+ else {
1234
+ try {
1235
+ (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnThreadUpdate(function (message) {
1236
+ var members = message.members;
1237
+ // Agent ending conversation would have 1 member left in the chat thread
1238
+ if (members.length === 1) {
1239
+ onAgentEndSessionCallback(message);
1240
+ if (_this.refreshTokenTimer !== null) {
1241
+ clearInterval(_this.refreshTokenTimer);
1242
+ _this.refreshTokenTimer = null;
1243
+ }
1244
+ }
1245
+ });
1246
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1247
+ RequestId: this.requestId,
1248
+ ChatId: this.chatToken.chatId
1249
+ });
1250
+ }
1251
+ catch (error) {
1252
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1253
+ RequestId: this.requestId,
1254
+ ChatId: this.chatToken.chatId
1255
+ });
1256
+ }
882
1257
  }
883
1258
  return [2 /*return*/];
884
1259
  });
885
1260
  });
886
1261
  };
887
1262
  OmnichannelChatSDK.prototype.uploadFileAttachment = function (fileInfo) {
1263
+ var _a, _b, _c, _d;
888
1264
  return __awaiter(this, void 0, void 0, function () {
889
- var fileMetadata, messageToSend, error_10;
890
- return __generator(this, function (_a) {
891
- switch (_a.label) {
1265
+ var createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_15, fileMetadata, messageToSend, error_16;
1266
+ return __generator(this, function (_e) {
1267
+ switch (_e.label) {
892
1268
  case 0:
893
1269
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.UploadFileAttachment, {
894
1270
  RequestId: this.requestId,
895
1271
  ChatId: this.chatToken.chatId
896
1272
  });
897
- if (!(platform_1.default.isReactNative() || platform_1.default.isNode())) return [3 /*break*/, 2];
898
- return [4 /*yield*/, this.conversation.sendFileData(fileInfo, FileSharingProtocolType_1.default.AmsBasedFileSharing)];
1273
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 7];
1274
+ 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))];
899
1275
  case 1:
900
- fileMetadata = _a.sent();
901
- return [3 /*break*/, 4];
902
- case 2: return [4 /*yield*/, this.conversation.uploadFile(fileInfo, FileSharingProtocolType_1.default.AmsBasedFileSharing)];
1276
+ createObjectResponse = _e.sent();
1277
+ documentId = createObjectResponse.id;
1278
+ return [4 /*yield*/, ((_c = this.AMSClient) === null || _c === void 0 ? void 0 : _c.uploadDocument(documentId, fileInfo))];
1279
+ case 2:
1280
+ uploadDocumentResponse = _e.sent();
1281
+ fileIdsProperty = {
1282
+ amsReferences: JSON.stringify([documentId])
1283
+ };
1284
+ fileMetaProperty = {
1285
+ amsMetadata: JSON.stringify([{
1286
+ contentType: fileInfo.type,
1287
+ fileName: fileInfo.name
1288
+ }])
1289
+ };
1290
+ sendMessageRequest = {
1291
+ content: '',
1292
+ metadata: __assign(__assign({ widgetId: this.omnichannelConfig.widgetId, clientMessageId: Date.now().toString() }, fileIdsProperty), fileMetaProperty)
1293
+ };
1294
+ messageToSend = {
1295
+ content: "",
1296
+ timestamp: new Date(),
1297
+ contentType: MessageContentType_1.default.Text,
1298
+ deliveryMode: DeliveryMode_1.default.Bridged,
1299
+ messageType: MessageType_1.default.UserMessage,
1300
+ tags: __spreadArrays(MessageTags_1.defaultMessageTags),
1301
+ sender: {
1302
+ displayName: "Customer",
1303
+ id: "customer",
1304
+ type: PersonType_1.default.User,
1305
+ },
1306
+ fileMetadata: uploadDocumentResponse
1307
+ };
1308
+ _e.label = 3;
903
1309
  case 3:
904
- fileMetadata = _a.sent();
905
- _a.label = 4;
1310
+ _e.trys.push([3, 5, , 6]);
1311
+ return [4 /*yield*/, ((_d = this.conversation) === null || _d === void 0 ? void 0 : _d.sendMessage(sendMessageRequest))];
906
1312
  case 4:
1313
+ _e.sent();
1314
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.UploadFileAttachment, {
1315
+ RequestId: this.requestId,
1316
+ ChatId: this.chatToken.chatId
1317
+ });
1318
+ return [2 /*return*/, messageToSend];
1319
+ case 5:
1320
+ error_15 = _e.sent();
1321
+ console.error("OmnichannelChatSDK/uploadFileAttachment/sendMessage/error");
1322
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
1323
+ RequestId: this.requestId,
1324
+ ChatId: this.chatToken.chatId
1325
+ });
1326
+ return [3 /*break*/, 6];
1327
+ case 6: return [2 /*return*/, {}];
1328
+ case 7:
1329
+ fileMetadata = void 0;
1330
+ if (!(platform_1.default.isReactNative() || platform_1.default.isNode())) return [3 /*break*/, 9];
1331
+ return [4 /*yield*/, this.conversation.sendFileData(fileInfo, FileSharingProtocolType_1.default.AmsBasedFileSharing)];
1332
+ case 8:
1333
+ fileMetadata = _e.sent();
1334
+ return [3 /*break*/, 11];
1335
+ case 9: return [4 /*yield*/, this.conversation.uploadFile(fileInfo, FileSharingProtocolType_1.default.AmsBasedFileSharing)];
1336
+ case 10:
1337
+ fileMetadata = _e.sent();
1338
+ _e.label = 11;
1339
+ case 11:
907
1340
  messageToSend = {
908
1341
  content: "",
909
1342
  timestamp: new Date(),
@@ -918,60 +1351,84 @@ var OmnichannelChatSDK = /** @class */ (function () {
918
1351
  },
919
1352
  fileMetadata: fileMetadata
920
1353
  };
921
- _a.label = 5;
922
- case 5:
923
- _a.trys.push([5, 7, , 8]);
1354
+ _e.label = 12;
1355
+ case 12:
1356
+ _e.trys.push([12, 14, , 15]);
924
1357
  return [4 /*yield*/, this.conversation.sendFileMessage(fileMetadata, messageToSend)];
925
- case 6:
926
- _a.sent();
1358
+ case 13:
1359
+ _e.sent();
927
1360
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.UploadFileAttachment, {
928
1361
  RequestId: this.requestId,
929
1362
  ChatId: this.chatToken.chatId
930
1363
  });
931
1364
  return [2 /*return*/, messageToSend];
932
- case 7:
933
- error_10 = _a.sent();
934
- console.error("OmnichannelChatSDK/uploadFileAttachment/error: " + error_10);
1365
+ case 14:
1366
+ error_16 = _e.sent();
1367
+ console.error("OmnichannelChatSDK/uploadFileAttachment/error: " + error_16);
935
1368
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
936
1369
  RequestId: this.requestId,
937
1370
  ChatId: this.chatToken.chatId
938
1371
  });
939
- return [2 /*return*/, error_10];
940
- case 8: return [2 /*return*/];
1372
+ return [2 /*return*/, error_16];
1373
+ case 15: return [2 /*return*/];
941
1374
  }
942
1375
  });
943
1376
  });
944
1377
  };
945
1378
  OmnichannelChatSDK.prototype.downloadFileAttachment = function (fileMetadata) {
1379
+ var _a, _b;
946
1380
  return __awaiter(this, void 0, void 0, function () {
947
- var downloadedFile, error_11;
948
- return __generator(this, function (_a) {
949
- switch (_a.label) {
1381
+ var response, view_location, viewResponse, _c, downloadedFile, error_17;
1382
+ return __generator(this, function (_d) {
1383
+ switch (_d.label) {
950
1384
  case 0:
951
1385
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
952
1386
  RequestId: this.requestId,
953
1387
  ChatId: this.chatToken.chatId
954
1388
  });
955
- _a.label = 1;
1389
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 6];
1390
+ _d.label = 1;
956
1391
  case 1:
957
- _a.trys.push([1, 3, , 4]);
958
- return [4 /*yield*/, this.conversation.downloadFile(fileMetadata)];
1392
+ _d.trys.push([1, 4, , 5]);
1393
+ return [4 /*yield*/, ((_a = this.AMSClient) === null || _a === void 0 ? void 0 : _a.getViewStatus(fileMetadata))];
959
1394
  case 2:
960
- downloadedFile = _a.sent();
1395
+ response = _d.sent();
1396
+ view_location = response.view_location;
1397
+ return [4 /*yield*/, ((_b = this.AMSClient) === null || _b === void 0 ? void 0 : _b.getView(fileMetadata, view_location))];
1398
+ case 3:
1399
+ viewResponse = _d.sent();
1400
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
1401
+ RequestId: this.requestId,
1402
+ ChatId: this.chatToken.chatId
1403
+ });
1404
+ return [2 /*return*/, viewResponse];
1405
+ case 4:
1406
+ _c = _d.sent();
1407
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
1408
+ RequestId: this.requestId,
1409
+ ChatId: this.chatToken.chatId
1410
+ });
1411
+ throw new Error('DownloadFileAttachmentFailed');
1412
+ case 5: return [3 /*break*/, 9];
1413
+ case 6:
1414
+ _d.trys.push([6, 8, , 9]);
1415
+ return [4 /*yield*/, this.conversation.downloadFile(fileMetadata)];
1416
+ case 7:
1417
+ downloadedFile = _d.sent();
961
1418
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
962
1419
  RequestId: this.requestId,
963
1420
  ChatId: this.chatToken.chatId
964
1421
  });
965
1422
  return [2 /*return*/, downloadedFile];
966
- case 3:
967
- error_11 = _a.sent();
968
- console.error("OmnichannelChatSDK/downloadFileAttachment/error: " + error_11);
1423
+ case 8:
1424
+ error_17 = _d.sent();
1425
+ console.error("OmnichannelChatSDK/downloadFileAttachment/error: " + error_17);
969
1426
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
970
1427
  RequestId: this.requestId,
971
1428
  ChatId: this.chatToken.chatId
972
1429
  });
973
1430
  throw new Error('DownloadFileAttachmentFailed');
974
- case 4: return [2 /*return*/];
1431
+ case 9: return [2 /*return*/];
975
1432
  }
976
1433
  });
977
1434
  });
@@ -1044,54 +1501,103 @@ var OmnichannelChatSDK = /** @class */ (function () {
1044
1501
  });
1045
1502
  };
1046
1503
  OmnichannelChatSDK.prototype.createChatAdapter = function (protocol) {
1047
- if (protocol === void 0) { protocol = ChatAdapterProtocols_1.default.IC3; }
1504
+ if (protocol === void 0) { protocol = null; }
1048
1505
  return __awaiter(this, void 0, void 0, function () {
1506
+ var supportedChatAdapterProtocols;
1049
1507
  var _this = this;
1050
1508
  return __generator(this, function (_a) {
1051
1509
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1052
1510
  return [2 /*return*/, Promise.reject('ChatAdapter is only supported on browser')];
1053
1511
  }
1054
- if (protocol !== ChatAdapterProtocols_1.default.IC3) {
1512
+ supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
1513
+ if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
1055
1514
  return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
1056
1515
  }
1057
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1058
- var ic3AdapterCDNUrl;
1059
- var _this = this;
1060
- var _a;
1061
- return __generator(this, function (_b) {
1062
- switch (_b.label) {
1063
- case 0:
1064
- ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol);
1065
- (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1066
- IC3Adapter: ic3AdapterCDNUrl
1067
- });
1068
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1069
- return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
1070
- /* istanbul ignore next */
1071
- _this.debug && console.debug('IC3Adapter loaded!');
1072
- var adapterConfig = {
1073
- chatToken: _this.chatToken,
1074
- userDisplayName: 'Customer',
1075
- userId: 'teamsvisitor',
1076
- sdkURL: _this.resolveIC3ClientUrl(),
1077
- sdk: _this.IC3Client
1078
- };
1079
- var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
1080
- adapter.logger = _this.ic3ClientLogger;
1081
- // Keep iframe communication alive to reuse the same IC3Client instance
1082
- window.Microsoft.BotFramework.WebChat.IC3SDKProvider.disposeSdk = function () { }; // eslint-disable-line @typescript-eslint/no-empty-function
1083
- _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1084
- resolve(adapter);
1085
- }, function () {
1086
- _this.scenarioMarker.failScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1087
- reject('Failed to load IC3Adapter');
1088
- })];
1089
- case 1:
1090
- _b.sent();
1091
- return [2 /*return*/];
1092
- }
1093
- });
1094
- }); })];
1516
+ if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
1517
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1518
+ var egressMiddlewares, ingressMiddlewares, featuresOption, acsAdapterCDNUrl;
1519
+ var _this = this;
1520
+ var _a;
1521
+ return __generator(this, function (_b) {
1522
+ switch (_b.label) {
1523
+ case 0:
1524
+ egressMiddlewares = [createFormatEgressTagsMiddleware_1.default()];
1525
+ ingressMiddlewares = [createFormatIngressTagsMiddleware_1.default()];
1526
+ featuresOption = {
1527
+ enableAdaptiveCards: true,
1528
+ enableThreadMemberUpdateNotification: true,
1529
+ enableLeaveThreadOnWindowClosed: false,
1530
+ egressMiddleware: egressMiddlewares,
1531
+ ingressMiddleware: ingressMiddlewares
1532
+ };
1533
+ acsAdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.ACS);
1534
+ (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1535
+ ACSAdapter: acsAdapterCDNUrl
1536
+ });
1537
+ return [4 /*yield*/, WebUtils_1.loadScript(acsAdapterCDNUrl, function () {
1538
+ /* istanbul ignore next */
1539
+ _this.debug && console.debug('ACSAdapter loaded!');
1540
+ try {
1541
+ var ChatAdapter = window.ChatAdapter; // eslint-disable-line @typescript-eslint/no-explicit-any
1542
+ var fileManager = new AMSFileManager_1.default(_this.AMSClient, _this.acsAdapterLogger);
1543
+ var adapter = ChatAdapter.createACSAdapter(_this.chatToken.token, _this.chatToken.visitorId || 'teamsvisitor', _this.chatToken.chatId, _this.chatToken.acsEndpoint, fileManager, 1000, ACSParticipantDisplayName_1.default.Customer, undefined, undefined, // logger
1544
+ featuresOption);
1545
+ resolve(adapter);
1546
+ }
1547
+ catch (_a) {
1548
+ throw new Error('Failed to load ACSAdapter');
1549
+ }
1550
+ }, function () {
1551
+ reject('Failed to load ACSADapter');
1552
+ })];
1553
+ case 1:
1554
+ _b.sent();
1555
+ return [2 /*return*/];
1556
+ }
1557
+ });
1558
+ }); })];
1559
+ }
1560
+ else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
1561
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1562
+ var ic3AdapterCDNUrl;
1563
+ var _this = this;
1564
+ var _a;
1565
+ return __generator(this, function (_b) {
1566
+ switch (_b.label) {
1567
+ case 0:
1568
+ ic3AdapterCDNUrl = this.resolveChatAdapterUrl(protocol || ChatAdapterProtocols_1.default.IC3);
1569
+ (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1570
+ IC3Adapter: ic3AdapterCDNUrl
1571
+ });
1572
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1573
+ return [4 /*yield*/, WebUtils_1.loadScript(ic3AdapterCDNUrl, function () {
1574
+ /* istanbul ignore next */
1575
+ _this.debug && console.debug('IC3Adapter loaded!');
1576
+ var adapterConfig = {
1577
+ chatToken: _this.chatToken,
1578
+ userDisplayName: 'Customer',
1579
+ userId: 'teamsvisitor',
1580
+ sdkURL: _this.resolveIC3ClientUrl(),
1581
+ sdk: _this.IC3Client
1582
+ };
1583
+ var adapter = new window.Microsoft.BotFramework.WebChat.IC3Adapter(adapterConfig);
1584
+ adapter.logger = _this.ic3ClientLogger;
1585
+ // Keep iframe communication alive to reuse the same IC3Client instance
1586
+ window.Microsoft.BotFramework.WebChat.IC3SDKProvider.disposeSdk = function () { }; // eslint-disable-line @typescript-eslint/no-empty-function
1587
+ _this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1588
+ resolve(adapter);
1589
+ }, function () {
1590
+ _this.scenarioMarker.failScenario(TelemetryEvent_1.default.CreateIC3Adapter);
1591
+ reject('Failed to load IC3Adapter');
1592
+ })];
1593
+ case 1:
1594
+ _b.sent();
1595
+ return [2 /*return*/];
1596
+ }
1597
+ });
1598
+ }); })];
1599
+ }
1600
+ return [2 /*return*/, Promise.reject("ChatAdapter for protocol " + protocol + " currently not supported")];
1095
1601
  });
1096
1602
  });
1097
1603
  };
@@ -1118,33 +1624,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
1118
1624
  result = msdyn_widgetsnippet.match(widgetSnippetSourceRegex);
1119
1625
  if (result && result.length) {
1120
1626
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1121
- var spoolSDKCDNUrl, LiveChatWidgetLibCDNUrl;
1627
+ var LiveChatWidgetLibCDNUrl;
1122
1628
  var _this = this;
1123
- var _a, _b;
1124
- return __generator(this, function (_c) {
1125
- switch (_c.label) {
1629
+ var _a;
1630
+ return __generator(this, function (_b) {
1631
+ switch (_b.label) {
1126
1632
  case 0:
1127
- spoolSDKCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/spool-sdk/sdk.bundle.js";
1128
- (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1129
- SpoolSDK: spoolSDKCDNUrl
1130
- });
1131
1633
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
1132
- return [4 /*yield*/, WebUtils_1.loadScript(spoolSDKCDNUrl, function () {
1133
- /* istanbul ignore next */
1134
- _this.debug && console.debug(spoolSDKCDNUrl + " loaded!");
1135
- }, function () {
1136
- var exceptionDetails = {
1137
- response: "SpoolSDKLoadFailed"
1138
- };
1139
- _this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1140
- ExceptionDetails: JSON.stringify(exceptionDetails)
1141
- });
1142
- reject('Failed to load SpoolSDK');
1143
- })];
1144
- case 1:
1145
- _c.sent();
1146
- LiveChatWidgetLibCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/LiveChatWidgetLibs.min.js";
1147
- (_b = this.telemetry) === null || _b === void 0 ? void 0 : _b.setCDNPackages({
1634
+ LiveChatWidgetLibCDNUrl = result[1] + "/livechatwidget/WebChatControl/lib/CallingBundle.js";
1635
+ (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
1148
1636
  VoiceVideoCalling: LiveChatWidgetLibCDNUrl
1149
1637
  });
1150
1638
  return [4 /*yield*/, WebUtils_1.loadScript(LiveChatWidgetLibCDNUrl, function () { return __awaiter(_this, void 0, void 0, function () {
@@ -1175,8 +1663,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1175
1663
  return [2 /*return*/];
1176
1664
  });
1177
1665
  }); })];
1178
- case 2:
1179
- _c.sent();
1666
+ case 1:
1667
+ _b.sent();
1180
1668
  return [2 /*return*/];
1181
1669
  }
1182
1670
  });
@@ -1187,6 +1675,95 @@ var OmnichannelChatSDK = /** @class */ (function () {
1187
1675
  });
1188
1676
  });
1189
1677
  };
1678
+ OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
1679
+ return __awaiter(this, void 0, void 0, function () {
1680
+ var conversationId, chatConfig, liveWSAndLiveChatEngJoin, chatWidgetLanguage, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, postConversationSurveyOwnerId, msdyn_localeid, localeId, liveWorkItemDetails, participantJoined, surveyInviteLinkRequest, optionalParams, surveyInviteLinkResponse, surveyInviteLink, formsProLocale, postChatContext, ex_1;
1681
+ return __generator(this, function (_a) {
1682
+ switch (_a.label) {
1683
+ case 0:
1684
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1685
+ RequestId: this.requestId
1686
+ });
1687
+ _a.label = 1;
1688
+ case 1:
1689
+ _a.trys.push([1, 6, , 7]);
1690
+ chatConfig = this.liveChatConfig;
1691
+ liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin, chatWidgetLanguage = chatConfig.ChatWidgetLanguage;
1692
+ msdyn_postconversationsurveyenable = liveWSAndLiveChatEngJoin.msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_sourcesurveyidentifier, postConversationSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationSurveyOwnerId;
1693
+ msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
1694
+ localeId = msdyn_localeid !== null && msdyn_localeid !== void 0 ? msdyn_localeid : "1033";
1695
+ if (!msdyn_postconversationsurveyenable) return [3 /*break*/, 4];
1696
+ return [4 /*yield*/, this.OCClient.getLWIDetails(this.requestId)];
1697
+ case 2:
1698
+ liveWorkItemDetails = _a.sent();
1699
+ participantJoined = (liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.CanRenderPostChat) && (liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.CanRenderPostChat) === "True";
1700
+ conversationId = liveWorkItemDetails === null || liveWorkItemDetails === void 0 ? void 0 : liveWorkItemDetails.ConversationId;
1701
+ surveyInviteLinkRequest = {
1702
+ "FormId": msfp_sourcesurveyidentifier,
1703
+ "ConversationId": conversationId,
1704
+ "OCLocaleCode": locale_1.getLocaleStringFromId(localeId)
1705
+ };
1706
+ optionalParams = {
1707
+ "requestId": this.requestId
1708
+ };
1709
+ if (this.authenticatedUserToken) {
1710
+ optionalParams.authenticatedUserToken = this.authenticatedUserToken;
1711
+ }
1712
+ return [4 /*yield*/, this.OCClient.getSurveyInviteLink(postConversationSurveyOwnerId, surveyInviteLinkRequest)];
1713
+ case 3:
1714
+ surveyInviteLinkResponse = _a.sent();
1715
+ surveyInviteLink = void 0, formsProLocale = void 0;
1716
+ if (surveyInviteLinkResponse != null) {
1717
+ if (surveyInviteLinkResponse.inviteList != null && surveyInviteLinkResponse.inviteList.length == 1) {
1718
+ surveyInviteLink = surveyInviteLinkResponse.inviteList[0].invitationLink;
1719
+ }
1720
+ else {
1721
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1722
+ ConversationId: conversationId,
1723
+ RequestId: this.requestId,
1724
+ ExceptionDetails: "Survey Invite link failed to send response."
1725
+ });
1726
+ return [2 /*return*/, Promise.reject("Survey Invite link failed to send response.")];
1727
+ }
1728
+ if (surveyInviteLinkResponse.formsProLocaleCode != null) {
1729
+ formsProLocale = surveyInviteLinkResponse.formsProLocaleCode;
1730
+ }
1731
+ postChatContext = {
1732
+ participantJoined: participantJoined,
1733
+ surveyInviteLink: surveyInviteLink,
1734
+ formsProLocale: formsProLocale
1735
+ };
1736
+ return [2 /*return*/, Promise.resolve(postChatContext)];
1737
+ }
1738
+ else {
1739
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1740
+ ConversationId: conversationId,
1741
+ RequestId: this.requestId,
1742
+ ExceptionDetails: "surveyInviteLinkResponse is null."
1743
+ });
1744
+ return [2 /*return*/, Promise.reject("surveyInviteLinkResponse is null.")];
1745
+ }
1746
+ return [3 /*break*/, 5];
1747
+ case 4:
1748
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1749
+ RequestId: this.requestId,
1750
+ ExceptionDetails: "Post Chat Survey is disabled. Please check the Omnichannel Administration Portal."
1751
+ });
1752
+ return [2 /*return*/, Promise.reject("Post Chat is disabled from admin side.")];
1753
+ case 5: return [3 /*break*/, 7];
1754
+ case 6:
1755
+ ex_1 = _a.sent();
1756
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
1757
+ ConversationId: conversationId,
1758
+ RequestId: this.requestId,
1759
+ ExceptionDetails: JSON.stringify(ex_1)
1760
+ });
1761
+ return [2 /*return*/, Promise.reject("Retrieving post chat context failed " + JSON.stringify(ex_1))];
1762
+ case 7: return [2 /*return*/];
1763
+ }
1764
+ });
1765
+ });
1766
+ };
1190
1767
  OmnichannelChatSDK.prototype.getIC3Client = function () {
1191
1768
  return __awaiter(this, void 0, void 0, function () {
1192
1769
  var IC3Client;
@@ -1272,15 +1849,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
1272
1849
  };
1273
1850
  OmnichannelChatSDK.prototype.getChatConfig = function () {
1274
1851
  return __awaiter(this, void 0, void 0, function () {
1275
- var liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, token, error_12;
1276
- return __generator(this, function (_a) {
1277
- switch (_a.label) {
1852
+ 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;
1853
+ return __generator(this, function (_b) {
1854
+ switch (_b.label) {
1278
1855
  case 0:
1279
- _a.trys.push([0, 5, , 6]);
1856
+ _b.trys.push([0, 8, , 9]);
1280
1857
  return [4 /*yield*/, this.OCClient.getChatConfig()];
1281
1858
  case 1:
1282
- liveChatConfig = _a.sent();
1283
- dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin;
1859
+ liveChatConfig = _b.sent();
1860
+ dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion;
1861
+ this.liveChatVersion = liveChatVersion || LiveChatVersion_1.default.V1;
1862
+ /* istanbul ignore next */
1863
+ this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] " + this.liveChatVersion);
1284
1864
  setting = dataMaskingConfig.setting;
1285
1865
  if (setting.msdyn_maskforcustomer) {
1286
1866
  this.dataMaskingRules = dataMaskingConfig.dataMaskingRules;
@@ -1300,23 +1880,47 @@ var OmnichannelChatSDK = /** @class */ (function () {
1300
1880
  if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
1301
1881
  this.preChatSurvey = preChatSurvey;
1302
1882
  }
1303
- if (!this.authSettings) return [3 /*break*/, 4];
1304
- if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 3];
1305
- this.debug && console.log("OmnichannelChatSDK/getChatConfig/auth settings with auth and getAuthToken!", this.authSettings, this.chatSDKConfig.getAuthToken);
1306
- return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
1883
+ if (!this.authSettings) return [3 /*break*/, 7];
1884
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetAuthToken);
1885
+ if (!this.chatSDKConfig.getAuthToken) return [3 /*break*/, 6];
1886
+ _b.label = 2;
1307
1887
  case 2:
1308
- token = _a.sent();
1888
+ _b.trys.push([2, 4, , 5]);
1889
+ return [4 /*yield*/, this.chatSDKConfig.getAuthToken()];
1890
+ case 3:
1891
+ token = _b.sent();
1309
1892
  if (token) {
1310
1893
  this.authenticatedUserToken = token;
1894
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetAuthToken);
1311
1895
  }
1312
1896
  else {
1313
- console.warn("OmnichannelChatSDK/getChatConfig/auth, chat requires auth, but getAuthToken() returned null");
1897
+ exceptionDetails = {
1898
+ response: "UndefinedAuthToken"
1899
+ };
1900
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1901
+ ExceptionDetails: JSON.stringify(exceptionDetails)
1902
+ });
1314
1903
  }
1315
- return [3 /*break*/, 4];
1316
- case 3:
1317
- console.warn("OmnichannelChatSDK/getChatConfig/auth, chat requires auth, but getAuthToken() is missing");
1318
- _a.label = 4;
1904
+ return [3 /*break*/, 5];
1319
1905
  case 4:
1906
+ _a = _b.sent();
1907
+ exceptionDetails = {
1908
+ response: "GetAuthTokenFailed"
1909
+ };
1910
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1911
+ ExceptionDetails: JSON.stringify(exceptionDetails)
1912
+ });
1913
+ return [3 /*break*/, 5];
1914
+ case 5: return [3 /*break*/, 7];
1915
+ case 6:
1916
+ exceptionDetails = {
1917
+ response: "GetAuthTokenNotFound"
1918
+ };
1919
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
1920
+ ExceptionDetails: JSON.stringify(exceptionDetails)
1921
+ });
1922
+ _b.label = 7;
1923
+ case 7:
1320
1924
  if (this.preChatSurvey) {
1321
1925
  /* istanbul ignore next */
1322
1926
  this.debug && console.log('Prechat Survey!');
@@ -1324,11 +1928,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
1324
1928
  this.callingOption = msdyn_callingoptions;
1325
1929
  this.liveChatConfig = liveChatConfig;
1326
1930
  return [2 /*return*/, this.liveChatConfig];
1327
- case 5:
1328
- error_12 = _a.sent();
1329
- console.error("OmnichannelChatSDK/getChatConfig/error " + error_12);
1330
- return [2 /*return*/, error_12];
1331
- case 6: return [2 /*return*/];
1931
+ case 8:
1932
+ error_18 = _b.sent();
1933
+ console.error("OmnichannelChatSDK/getChatConfig/error " + error_18);
1934
+ return [2 /*return*/, error_18];
1935
+ case 9: return [2 /*return*/];
1332
1936
  }
1333
1937
  });
1334
1938
  });
@@ -1343,20 +1947,33 @@ var OmnichannelChatSDK = /** @class */ (function () {
1343
1947
  return libraries_1.default.getIC3ClientCDNUrl();
1344
1948
  };
1345
1949
  OmnichannelChatSDK.prototype.resolveChatAdapterUrl = function (protocol) {
1346
- if (protocol !== ChatAdapterProtocols_1.default.IC3) {
1950
+ var supportedChatAdapterProtocols = [ChatAdapterProtocols_1.default.ACS, ChatAdapterProtocols_1.default.IC3];
1951
+ if (protocol && !supportedChatAdapterProtocols.includes(protocol)) {
1347
1952
  throw new Error("ChatAdapter for protocol " + protocol + " currently not supported");
1348
1953
  }
1349
- if (this.chatSDKConfig.chatAdapterConfig && 'webChatIC3AdapterCDNUrl' in this.chatSDKConfig.chatAdapterConfig) {
1350
- return this.chatSDKConfig.chatAdapterConfig.webChatIC3AdapterCDNUrl;
1954
+ if (protocol === ChatAdapterProtocols_1.default.ACS || this.liveChatVersion === LiveChatVersion_1.default.V2) {
1955
+ if (this.chatSDKConfig.chatAdapterConfig && 'webChatACSAdapterCDNUrl' in this.chatSDKConfig.chatAdapterConfig) {
1956
+ return this.chatSDKConfig.chatAdapterConfig.webChatACSAdapterCDNUrl;
1957
+ }
1958
+ if (this.chatSDKConfig.chatAdapterConfig && 'webChatACSAdapterVersion' in this.chatSDKConfig.chatAdapterConfig) {
1959
+ return libraries_1.default.getACSAdapterCDNUrl(this.chatSDKConfig.chatAdapterConfig.webChatACSAdapterVersion);
1960
+ }
1961
+ return libraries_1.default.getACSAdapterCDNUrl();
1351
1962
  }
1352
- if (this.chatSDKConfig.chatAdapterConfig && 'webChatIC3AdapterVersion' in this.chatSDKConfig.chatAdapterConfig) {
1353
- return libraries_1.default.getIC3AdapterCDNUrl(this.chatSDKConfig.chatAdapterConfig.webChatIC3AdapterVersion);
1963
+ else if (protocol === ChatAdapterProtocols_1.default.IC3 || this.liveChatVersion === LiveChatVersion_1.default.V1) {
1964
+ if (this.chatSDKConfig.chatAdapterConfig && 'webChatIC3AdapterCDNUrl' in this.chatSDKConfig.chatAdapterConfig) {
1965
+ return this.chatSDKConfig.chatAdapterConfig.webChatIC3AdapterCDNUrl;
1966
+ }
1967
+ if (this.chatSDKConfig.chatAdapterConfig && 'webChatIC3AdapterVersion' in this.chatSDKConfig.chatAdapterConfig) {
1968
+ return libraries_1.default.getIC3AdapterCDNUrl(this.chatSDKConfig.chatAdapterConfig.webChatIC3AdapterVersion);
1969
+ }
1970
+ return libraries_1.default.getIC3AdapterCDNUrl();
1354
1971
  }
1355
- return libraries_1.default.getIC3AdapterCDNUrl();
1972
+ return '';
1356
1973
  };
1357
1974
  OmnichannelChatSDK.prototype.updateChatToken = function (newToken, newRegionGTMS) {
1358
1975
  return __awaiter(this, void 0, void 0, function () {
1359
- var sessionInfo, error_13, exceptionDetails;
1976
+ var sessionInfo, error_19, exceptionDetails;
1360
1977
  return __generator(this, function (_a) {
1361
1978
  switch (_a.label) {
1362
1979
  case 0:
@@ -1381,7 +1998,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1381
1998
  });
1382
1999
  return [3 /*break*/, 4];
1383
2000
  case 3:
1384
- error_13 = _a.sent();
2001
+ error_19 = _a.sent();
1385
2002
  exceptionDetails = {
1386
2003
  response: "UpdateChatTokenFailed"
1387
2004
  };
@@ -1390,7 +2007,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1390
2007
  ChatId: this.chatToken.chatId,
1391
2008
  ExceptionDetails: JSON.stringify(exceptionDetails)
1392
2009
  });
1393
- console.error("OmnichannelChatSDK/updateChatToken/error " + error_13);
2010
+ console.error("OmnichannelChatSDK/updateChatToken/error " + error_19);
1394
2011
  return [3 /*break*/, 4];
1395
2012
  case 4: return [2 /*return*/];
1396
2013
  }