@microsoft/omnichannel-chat-sdk 0.3.1-main.c96fb51 → 1.0.1-main.1e6bcff

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